Changeset 198 in code for trunk


Ignore:
Timestamp:
Apr 1, 2020, 10:16:32 AM (5 years ago)
Author:
contact
Message:

Auto away

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

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/upstream.go

    r197 r198  
    5555        caps       map[string]string
    5656        batches    map[string]batch
     57        away       bool
    5758
    5859        tagsSupported   bool
     
    12701271        case "ACK":
    12711272                // Ignore
     1273        case irc.RPL_NOWAWAY, irc.RPL_UNAWAY:
     1274                // Ignore
    12721275        case irc.RPL_YOURHOST, irc.RPL_CREATED:
    12731276                // Ignore
     
    14841487        }
    14851488}
     1489
     1490func (uc *upstreamConn) updateAway() {
     1491        away := true
     1492        uc.forEachDownstream(func(*downstreamConn) {
     1493                away = false
     1494        })
     1495        if away == uc.away {
     1496                return
     1497        }
     1498        if away {
     1499                uc.SendMessage(&irc.Message{
     1500                        Command: "AWAY",
     1501                        Params:  []string{"Auto away"},
     1502                })
     1503        } else {
     1504                uc.SendMessage(&irc.Message{
     1505                        Command: "AWAY",
     1506                })
     1507        }
     1508        uc.away = away
     1509}
  • trunk/user.go

    r197 r198  
    176176                switch e := e.(type) {
    177177                case eventUpstreamConnected:
    178                         // Nothing to do
     178                        uc := e.uc
     179                        uc.updateAway()
    179180                case eventUpstreamDisconnected:
    180181                        uc := e.uc
     
    201202
    202203                        u.downstreamConns = append(u.downstreamConns, dc)
     204
     205                        u.forEachUpstream(func(uc *upstreamConn) {
     206                                uc.updateAway()
     207                        })
    203208                case eventDownstreamDisconnected:
    204209                        dc := e.dc
     
    209214                                }
    210215                        }
     216
     217                        u.forEachUpstream(func(uc *upstreamConn) {
     218                                uc.updateAway()
     219                        })
    211220                case eventDownstreamMessage:
    212221                        msg, dc := e.msg, e.dc
Note: See TracChangeset for help on using the changeset viewer.