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:
Simon Ser 2020-04-05 15:04:52 +02:00
parent 93c96d6c21
commit e70bf9c42a
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48
2 changed files with 18 additions and 13 deletions

View File

@ -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
View File

@ -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