From 21581958c38861f3a62ef7c27d0a8a6f4db2a1f8 Mon Sep 17 00:00:00 2001 From: Jeff Halter <868228+jhalter@users.noreply.github.com> Date: Tue, 21 Jun 2022 14:03:31 -0700 Subject: Refactor notifyOthers --- hotline/client_conn.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'hotline/client_conn.go') 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 -- cgit