Changeset 499 in code for trunk


Ignore:
Timestamp:
Apr 13, 2021, 5:11:05 PM (4 years ago)
Author:
contact
Message:

Relay detached channel backlog as BouncerServ NOTICE if necessary

Instead of ignoring detached channels wehn replaying backlog,
process them as usual and relay messages as BouncerServ NOTICEs
if necessary. Advance the delivery receipts as if the channel was
attached.

Closes: https://todo.sr.ht/~emersion/soju/98

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/downstream.go

    r496 r499  
    10311031                return
    10321032        }
    1033         if ch := net.channels.Value(target); ch != nil && ch.Detached {
    1034                 return
    1035         }
     1033
     1034        ch := net.channels.Value(target)
    10361035
    10371036        limit := 4000
     
    10571056                }
    10581057
    1059                 if dc.caps["batch"] {
    1060                         msg.Tags["batch"] = irc.TagValue(batchRef)
    1061                 }
    1062                 dc.SendMessage(dc.marshalMessage(msg, net))
     1058                if ch != nil && ch.Detached {
     1059                        if net.detachedMessageNeedsRelay(ch, msg) {
     1060                                dc.relayDetachedMessage(net, msg)
     1061                        }
     1062                } else {
     1063                        if dc.caps["batch"] {
     1064                                msg.Tags["batch"] = irc.TagValue(batchRef)
     1065                        }
     1066                        dc.SendMessage(dc.marshalMessage(msg, net))
     1067                }
    10631068        }
    10641069
     
    10691074                        Params:  []string{"-" + batchRef},
    10701075                })
     1076        }
     1077}
     1078
     1079func (dc *downstreamConn) relayDetachedMessage(net *network, msg *irc.Message) {
     1080        if msg.Command != "PRIVMSG" && msg.Command != "NOTICE" {
     1081                return
     1082        }
     1083
     1084        sender := msg.Prefix.Name
     1085        target, text := msg.Params[0], msg.Params[1]
     1086        if net.isHighlight(msg) {
     1087                sendServiceNOTICE(dc, fmt.Sprintf("highlight in %v: <%v> %v", dc.marshalEntity(net, target), sender, text))
     1088        } else {
     1089                sendServiceNOTICE(dc, fmt.Sprintf("message in %v: <%v> %v", dc.marshalEntity(net, target), sender, text))
    10711090        }
    10721091}
  • trunk/upstream.go

    r498 r499  
    392392                        if ch != nil {
    393393                                if ch.Detached {
    394                                         uc.handleDetachedMessage(msg.Prefix.Name, text, ch)
     394                                        uc.handleDetachedMessage(ch, msg)
    395395                                }
    396396
    397                                 highlight := msg.Prefix.Name != uc.nick && isHighlight(text, uc.nick)
     397                                highlight := uc.network.isHighlight(msg)
    398398                                if ch.DetachOn == FilterMessage || ch.DetachOn == FilterDefault || (ch.DetachOn == FilterHighlight && highlight) {
    399399                                        uc.updateChannelAutoDetach(target)
     
    14381438}
    14391439
    1440 func (uc *upstreamConn) handleDetachedMessage(sender string, text string, ch *Channel) {
    1441         highlight := sender != uc.nick && isHighlight(text, uc.nick)
    1442         if ch.RelayDetached == FilterMessage || ((ch.RelayDetached == FilterHighlight || ch.RelayDetached == FilterDefault) && highlight) {
     1440func (uc *upstreamConn) handleDetachedMessage(ch *Channel, msg *irc.Message) {
     1441        if uc.network.detachedMessageNeedsRelay(ch, msg) {
    14431442                uc.forEachDownstream(func(dc *downstreamConn) {
    1444                         if highlight {
    1445                                 sendServiceNOTICE(dc, fmt.Sprintf("highlight in %v: <%v> %v", dc.marshalEntity(uc.network, ch.Name), sender, text))
    1446                         } else {
    1447                                 sendServiceNOTICE(dc, fmt.Sprintf("message in %v: <%v> %v", dc.marshalEntity(uc.network, ch.Name), sender, text))
    1448                         }
    1449                 })
    1450         }
    1451         if ch.ReattachOn == FilterMessage || (ch.ReattachOn == FilterHighlight && highlight) {
     1443                        dc.relayDetachedMessage(uc.network, msg)
     1444                })
     1445        }
     1446        if ch.ReattachOn == FilterMessage || (ch.ReattachOn == FilterHighlight && uc.network.isHighlight(msg)) {
    14521447                uc.network.attach(ch)
    14531448                if err := uc.srv.db.StoreChannel(uc.network.ID, ch); err != nil {
     
    17441739        // Don't forward messages if it's a detached channel
    17451740        ch := uc.network.channels.Value(target)
    1746         if ch != nil && ch.Detached {
    1747                 return
    1748         }
     1741        detached := ch != nil && ch.Detached
    17491742
    17501743        uc.forEachDownstream(func(dc *downstreamConn) {
    1751                 if dc != origin || dc.caps["echo-message"] {
     1744                if !detached && (dc != origin || dc.caps["echo-message"]) {
    17521745                        dc.sendMessageWithID(dc.marshalMessage(msg, uc.network), msgID)
    17531746                } else {
  • trunk/user.go

    r497 r499  
    352352}
    353353
     354func (net *network) isHighlight(msg *irc.Message) bool {
     355        if msg.Command != "PRIVMSG" && msg.Command != "NOTICE" {
     356                return false
     357        }
     358
     359        text := msg.Params[1]
     360
     361        nick := net.Nick
     362        if net.conn != nil {
     363                nick = net.conn.nick
     364        }
     365
     366        // TODO: use case-mapping aware comparison here
     367        return msg.Prefix.Name != nick && isHighlight(text, nick)
     368}
     369
     370func (net *network) detachedMessageNeedsRelay(ch *Channel, msg *irc.Message) bool {
     371        highlight := net.isHighlight(msg)
     372        return ch.RelayDetached == FilterMessage || ((ch.RelayDetached == FilterHighlight || ch.RelayDetached == FilterDefault) && highlight)
     373}
     374
    354375type user struct {
    355376        User
Note: See TracChangeset for help on using the changeset viewer.