Changeset 781 in code for trunk/bridge.go


Ignore:
Timestamp:
Feb 11, 2022, 6:41:46 PM (3 years ago)
Author:
delthas
Message:

Add support for the wip soju.im/read capability and READ command

READ lets downstream clients share information between each other about
what messages have been read by other downstreams.

Each target/entity has an optional corresponding read receipt, which is
stored as a timestamp.

  • When a downstream sends: READ #chan timestamp=2020-01-01T01:23:45.000Z the read receipt for that target is set to that date
  • soju sends READ to downstreams:
    • on JOIN, if the client uses the soju.im/read capability
    • when the read receipt timestamp is set by any downstream

The read receipt date is clamped by the previous receipt date and the
current time.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bridge.go

    r764 r781  
    22
    33import (
     4        "context"
     5        "fmt"
    46        "strconv"
    57        "strings"
     
    810)
    911
    10 func forwardChannel(dc *downstreamConn, ch *upstreamChannel) {
     12func forwardChannel(ctx context.Context, dc *downstreamConn, ch *upstreamChannel) {
    1113        if !ch.complete {
    1214                panic("Tried to forward a partial channel")
     
    1719                sendTopic(dc, ch)
    1820        }
     21
     22        if dc.caps["soju.im/read"] {
     23                channelCM := ch.conn.network.casemap(ch.Name)
     24                r, err := dc.srv.db.GetReadReceipt(ctx, ch.conn.network.ID, channelCM)
     25                if err != nil {
     26                        dc.logger.Printf("failed to get the read receipt for %q: %v", ch.Name, err)
     27                } else {
     28                        timestampStr := "*"
     29                        if r != nil {
     30                                timestampStr = fmt.Sprintf("timestamp=%s", r.Timestamp.UTC().Format(serverTimeLayout))
     31                        }
     32                        dc.SendMessage(&irc.Message{
     33                                Prefix:  dc.prefix(),
     34                                Command: "READ",
     35                                Params:  []string{dc.marshalEntity(ch.conn.network, ch.Name), timestampStr},
     36                        })
     37                }
     38        }
     39
    1940        sendNames(dc, ch)
    2041}
Note: See TracChangeset for help on using the changeset viewer.