Changeset 284 in code for trunk/user.go


Ignore:
Timestamp:
May 1, 2020, 1:18:14 PM (5 years ago)
Author:
contact
Message:

Add support for detached channels

Channels can now be detached by leaving them with the reason "detach",
and re-attached by joining them again. Upon detaching the channel is
no longer forwarded to downstream connections. Upon re-attaching the
history buffer is sent.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/user.go

    r283 r284  
    151151                return err
    152152        }
     153        prev := net.channels[ch.Name]
    153154        net.channels[ch.Name] = ch
     155
     156        if prev != nil && prev.Detached != ch.Detached {
     157                history := net.history[ch.Name]
     158                if ch.Detached {
     159                        net.user.srv.Logger.Printf("network %q: detaching channel %q", net.GetName(), ch.Name)
     160                        net.forEachDownstream(func(dc *downstreamConn) {
     161                                net.offlineClients[dc.clientName] = struct{}{}
     162                                if history != nil {
     163                                        history.offlineClients[dc.clientName] = history.ring.Cur()
     164                                }
     165
     166                                dc.SendMessage(&irc.Message{
     167                                        Prefix:  dc.prefix(),
     168                                        Command: "PART",
     169                                        Params:  []string{dc.marshalEntity(net, ch.Name), "Detach"},
     170                                })
     171                        })
     172                } else {
     173                        net.user.srv.Logger.Printf("network %q: attaching channel %q", net.GetName(), ch.Name)
     174
     175                        var uch *upstreamChannel
     176                        if net.conn != nil {
     177                                uch = net.conn.channels[ch.Name]
     178                        }
     179
     180                        net.forEachDownstream(func(dc *downstreamConn) {
     181                                dc.SendMessage(&irc.Message{
     182                                        Prefix:  dc.prefix(),
     183                                        Command: "JOIN",
     184                                        Params:  []string{dc.marshalEntity(net, ch.Name)},
     185                                })
     186
     187                                if uch != nil {
     188                                        forwardChannel(dc, uch)
     189                                }
     190
     191                                if history != nil {
     192                                        dc.sendNetworkHistory(net)
     193                                }
     194                        })
     195                }
     196        }
     197
    154198        return nil
    155199}
     
    343387
    344388                                net.offlineClients[dc.clientName] = struct{}{}
    345                                 for _, history := range net.history {
     389                                for target, history := range net.history {
     390                                        if ch, ok := net.channels[target]; ok && ch.Detached {
     391                                                continue
     392                                        }
    346393                                        history.offlineClients[dc.clientName] = history.ring.Cur()
    347394                                }
Note: See TracChangeset for help on using the changeset viewer.