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,
|
Params: params,
|
||||||
})
|
})
|
||||||
|
|
||||||
ch, err := dc.srv.db.GetChannel(uc.network.ID, upstreamName)
|
ch := &Channel{Name: upstreamName, Key: key}
|
||||||
if err == ErrNoSuchChannel {
|
if err := uc.network.createUpdateChannel(ch); err != nil {
|
||||||
ch = &Channel{Name: upstreamName}
|
dc.logger.Printf("failed to create or update channel %q: %v", upstreamName, err)
|
||||||
} else if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
ch.Key = key
|
|
||||||
|
|
||||||
if err := dc.srv.db.StoreChannel(uc.network.ID, ch); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case "PART":
|
case "PART":
|
||||||
@ -866,8 +858,8 @@ func (dc *downstreamConn) handleMessageRegistered(msg *irc.Message) error {
|
|||||||
Params: params,
|
Params: params,
|
||||||
})
|
})
|
||||||
|
|
||||||
if err := dc.srv.db.DeleteChannel(uc.network.ID, upstreamName); err != nil {
|
if err := uc.network.deleteChannel(upstreamName); err != nil {
|
||||||
dc.logger.Printf("failed to delete channel %q in DB: %v", upstreamName, err)
|
dc.logger.Printf("failed to delete channel %q: %v", upstreamName, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case "KICK":
|
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 {
|
type user struct {
|
||||||
User
|
User
|
||||||
srv *Server
|
srv *Server
|
||||||
|
Loading…
Reference in New Issue
Block a user