Add network.{createUpdate,delete}Channel
These are about to get more complicated as we move towards per-entity ring buffers.
This commit is contained in:
parent
93c96d6c21
commit
e70bf9c42a
@ -827,17 +827,9 @@ func (dc *downstreamConn) handleMessageRegistered(msg *irc.Message) error {
|
||||
Params: params,
|
||||
})
|
||||
|
||||
ch, err := dc.srv.db.GetChannel(uc.network.ID, upstreamName)
|
||||
if err == ErrNoSuchChannel {
|
||||
ch = &Channel{Name: upstreamName}
|
||||
} else if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ch.Key = key
|
||||
|
||||
if err := dc.srv.db.StoreChannel(uc.network.ID, ch); err != nil {
|
||||
return err
|
||||
ch := &Channel{Name: upstreamName, Key: key}
|
||||
if err := uc.network.createUpdateChannel(ch); err != nil {
|
||||
dc.logger.Printf("failed to create or update channel %q: %v", upstreamName, err)
|
||||
}
|
||||
}
|
||||
case "PART":
|
||||
@ -866,8 +858,8 @@ func (dc *downstreamConn) handleMessageRegistered(msg *irc.Message) error {
|
||||
Params: params,
|
||||
})
|
||||
|
||||
if err := dc.srv.db.DeleteChannel(uc.network.ID, upstreamName); err != nil {
|
||||
dc.logger.Printf("failed to delete channel %q in DB: %v", upstreamName, err)
|
||||
if err := uc.network.deleteChannel(upstreamName); err != nil {
|
||||
dc.logger.Printf("failed to delete channel %q: %v", upstreamName, err)
|
||||
}
|
||||
}
|
||||
case "KICK":
|
||||
|
13
user.go
13
user.go
@ -139,6 +139,19 @@ func (net *network) Stop() {
|
||||
}
|
||||
}
|
||||
|
||||
func (net *network) createUpdateChannel(ch *Channel) error {
|
||||
if dbCh, err := net.user.srv.db.GetChannel(net.ID, ch.Name); err == nil {
|
||||
ch.ID = dbCh.ID
|
||||
} else if err != ErrNoSuchChannel {
|
||||
return err
|
||||
}
|
||||
return net.user.srv.db.StoreChannel(net.ID, ch)
|
||||
}
|
||||
|
||||
func (net *network) deleteChannel(name string) error {
|
||||
return net.user.srv.db.DeleteChannel(net.ID, name)
|
||||
}
|
||||
|
||||
type user struct {
|
||||
User
|
||||
srv *Server
|
||||
|
Loading…
Reference in New Issue
Block a user