NotifyDeletedClient closes existing connections with the given token.
(userID uint, token string)
| 65 | |
| 66 | // NotifyDeletedClient closes existing connections with the given token. |
| 67 | func (a *API) NotifyDeletedClient(userID uint, token string) { |
| 68 | a.lock.Lock() |
| 69 | defer a.lock.Unlock() |
| 70 | if clients, ok := a.clients[userID]; ok { |
| 71 | for i := len(clients) - 1; i >= 0; i-- { |
| 72 | client := clients[i] |
| 73 | if client.token == token { |
| 74 | client.Close() |
| 75 | clients = append(clients[:i], clients[i+1:]...) |
| 76 | } |
| 77 | } |
| 78 | a.clients[userID] = clients |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | // Notify notifies the clients with the given userID that a new messages was created. |
| 83 | func (a *API) Notify(userID uint, msg *model.MessageExternal) { |