Simplify network.offlineClients
Replace it with a list of all clients (online or offline).
This commit is contained in:
parent
2b92e4ecd4
commit
5a899abaab
@ -990,9 +990,14 @@ func (dc *downstreamConn) welcome() error {
|
|||||||
dc.forEachNetwork(func(net *network) {
|
dc.forEachNetwork(func(net *network) {
|
||||||
// Only send history if we're the first connected client with that name
|
// Only send history if we're the first connected client with that name
|
||||||
// for the network
|
// for the network
|
||||||
if _, ok := net.offlineClients[dc.clientName]; ok {
|
firstClient := true
|
||||||
|
dc.user.forEachDownstream(func(c *downstreamConn) {
|
||||||
|
if c != dc && c.clientName == dc.clientName && c.network == dc.network {
|
||||||
|
firstClient = false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
if firstClient {
|
||||||
dc.sendNetworkBacklog(net)
|
dc.sendNetworkBacklog(net)
|
||||||
delete(net.offlineClients, dc.clientName)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fast-forward history to last message
|
// Fast-forward history to last message
|
||||||
|
18
upstream.go
18
upstream.go
@ -1740,14 +1740,12 @@ func (uc *upstreamConn) appendLog(entity string, msg *irc.Message) (msgID string
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
detached := false
|
|
||||||
if ch := uc.network.channels.Value(entity); ch != nil {
|
|
||||||
detached = ch.Detached
|
|
||||||
}
|
|
||||||
|
|
||||||
delivered := uc.network.delivered.Value(entity)
|
delivered := uc.network.delivered.Value(entity)
|
||||||
entityCM := uc.network.casemap(entity)
|
entityCM := uc.network.casemap(entity)
|
||||||
if delivered == nil {
|
if delivered == nil {
|
||||||
|
// This is the first message we receive from this target. Save the last
|
||||||
|
// message ID in delivery receipts, so that we can send the new message
|
||||||
|
// in the backlog if an offline client reconnects.
|
||||||
lastID, err := uc.user.msgStore.LastMsgID(uc.network, entityCM, time.Now())
|
lastID, err := uc.user.msgStore.LastMsgID(uc.network, entityCM, time.Now())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
uc.logger.Printf("failed to log message: failed to get last message ID: %v", err)
|
uc.logger.Printf("failed to log message: failed to get last message ID: %v", err)
|
||||||
@ -1757,17 +1755,9 @@ func (uc *upstreamConn) appendLog(entity string, msg *irc.Message) (msgID string
|
|||||||
delivered = make(deliveredClientMap)
|
delivered = make(deliveredClientMap)
|
||||||
uc.network.delivered.SetValue(entity, delivered)
|
uc.network.delivered.SetValue(entity, delivered)
|
||||||
|
|
||||||
for clientName, _ := range uc.network.offlineClients {
|
for clientName, _ := range uc.network.clients {
|
||||||
delivered[clientName] = lastID
|
delivered[clientName] = lastID
|
||||||
}
|
}
|
||||||
|
|
||||||
if detached {
|
|
||||||
// If the channel is detached, online clients act as offline
|
|
||||||
// clients too
|
|
||||||
uc.forEachDownstream(func(dc *downstreamConn) {
|
|
||||||
delivered[dc.clientName] = lastID
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
msgID, err := uc.user.msgStore.Append(uc.network, entityCM, msg)
|
msgID, err := uc.user.msgStore.Append(uc.network, entityCM, msg)
|
||||||
|
23
user.go
23
user.go
@ -65,7 +65,7 @@ type network struct {
|
|||||||
conn *upstreamConn
|
conn *upstreamConn
|
||||||
channels channelCasemapMap
|
channels channelCasemapMap
|
||||||
delivered deliveredCasemapMap
|
delivered deliveredCasemapMap
|
||||||
offlineClients map[string]struct{} // indexed by client name
|
clients map[string]struct{} // indexed by client name
|
||||||
lastError error
|
lastError error
|
||||||
casemap casemapping
|
casemap casemapping
|
||||||
}
|
}
|
||||||
@ -83,7 +83,7 @@ func newNetwork(user *user, record *Network, channels []Channel) *network {
|
|||||||
stopped: make(chan struct{}),
|
stopped: make(chan struct{}),
|
||||||
channels: m,
|
channels: m,
|
||||||
delivered: deliveredCasemapMap{newCasemapMap(0)},
|
delivered: deliveredCasemapMap{newCasemapMap(0)},
|
||||||
offlineClients: make(map[string]struct{}),
|
clients: make(map[string]struct{}),
|
||||||
casemap: casemapRFC1459,
|
casemap: casemapRFC1459,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -196,8 +196,6 @@ func (net *network) detach(ch *Channel) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
net.forEachDownstream(func(dc *downstreamConn) {
|
net.forEachDownstream(func(dc *downstreamConn) {
|
||||||
net.offlineClients[dc.clientName] = struct{}{}
|
|
||||||
|
|
||||||
dc.SendMessage(&irc.Message{
|
dc.SendMessage(&irc.Message{
|
||||||
Prefix: dc.prefix(),
|
Prefix: dc.prefix(),
|
||||||
Command: "PART",
|
Command: "PART",
|
||||||
@ -448,6 +446,7 @@ func (u *user) run() {
|
|||||||
u.downstreamConns = append(u.downstreamConns, dc)
|
u.downstreamConns = append(u.downstreamConns, dc)
|
||||||
|
|
||||||
dc.forEachNetwork(func(network *network) {
|
dc.forEachNetwork(func(network *network) {
|
||||||
|
network.clients[dc.clientName] = struct{}{}
|
||||||
if network.lastError != nil {
|
if network.lastError != nil {
|
||||||
sendServiceNOTICE(dc, fmt.Sprintf("disconnected from %s: %v", network.GetName(), network.lastError))
|
sendServiceNOTICE(dc, fmt.Sprintf("disconnected from %s: %v", network.GetName(), network.lastError))
|
||||||
}
|
}
|
||||||
@ -466,22 +465,6 @@ func (u *user) run() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save history if we're the last client with this name
|
|
||||||
skipHistory := make(map[*network]bool)
|
|
||||||
u.forEachDownstream(func(conn *downstreamConn) {
|
|
||||||
if dc.clientName == conn.clientName {
|
|
||||||
skipHistory[conn.network] = true
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
dc.forEachNetwork(func(net *network) {
|
|
||||||
if skipHistory[net] || skipHistory[nil] {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
net.offlineClients[dc.clientName] = struct{}{}
|
|
||||||
})
|
|
||||||
|
|
||||||
u.forEachUpstream(func(uc *upstreamConn) {
|
u.forEachUpstream(func(uc *upstreamConn) {
|
||||||
uc.updateAway()
|
uc.updateAway()
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user