diff --git a/downstream.go b/downstream.go index 45c3c4e..2d3784e 100644 --- a/downstream.go +++ b/downstream.go @@ -325,12 +325,12 @@ func (dc *downstreamConn) ackMsgID(id string) { return } - history, ok := network.history[entity] + delivered, ok := network.delivered[entity] if !ok { return } - history.clients[dc.clientName] = id + delivered[dc.clientName] = id } func (dc *downstreamConn) sendPing(msgID string) { @@ -947,7 +947,7 @@ func (dc *downstreamConn) welcome() error { } // Fast-forward history to last message - for target, history := range net.history { + for target, delivered := range net.delivered { if ch, ok := net.channels[target]; ok && ch.Detached { continue } @@ -957,7 +957,7 @@ func (dc *downstreamConn) welcome() error { dc.logger.Printf("failed to get last message ID: %v", err) continue } - history.clients[dc.clientName] = lastID + delivered[dc.clientName] = lastID } }) @@ -982,12 +982,12 @@ func (dc *downstreamConn) sendNetworkBacklog(net *network) { if dc.caps["draft/chathistory"] || dc.user.msgStore == nil { return } - for target, history := range net.history { + for target, delivered := range net.delivered { if ch, ok := net.channels[target]; ok && ch.Detached { continue } - lastDelivered, ok := history.clients[dc.clientName] + lastDelivered, ok := delivered[dc.clientName] if !ok { continue } diff --git a/upstream.go b/upstream.go index f0fdf63..8843b1b 100644 --- a/upstream.go +++ b/upstream.go @@ -1678,7 +1678,7 @@ func (uc *upstreamConn) appendLog(entity string, msg *irc.Message) (msgID string detached = ch.Detached } - history, ok := uc.network.history[entity] + delivered, ok := uc.network.delivered[entity] if !ok { lastID, err := uc.user.msgStore.LastMsgID(uc.network, entity, time.Now()) if err != nil { @@ -1686,20 +1686,18 @@ func (uc *upstreamConn) appendLog(entity string, msg *irc.Message) (msgID string return "" } - history = &networkHistory{ - clients: make(map[string]string), - } - uc.network.history[entity] = history + delivered = make(map[string]string) + uc.network.delivered[entity] = delivered for clientName, _ := range uc.network.offlineClients { - history.clients[clientName] = lastID + delivered[clientName] = lastID } if detached { // If the channel is detached, online clients act as offline // clients too uc.forEachDownstream(func(dc *downstreamConn) { - history.clients[dc.clientName] = lastID + delivered[dc.clientName] = lastID }) } } diff --git a/user.go b/user.go index 6c59b75..c17c3d2 100644 --- a/user.go +++ b/user.go @@ -55,10 +55,6 @@ type eventChannelDetach struct { type eventStop struct{} -type networkHistory struct { - clients map[string]string // indexed by client name -} - type network struct { Network user *user @@ -66,8 +62,8 @@ type network struct { conn *upstreamConn channels map[string]*Channel - history map[string]*networkHistory // indexed by entity - offlineClients map[string]struct{} // indexed by client name + delivered map[string]map[string]string // entity -> client name -> msg ID + offlineClients map[string]struct{} // indexed by client name lastError error } @@ -83,7 +79,7 @@ func newNetwork(user *user, record *Network, channels []Channel) *network { user: user, stopped: make(chan struct{}), channels: m, - history: make(map[string]*networkHistory), + delivered: make(map[string]map[string]string), offlineClients: make(map[string]struct{}), } } @@ -230,7 +226,7 @@ func (net *network) attach(ch *Channel) { forwardChannel(dc, uch) } - if net.history[ch.Name] != nil { + if _, ok := net.delivered[ch.Name]; ok { dc.sendNetworkBacklog(net) } })