Changeset 482 in code for trunk


Ignore:
Timestamp:
Mar 29, 2021, 2:55:57 PM (4 years ago)
Author:
contact
Message:

Simplify network.offlineClients

Replace it with a list of all clients (online or offline).

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/downstream.go

    r480 r482  
    991991                // Only send history if we're the first connected client with that name
    992992                // for the network
    993                 if _, ok := net.offlineClients[dc.clientName]; ok {
     993                firstClient := true
     994                dc.user.forEachDownstream(func(c *downstreamConn) {
     995                        if c != dc && c.clientName == dc.clientName && c.network == dc.network {
     996                                firstClient = false
     997                        }
     998                })
     999                if firstClient {
    9941000                        dc.sendNetworkBacklog(net)
    995                         delete(net.offlineClients, dc.clientName)
    9961001                }
    9971002
  • trunk/upstream.go

    r480 r482  
    17411741        }
    17421742
    1743         detached := false
    1744         if ch := uc.network.channels.Value(entity); ch != nil {
    1745                 detached = ch.Detached
    1746         }
    1747 
    17481743        delivered := uc.network.delivered.Value(entity)
    17491744        entityCM := uc.network.casemap(entity)
    17501745        if delivered == nil {
     1746                // This is the first message we receive from this target. Save the last
     1747                // message ID in delivery receipts, so that we can send the new message
     1748                // in the backlog if an offline client reconnects.
    17511749                lastID, err := uc.user.msgStore.LastMsgID(uc.network, entityCM, time.Now())
    17521750                if err != nil {
     
    17581756                uc.network.delivered.SetValue(entity, delivered)
    17591757
    1760                 for clientName, _ := range uc.network.offlineClients {
     1758                for clientName, _ := range uc.network.clients {
    17611759                        delivered[clientName] = lastID
    1762                 }
    1763 
    1764                 if detached {
    1765                         // If the channel is detached, online clients act as offline
    1766                         // clients too
    1767                         uc.forEachDownstream(func(dc *downstreamConn) {
    1768                                 delivered[dc.clientName] = lastID
    1769                         })
    17701760                }
    17711761        }
  • trunk/user.go

    r480 r482  
    6363        stopped chan struct{}
    6464
    65         conn           *upstreamConn
    66         channels       channelCasemapMap
    67         delivered      deliveredCasemapMap
    68         offlineClients map[string]struct{} // indexed by client name
    69         lastError      error
    70         casemap        casemapping
     65        conn      *upstreamConn
     66        channels  channelCasemapMap
     67        delivered deliveredCasemapMap
     68        clients  map[string]struct{} // indexed by client name
     69        lastError error
     70        casemap   casemapping
    7171}
    7272
     
    7979
    8080        return &network{
    81                 Network:        *record,
    82                 user:           user,
    83                 stopped:        make(chan struct{}),
    84                 channels:       m,
    85                 delivered:      deliveredCasemapMap{newCasemapMap(0)},
    86                 offlineClients: make(map[string]struct{}),
    87                 casemap:        casemapRFC1459,
     81                Network:   *record,
     82                user:      user,
     83                stopped:   make(chan struct{}),
     84                channels:  m,
     85                delivered: deliveredCasemapMap{newCasemapMap(0)},
     86                clients:  make(map[string]struct{}),
     87                casemap:   casemapRFC1459,
    8888        }
    8989}
     
    197197
    198198        net.forEachDownstream(func(dc *downstreamConn) {
    199                 net.offlineClients[dc.clientName] = struct{}{}
    200 
    201199                dc.SendMessage(&irc.Message{
    202200                        Prefix:  dc.prefix(),
     
    449447
    450448                        dc.forEachNetwork(func(network *network) {
     449                                network.clients[dc.clientName] = struct{}{}
    451450                                if network.lastError != nil {
    452451                                        sendServiceNOTICE(dc, fmt.Sprintf("disconnected from %s: %v", network.GetName(), network.lastError))
     
    466465                                }
    467466                        }
    468 
    469                         // Save history if we're the last client with this name
    470                         skipHistory := make(map[*network]bool)
    471                         u.forEachDownstream(func(conn *downstreamConn) {
    472                                 if dc.clientName == conn.clientName {
    473                                         skipHistory[conn.network] = true
    474                                 }
    475                         })
    476 
    477                         dc.forEachNetwork(func(net *network) {
    478                                 if skipHistory[net] || skipHistory[nil] {
    479                                         return
    480                                 }
    481 
    482                                 net.offlineClients[dc.clientName] = struct{}{}
    483                         })
    484467
    485468                        u.forEachUpstream(func(uc *upstreamConn) {
Note: See TracChangeset for help on using the changeset viewer.