Changeset 89 in code for trunk/downstream.go


Ignore:
Timestamp:
Mar 12, 2020, 5:33:03 PM (5 years ago)
Author:
contact
Message:

Update DB on JOIN and PART

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/downstream.go

    r88 r89  
    115115}
    116116
     117// upstream returns the upstream connection, if any. If there are zero or if
     118// there are multiple upstream connections, it returns nil.
     119func (dc *downstreamConn) upstream() *upstreamConn {
     120        if dc.network == nil {
     121                return nil
     122        }
     123
     124        var upstream *upstreamConn
     125        dc.forEachUpstream(func(uc *upstreamConn) {
     126                upstream = uc
     127        })
     128        return upstream
     129}
     130
    117131func (dc *downstreamConn) unmarshalChannel(name string) (*upstreamConn, string, error) {
     132        if uc := dc.upstream(); uc != nil {
     133                return uc, name, nil
     134        }
     135
    118136        // TODO: extract network name from channel name if dc.upstream == nil
    119137        var channel *upstreamChannel
     
    462480                        Params:  []string{upstreamName},
    463481                })
    464                 // TODO: add/remove channel from upstream config
     482
     483                switch msg.Command {
     484                case "JOIN":
     485                        err := dc.srv.db.StoreChannel(uc.network.ID, &Channel{
     486                                Name: upstreamName,
     487                        })
     488                        if err != nil {
     489                                dc.logger.Printf("failed to create channel %q in DB: %v", upstreamName, err)
     490                        }
     491                case "PART":
     492                        if err := dc.srv.db.DeleteChannel(uc.network.ID, upstreamName); err != nil {
     493                                dc.logger.Printf("failed to delete channel %q in DB: %v", upstreamName, err)
     494                        }
     495                }
    465496        case "MODE":
    466497                if msg.Prefix == nil {
Note: See TracChangeset for help on using the changeset viewer.