mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-10 22:19:31 +01:00
review fixes: rename MonitorManager methods
This commit is contained in:
parent
26686d7e86
commit
3877db2391
@ -301,7 +301,7 @@ func (client *Client) Register() {
|
|||||||
client.Touch()
|
client.Touch()
|
||||||
|
|
||||||
client.updateNickMask("")
|
client.updateNickMask("")
|
||||||
client.server.monitorManager.alertMonitors(client, true)
|
client.server.monitorManager.AlertAbout(client, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
// IdleTime returns how long this client's been idle.
|
// IdleTime returns how long this client's been idle.
|
||||||
@ -539,9 +539,9 @@ func (client *Client) destroy() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// alert monitors
|
// alert monitors
|
||||||
client.server.monitorManager.alertMonitors(client, false)
|
client.server.monitorManager.AlertAbout(client, false)
|
||||||
// clean up monitor state
|
// clean up monitor state
|
||||||
client.server.monitorManager.clearMonitorList(client)
|
client.server.monitorManager.RemoveAll(client)
|
||||||
|
|
||||||
// clean up channels
|
// clean up channels
|
||||||
client.server.channelJoinPartMutex.Lock()
|
client.server.channelJoinPartMutex.Lock()
|
||||||
|
@ -31,8 +31,8 @@ func NewMonitorManager() *MonitorManager {
|
|||||||
|
|
||||||
var MonitorLimitExceeded = errors.New("Monitor limit exceeded")
|
var MonitorLimitExceeded = errors.New("Monitor limit exceeded")
|
||||||
|
|
||||||
// alertMonitors alerts everyone monitoring us that we're online.
|
// AlertAbout alerts everyone monitoring `client`'s nick that `client` is now {on,off}line.
|
||||||
func (manager *MonitorManager) alertMonitors(client *Client, online bool) {
|
func (manager *MonitorManager) AlertAbout(client *Client, online bool) {
|
||||||
cfnick := client.getNickCasefolded()
|
cfnick := client.getNickCasefolded()
|
||||||
nick := client.getNick()
|
nick := client.getNick()
|
||||||
var watchers []*Client
|
var watchers []*Client
|
||||||
@ -59,18 +59,8 @@ func (manager *MonitorManager) alertMonitors(client *Client, online bool) {
|
|||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
// clearMonitorList clears our MONITOR list.
|
// Add registers `client` to receive notifications about `nick`.
|
||||||
func (manager *MonitorManager) clearMonitorList(client *Client) {
|
func (manager *MonitorManager) Add(client *Client, nick string, limit int) error {
|
||||||
manager.Lock()
|
|
||||||
defer manager.Unlock()
|
|
||||||
|
|
||||||
for nick, _ := range manager.watching[client] {
|
|
||||||
delete(manager.watchedby[nick], client)
|
|
||||||
}
|
|
||||||
delete(manager.watching, client)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (manager *MonitorManager) addMonitor(client *Client, nick string, limit int) error {
|
|
||||||
manager.Lock()
|
manager.Lock()
|
||||||
defer manager.Unlock()
|
defer manager.Unlock()
|
||||||
|
|
||||||
@ -90,7 +80,8 @@ func (manager *MonitorManager) addMonitor(client *Client, nick string, limit int
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (manager *MonitorManager) removeMonitor(client *Client, nick string) error {
|
// Remove unregisters `client` from receiving notifications about `nick`.
|
||||||
|
func (manager *MonitorManager) Remove(client *Client, nick string) error {
|
||||||
manager.Lock()
|
manager.Lock()
|
||||||
defer manager.Unlock()
|
defer manager.Unlock()
|
||||||
// deleting from nil maps is fine
|
// deleting from nil maps is fine
|
||||||
@ -99,7 +90,19 @@ func (manager *MonitorManager) removeMonitor(client *Client, nick string) error
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (manager *MonitorManager) listMonitors(client *Client) (nicks []string) {
|
// RemoveAll unregisters `client` from receiving notifications about *all* nicks.
|
||||||
|
func (manager *MonitorManager) RemoveAll(client *Client) {
|
||||||
|
manager.Lock()
|
||||||
|
defer manager.Unlock()
|
||||||
|
|
||||||
|
for nick, _ := range manager.watching[client] {
|
||||||
|
delete(manager.watchedby[nick], client)
|
||||||
|
}
|
||||||
|
delete(manager.watching, client)
|
||||||
|
}
|
||||||
|
|
||||||
|
// List lists all nicks that `client` is registered to receive notifications about.
|
||||||
|
func (manager *MonitorManager) List(client *Client) (nicks []string) {
|
||||||
manager.RLock()
|
manager.RLock()
|
||||||
defer manager.RUnlock()
|
defer manager.RUnlock()
|
||||||
for nick := range manager.watching[client] {
|
for nick := range manager.watching[client] {
|
||||||
@ -141,7 +144,7 @@ func monitorRemoveHandler(server *Server, client *Client, msg ircmsg.IrcMessage)
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
server.monitorManager.removeMonitor(client, cfnick)
|
server.monitorManager.Remove(client, cfnick)
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
return false
|
||||||
@ -171,7 +174,7 @@ func monitorAddHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bo
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
err = server.monitorManager.addMonitor(client, casefoldedTarget, limit)
|
err = server.monitorManager.Add(client, casefoldedTarget, limit)
|
||||||
if err == MonitorLimitExceeded {
|
if err == MonitorLimitExceeded {
|
||||||
client.Send(nil, server.name, ERR_MONLISTFULL, client.getNick(), strconv.Itoa(server.limits.MonitorEntries), strings.Join(targets, ","))
|
client.Send(nil, server.name, ERR_MONLISTFULL, client.getNick(), strconv.Itoa(server.limits.MonitorEntries), strings.Join(targets, ","))
|
||||||
break
|
break
|
||||||
@ -198,12 +201,12 @@ func monitorAddHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bo
|
|||||||
}
|
}
|
||||||
|
|
||||||
func monitorClearHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
func monitorClearHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
||||||
server.monitorManager.clearMonitorList(client)
|
server.monitorManager.RemoveAll(client)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func monitorListHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
func monitorListHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
||||||
monitorList := server.monitorManager.listMonitors(client)
|
monitorList := server.monitorManager.List(client)
|
||||||
|
|
||||||
for _, line := range argsToStrings(maxLastArgLength, monitorList, ",") {
|
for _, line := range argsToStrings(maxLastArgLength, monitorList, ",") {
|
||||||
client.Send(nil, server.name, RPL_MONLIST, client.getNick(), line)
|
client.Send(nil, server.name, RPL_MONLIST, client.getNick(), line)
|
||||||
@ -218,7 +221,7 @@ func monitorStatusHandler(server *Server, client *Client, msg ircmsg.IrcMessage)
|
|||||||
var online []string
|
var online []string
|
||||||
var offline []string
|
var offline []string
|
||||||
|
|
||||||
monitorList := server.monitorManager.listMonitors(client)
|
monitorList := server.monitorManager.List(client)
|
||||||
|
|
||||||
for _, name := range monitorList {
|
for _, name := range monitorList {
|
||||||
target := server.clients.Get(name)
|
target := server.clients.Get(name)
|
||||||
|
@ -57,7 +57,7 @@ func nickHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if client.registered {
|
if client.registered {
|
||||||
client.server.monitorManager.alertMonitors(client, true)
|
client.server.monitorManager.AlertAbout(client, true)
|
||||||
}
|
}
|
||||||
server.tryRegister(client)
|
server.tryRegister(client)
|
||||||
return false
|
return false
|
||||||
|
Loading…
Reference in New Issue
Block a user