aboutsummaryrefslogtreecommitdiff
path: root/hotline/client_conn.go
diff options
context:
space:
mode:
authorJeff Halter <868228+jhalter@users.noreply.github.com>2022-06-21 14:03:31 -0700
committerJeff Halter <868228+jhalter@users.noreply.github.com>2022-06-21 14:03:31 -0700
commit21581958c38861f3a62ef7c27d0a8a6f4db2a1f8 (patch)
treefeb1eb06405215ccd6dabe6ee96ddb7c0b5027d2 /hotline/client_conn.go
parent0fcfa5d54b166559c0ca31932a71a7eabb79c72c (diff)
Refactor notifyOthers
Diffstat (limited to 'hotline/client_conn.go')
-rw-r--r--hotline/client_conn.go9
1 files changed, 6 insertions, 3 deletions
diff --git a/hotline/client_conn.go b/hotline/client_conn.go
index a3c5258..997b9c9 100644
--- a/hotline/client_conn.go
+++ b/hotline/client_conn.go
@@ -172,7 +172,9 @@ func (cc *ClientConn) Disconnect() {
delete(cc.Server.Clients, binary.BigEndian.Uint16(*cc.ID))
- cc.notifyOthers(*NewTransaction(tranNotifyDeleteUser, nil, NewField(fieldUserID, *cc.ID)))
+ for _, t := range cc.notifyOthers(*NewTransaction(tranNotifyDeleteUser, nil, NewField(fieldUserID, *cc.ID))) {
+ cc.Server.outbox <- t
+ }
if err := cc.Connection.Close(); err != nil {
cc.Server.Logger.Errorw("error closing client connection", "RemoteAddr", cc.RemoteAddr)
@@ -180,13 +182,14 @@ func (cc *ClientConn) Disconnect() {
}
// notifyOthers sends transaction t to other clients connected to the server
-func (cc *ClientConn) notifyOthers(t Transaction) {
+func (cc *ClientConn) notifyOthers(t Transaction) (trans []Transaction) {
for _, c := range sortedClients(cc.Server.Clients) {
if c.ID != cc.ID && c.Agreed {
t.clientID = c.ID
- cc.Server.outbox <- t
+ trans = append(trans, t)
}
}
+ return trans
}
// NewReply returns a reply Transaction with fields for the ClientConn