Changeset 284 in code for trunk/downstream.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/downstream.go

    r279 r284  
    768768        dc.forEachUpstream(func(uc *upstreamConn) {
    769769                for _, ch := range uc.channels {
    770                         if ch.complete {
    771                                 dc.SendMessage(&irc.Message{
    772                                         Prefix:  dc.prefix(),
    773                                         Command: "JOIN",
    774                                         Params:  []string{dc.marshalEntity(ch.conn.network, ch.Name)},
    775                                 })
    776 
    777                                 forwardChannel(dc, ch)
    778                         }
     770                        if !ch.complete {
     771                                continue
     772                        }
     773                        if record, ok := uc.network.channels[ch.Name]; ok && record.Detached {
     774                                continue
     775                        }
     776
     777                        dc.SendMessage(&irc.Message{
     778                                Prefix:  dc.prefix(),
     779                                Command: "JOIN",
     780                                Params:  []string{dc.marshalEntity(ch.conn.network, ch.Name)},
     781                        })
     782
     783                        forwardChannel(dc, ch)
    779784                }
    780785        })
     
    794799func (dc *downstreamConn) sendNetworkHistory(net *network) {
    795800        for target, history := range net.history {
     801                if ch, ok := net.channels[target]; ok && ch.Detached {
     802                        continue
     803                }
     804
    796805                seq, ok := history.offlineClients[dc.clientName]
    797806                if !ok {
     
    946955                        })
    947956
    948                         ch := &Channel{Name: upstreamName, Key: key}
     957                        ch := &Channel{Name: upstreamName, Key: key, Detached: false}
    949958                        if err := uc.network.createUpdateChannel(ch); err != nil {
    950959                                dc.logger.Printf("failed to create or update channel %q: %v", upstreamName, err)
     
    968977                        }
    969978
    970                         params := []string{upstreamName}
    971                         if reason != "" {
    972                                 params = append(params, reason)
    973                         }
    974                         uc.SendMessage(&irc.Message{
    975                                 Command: "PART",
    976                                 Params:  params,
    977                         })
    978 
    979                         if err := uc.network.deleteChannel(upstreamName); err != nil {
    980                                 dc.logger.Printf("failed to delete channel %q: %v", upstreamName, err)
     979                        if strings.EqualFold(reason, "detach") {
     980                                ch := &Channel{Name: upstreamName, Detached: true}
     981                                if err := uc.network.createUpdateChannel(ch); err != nil {
     982                                        dc.logger.Printf("failed to detach channel %q: %v", upstreamName, err)
     983                                }
     984                        } else {
     985                                params := []string{upstreamName}
     986                                if reason != "" {
     987                                        params = append(params, reason)
     988                                }
     989                                uc.SendMessage(&irc.Message{
     990                                        Command: "PART",
     991                                        Params:  params,
     992                                })
     993
     994                                if err := uc.network.deleteChannel(upstreamName); err != nil {
     995                                        dc.logger.Printf("failed to delete channel %q: %v", upstreamName, err)
     996                                }
    981997                        }
    982998                }
Note: See TracChangeset for help on using the changeset viewer.