~emersion/soju-dev

Always update last seen msg ID on welcome v1 PROPOSED

Eyal Sawady: 1
 Always update last seen msg ID on welcome

 1 files changed, 8 insertions(+), 6 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~emersion/soju-dev/patches/27263/mbox | git am -3
Learn more about email & git

[PATCH] Always update last seen msg ID on welcome Export this patch

Fixes backlog not being sent for channels which a client hasn't seen
messages from.

Steps to reproduce:
- Join a new channel (or an old channel with a new client)
- Disconnect
- Send a message to that channel
- Reconnect
---
While testing this patch, I found another bug related to backlog:
- Detach from a channel
- Send a message to that channel
- Disconnect
- Send another message to the same channel
- Reconnect
- Reattach to that channel

When I did this, the first message was dropped. Something similar
happened when I detached, disconnected, sent a message, reconnected,
sent another message, then reattached.

Should I file a ticket for that?
 downstream.go | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/downstream.go b/downstream.go
index 026b04b..d2c2bbe 100644
--- a/downstream.go
+++ b/downstream.go
@@ -1485,20 +1485,22 @@ func (dc *downstreamConn) welcome(ctx context.Context) error {
		})
		if firstClient {
			net.delivered.ForEachTarget(func(target string) {
				targetCM := net.casemap(target)
				lastID, err := dc.user.msgStore.LastMsgID(&net.Network, targetCM, time.Now())
				if err != nil {
					dc.logger.Printf("failed to get last message ID: %v", err)
					return
				}

				lastDelivered := net.delivered.LoadID(target, dc.clientName)
				if lastDelivered == "" {
					net.delivered.StoreID(target, dc.clientName, lastID)
					return
				}

				dc.sendTargetBacklog(ctx, net, target, lastDelivered)

				// Fast-forward history to last message
				targetCM := net.casemap(target)
				lastID, err := dc.user.msgStore.LastMsgID(&net.Network, targetCM, time.Now())
				if err != nil {
					dc.logger.Printf("failed to get last message ID: %v", err)
					return
				}
				net.delivered.StoreID(target, dc.clientName, lastID)
			})
		}
-- 
2.34.1