Changeset 276 in code for trunk/upstream.go


Ignore:
Timestamp:
Apr 29, 2020, 5:34:44 PM (5 years ago)
Author:
contact
Message:

Add support for away-notify

This makes use of cap-notify to dynamically advertise support for
away-notify. away-notify is advertised to downstream connections if all
upstreams support it.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/upstream.go

    r274 r276  
    4747        modes      userModes
    4848        channels   map[string]*upstreamChannel
    49         caps       map[string]string
     49        caps       map[string]string // available capabilities
    5050        batches    map[string]batch
    5151        away       bool
    5252
    53         tagsSupported   bool
    54         labelsSupported bool
    55         nextLabelID     uint64
     53        tagsSupported       bool
     54        awayNotifySupported bool
     55        labelsSupported     bool
     56        nextLabelID         uint64
    5657
    5758        saslClient  sasl.Client
     
    318319
    319320                        requestCaps := make([]string, 0, 16)
    320                         for _, c := range []string{"message-tags", "batch", "labeled-response", "server-time"} {
     321                        for _, c := range []string{"message-tags", "batch", "labeled-response", "server-time", "away-notify"} {
    321322                                if _, ok := uc.caps[c]; ok {
    322323                                        requestCaps = append(requestCaps, c)
     
    450451                uc.registered = true
    451452                uc.logger.Printf("connection registered")
     453
     454                uc.forEachDownstream(func(dc *downstreamConn) {
     455                        dc.updateSupportedCaps()
     456                })
    452457
    453458                for _, ch := range uc.network.channels {
     
    11491154                        })
    11501155                })
     1156        case "AWAY":
     1157                if msg.Prefix == nil {
     1158                        return fmt.Errorf("expected a prefix")
     1159                }
     1160
     1161                uc.forEachDownstream(func(dc *downstreamConn) {
     1162                        if !dc.caps["away-notify"] {
     1163                                return
     1164                        }
     1165                        dc.SendMessage(&irc.Message{
     1166                                Prefix:  dc.marshalUserPrefix(uc.network, msg.Prefix),
     1167                                Command: "AWAY",
     1168                                Params:  msg.Params,
     1169                        })
     1170                })
    11511171        case "TAGMSG":
    11521172                // TODO: relay to downstream connections that accept message-tags
     
    12631283
    12641284func (uc *upstreamConn) handleCapAck(name string, ok bool) error {
    1265         auth := &uc.network.SASL
    12661285        switch name {
    12671286        case "sasl":
     
    12711290                }
    12721291
     1292                auth := &uc.network.SASL
    12731293                switch auth.Mechanism {
    12741294                case "PLAIN":
     
    12871307        case "labeled-response":
    12881308                uc.labelsSupported = ok
     1309        case "away-notify":
     1310                uc.awayNotifySupported = ok
    12891311        case "batch", "server-time":
    12901312                // Nothing to do
Note: See TracChangeset for help on using the changeset viewer.