diff options
author | Bohdan Horbeshko <bodqhrohro@gmail.com> | 2021-12-04 21:10:54 +0300 |
---|---|---|
committer | Bohdan Horbeshko <bodqhrohro@gmail.com> | 2021-12-04 21:10:54 +0300 |
commit | 105f5017c35f92a9e2f5398a06cfdd3f1da31bad (patch) | |
tree | c602c7eb3ede37718894e7dea7875490cbc8d728 /telegram/handlers.go | |
parent | bc37cf0c4f0d58752f92238a013513be9aa3caff (diff) |
Migrate to TDlib 1.7.9
Diffstat (limited to 'telegram/handlers.go')
-rw-r--r-- | telegram/handlers.go | 46 |
1 files changed, 23 insertions, 23 deletions
diff --git a/telegram/handlers.go b/telegram/handlers.go index e768f04..f8e6751 100644 --- a/telegram/handlers.go +++ b/telegram/handlers.go @@ -119,15 +119,15 @@ func (c *Client) updateHandler() { // new user discovered func (c *Client) updateUser(update *client.UpdateUser) { - c.cache.SetUser(update.User.Id, update.User) + c.cache.SetUser(update.User.ID, update.User) show, status := c.userStatusToText(update.User.Status) - go c.ProcessStatusUpdate(int64(update.User.Id), status, show) + go c.ProcessStatusUpdate(update.User.ID, status, show) } // user status changed func (c *Client) updateUserStatus(update *client.UpdateUserStatus) { show, status := c.userStatusToText(update.Status) - go c.ProcessStatusUpdate(int64(update.UserId), status, show, gateway.SPImmed(false)) + go c.ProcessStatusUpdate(update.UserID, status, show, gateway.SPImmed(false)) } // new chat discovered @@ -135,7 +135,7 @@ func (c *Client) updateNewChat(update *client.UpdateNewChat) { go func() { if update.Chat != nil && update.Chat.Photo != nil && update.Chat.Photo.Small != nil { _, err := c.client.DownloadFile(&client.DownloadFileRequest{ - FileId: update.Chat.Photo.Small.Id, + FileID: update.Chat.Photo.Small.ID, Priority: 32, Synchronous: true, }) @@ -145,7 +145,7 @@ func (c *Client) updateNewChat(update *client.UpdateNewChat) { } } - c.cache.SetChat(update.Chat.Id, update.Chat) + c.cache.SetChat(update.Chat.ID, update.Chat) var isChannel = false if update.Chat.Type.ChatTypeType() == client.TypeChatTypeSupergroup { @@ -157,21 +157,21 @@ func (c *Client) updateNewChat(update *client.UpdateNewChat) { } // don't subscribe to channel posters - if !((isChannel && update.Chat.LastReadInboxMessageId == 0) || + if !((isChannel && update.Chat.LastReadInboxMessageID == 0) || // don't subscribe to chats with no conversation // (manual adding will trigger a subscribe anyway) - (update.Chat.LastReadInboxMessageId == 0 && update.Chat.LastReadOutboxMessageId == 0)) { + (update.Chat.LastReadInboxMessageID == 0 && update.Chat.LastReadOutboxMessageID == 0)) { gateway.SendPresence( c.xmpp, c.jid, - gateway.SPFrom(strconv.FormatInt(update.Chat.Id, 10)), + gateway.SPFrom(strconv.FormatInt(update.Chat.ID, 10)), gateway.SPType("subscribe"), gateway.SPNickname(update.Chat.Title), ) } - if update.Chat.Id < 0 { - c.ProcessStatusUpdate(update.Chat.Id, update.Chat.Title, "chat") + if update.Chat.ID < 0 { + c.ProcessStatusUpdate(update.Chat.ID, update.Chat.Title, "chat") } }() } @@ -180,7 +180,7 @@ func (c *Client) updateNewChat(update *client.UpdateNewChat) { func (c *Client) updateNewMessage(update *client.UpdateNewMessage) { go func() { // guarantee sequential message delivering per chat - lock := c.getChatMessageLock(update.Message.ChatId) + lock := c.getChatMessageLock(update.Message.ChatID) lock.Lock() defer lock.Unlock() @@ -192,7 +192,7 @@ func (c *Client) updateNewMessage(update *client.UpdateNewMessage) { } log.WithFields(log.Fields{ - "chat_id": update.Message.ChatId, + "chat_id": update.Message.ChatID, }).Warn("New message from chat") text := c.messageToText(update.Message) @@ -201,7 +201,7 @@ func (c *Client) updateNewMessage(update *client.UpdateNewMessage) { // download file(s) if file != nil && !file.Local.IsDownloadingCompleted { c.client.DownloadFile(&client.DownloadFileRequest{ - FileId: file.Id, + FileID: file.ID, Priority: 32, Synchronous: true, }) @@ -212,9 +212,9 @@ func (c *Client) updateNewMessage(update *client.UpdateNewMessage) { prefix.WriteString(c.messageToPrefix(update.Message, c.formatContent(file, filename))) if text != "" { // \n if it is groupchat and message is not empty - if update.Message.ChatId < 0 { + if update.Message.ChatID < 0 { prefix.WriteString("\n") - } else if update.Message.ChatId > 0 { + } else if update.Message.ChatID > 0 { prefix.WriteString(" | ") } @@ -226,12 +226,12 @@ func (c *Client) updateNewMessage(update *client.UpdateNewMessage) { // mark message as read c.client.ViewMessages(&client.ViewMessagesRequest{ - ChatId: update.Message.ChatId, - MessageIds: []int64{update.Message.Id}, + ChatID: update.Message.ChatID, + MessageIDs: []int64{update.Message.ID}, ForceRead: true, }) // forward message to XMPP - gateway.SendMessage(c.jid, strconv.FormatInt(update.Message.ChatId, 10), text, c.xmpp) + gateway.SendMessage(c.jid, strconv.FormatInt(update.Message.ChatID, 10), text, c.xmpp) }() } @@ -240,20 +240,20 @@ func (c *Client) updateMessageContent(update *client.UpdateMessageContent) { markupFunction := formatter.EntityToMarkdown if update.NewContent.MessageContentType() == client.TypeMessageText { textContent := update.NewContent.(*client.MessageText) - text := fmt.Sprintf("✎ %v | %s", update.MessageId, formatter.Format( + text := fmt.Sprintf("✎ %v | %s", update.MessageID, formatter.Format( textContent.Text.Text, formatter.SortEntities(textContent.Text.Entities), markupFunction, )) - gateway.SendMessage(c.jid, strconv.FormatInt(update.ChatId, 10), text, c.xmpp) + gateway.SendMessage(c.jid, strconv.FormatInt(update.ChatID, 10), text, c.xmpp) } } // message(s) deleted func (c *Client) updateDeleteMessages(update *client.UpdateDeleteMessages) { if update.IsPermanent { - text := "✗ " + strings.Join(int64SliceToStringSlice(update.MessageIds), ",") - gateway.SendMessage(c.jid, strconv.FormatInt(update.ChatId, 10), text, c.xmpp) + text := "✗ " + strings.Join(int64SliceToStringSlice(update.MessageIDs), ",") + gateway.SendMessage(c.jid, strconv.FormatInt(update.ChatID, 10), text, c.xmpp) } } @@ -269,7 +269,7 @@ func (c *Client) updateFile(update *client.UpdateFile) { fmt.Sprintf( "%s/%s%s", c.content.Path, - fmt.Sprintf("%x", sha256.Sum256([]byte(update.File.Remote.Id))), + fmt.Sprintf("%x", sha256.Sum256([]byte(update.File.Remote.ID))), filepath.Ext(update.File.Local.Path), ), ) |