Changeset 665 in code for trunk/downstream.go


Ignore:
Timestamp:
Nov 3, 2021, 2:17:16 PM (4 years ago)
Author:
delthas
Message:

Add support for draft/event-playback

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/downstream.go

    r664 r665  
    519519        dc.SendMessage(msg)
    520520
    521         if id == "" || !dc.messageSupportsHistory(msg) {
     521        if id == "" || !dc.messageSupportsBacklog(msg) {
    522522                return
    523523        }
     
    530530// isn't enabled.
    531531func (dc *downstreamConn) advanceMessageWithID(msg *irc.Message, id string) {
    532         if id == "" || !dc.messageSupportsHistory(msg) {
     532        if id == "" || !dc.messageSupportsBacklog(msg) {
    533533                return
    534534        }
     
    572572// marshalMessage re-formats a message coming from an upstream connection so
    573573// that it's suitable for being sent on this downstream connection. Only
    574 // messages that may appear in logs are supported, except MODE.
     574// messages that may appear in logs are supported, except MODE messages which
     575// may only appear in single-upstream mode.
    575576func (dc *downstreamConn) marshalMessage(msg *irc.Message, net *network) *irc.Message {
     577        if dc.network != nil {
     578                return msg
     579        }
     580
    576581        msg = msg.Copy()
    577582        msg.Prefix = dc.marshalUserPrefix(net, msg.Prefix)
     
    984989                }
    985990        }
     991
     992        if dc.srv.LogPath != "" && dc.network != nil {
     993                dc.setSupportedCap("draft/event-playback", "")
     994        } else {
     995                dc.unsetSupportedCap("draft/event-playback")
     996        }
    986997}
    987998
     
    12981309}
    12991310
    1300 // messageSupportsHistory checks whether the provided message can be sent as
     1311// messageSupportsBacklog checks whether the provided message can be sent as
    13011312// part of an history batch.
    1302 func (dc *downstreamConn) messageSupportsHistory(msg *irc.Message) bool {
     1313func (dc *downstreamConn) messageSupportsBacklog(msg *irc.Message) bool {
    13031314        // Don't replay all messages, because that would mess up client
    13041315        // state. For instance we just sent the list of users, sending
    13051316        // PART messages for one of these users would be incorrect.
    1306         // TODO: add support for draft/event-playback
    13071317        switch msg.Command {
    13081318        case "PRIVMSG", "NOTICE":
     
    13291339        dc.SendBatch("chathistory", []string{dc.marshalEntity(net, target)}, nil, func(batchRef irc.TagValue) {
    13301340                for _, msg := range history {
    1331                         if !dc.messageSupportsHistory(msg) {
    1332                                 continue
    1333                         }
    1334 
    13351341                        if ch != nil && ch.Detached {
    13361342                                if net.detachedMessageNeedsRelay(ch, msg) {
     
    23272333                }
    23282334
     2335                eventPlayback := dc.caps["draft/event-playback"]
     2336
    23292337                var history []*irc.Message
    23302338                switch subcommand {
    23312339                case "BEFORE":
    2332                         history, err = store.LoadBeforeTime(network, entity, bounds[0], time.Time{}, limit)
     2340                        history, err = store.LoadBeforeTime(network, entity, bounds[0], time.Time{}, limit, eventPlayback)
    23332341                case "AFTER":
    2334                         history, err = store.LoadAfterTime(network, entity, bounds[0], time.Now(), limit)
     2342                        history, err = store.LoadAfterTime(network, entity, bounds[0], time.Now(), limit, eventPlayback)
    23352343                case "BETWEEN":
    23362344                        if bounds[0].Before(bounds[1]) {
    2337                                 history, err = store.LoadAfterTime(network, entity, bounds[0], bounds[1], limit)
     2345                                history, err = store.LoadAfterTime(network, entity, bounds[0], bounds[1], limit, eventPlayback)
    23382346                        } else {
    2339                                 history, err = store.LoadBeforeTime(network, entity, bounds[0], bounds[1], limit)
     2347                                history, err = store.LoadBeforeTime(network, entity, bounds[0], bounds[1], limit, eventPlayback)
    23402348                        }
    23412349                case "TARGETS":
    23422350                        // TODO: support TARGETS in multi-upstream mode
    2343                         targets, err := store.ListTargets(network, bounds[0], bounds[1], limit)
     2351                        targets, err := store.ListTargets(network, bounds[0], bounds[1], limit, eventPlayback)
    23442352                        if err != nil {
    23452353                                dc.logger.Printf("failed fetching targets for chathistory: %v", err)
Note: See TracChangeset for help on using the changeset viewer.