diff options
author | bodqhrohro <bodqhrohro@gmail.com> | 2019-11-29 03:51:41 +0300 |
---|---|---|
committer | bodqhrohro <bodqhrohro@gmail.com> | 2019-11-29 03:51:41 +0300 |
commit | dbe87fafa8fb3c38d6cb22ac335cc76b70b607a6 (patch) | |
tree | 784f16c7e27444c03b865e1f4c03aadac1f18bf8 /telegram/handlers.go | |
parent | bcf222b53db2199cb6c784ac8c5b7105d794b6c9 (diff) |
Handle updates of user status
Diffstat (limited to 'telegram/handlers.go')
-rw-r--r-- | telegram/handlers.go | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/telegram/handlers.go b/telegram/handlers.go new file mode 100644 index 0000000..1195831 --- /dev/null +++ b/telegram/handlers.go @@ -0,0 +1,38 @@ +package telegram + +import ( + log "github.com/sirupsen/logrus" + "github.com/zelenin/go-tdlib/client" +) + +func uhOh() { + log.Fatal("Update type mismatch") +} + +func (c *Client) updateHandler() { + listener := c.client.GetListener() + defer listener.Close() + + for update := range listener.Updates { + if update.GetClass() == client.ClassUpdate { + switch update.GetType() { + case client.TypeUpdateUser: + typedUpdate, ok := update.(*client.UpdateUser) + if !ok { + uhOh() + } + c.updateUser(typedUpdate) + default: + // log only handled types + continue + } + + log.Debugf("%#v", update) + } + } +} + +func (c *Client) updateUser(update *client.UpdateUser) { + cache.users[update.User.Id] = update.User + c.processStatusUpdate(update.User.Id, &update.User.Status) +} |