Rename network.history to network.delivered

"History" is over-loaded with e.g. CHATHISTORY support.
This commit is contained in:
Simon Ser 2021-02-10 11:31:34 +01:00
parent c14118f7f9
commit 7e39f6d663
3 changed files with 15 additions and 21 deletions

View File

@ -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
}

View File

@ -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
})
}
}

12
user.go
View File

@ -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)
}
})