diff --git a/telegram/client.go b/telegram/client.go index f10bf44..e1b84fe 100644 --- a/telegram/client.go +++ b/telegram/client.go @@ -47,6 +47,12 @@ type HashedAvatar struct { File int32 } +// IntPair holds two int64 values +type IntPair struct { + ChatId int64 + MessageId int64 +} + // Client stores the metadata for lazily invoked TDlib instance type Client struct { client *client.Client @@ -69,7 +75,7 @@ type Client struct { outbox map[string]string editOutbox map[string]string - pinOutbox map[int64]chan int64 + pinOutbox map[IntPair]chan int64 DelayedStatuses map[int64]*DelayedStatus DelayedStatusesLock sync.Mutex @@ -169,7 +175,7 @@ func NewClient(conf config.TelegramConfig, jid string, component *xmpp.Component cache: cache.NewCache(), outbox: make(map[string]string), editOutbox: make(map[string]string), - pinOutbox: make(map[int64]chan int64), + pinOutbox: make(map[IntPair]chan int64), mucCache: make(map[int64]*MUCState), options: options, DelayedStatuses: make(map[int64]*DelayedStatus), diff --git a/telegram/handlers.go b/telegram/handlers.go index a1fc001..d18d356 100644 --- a/telegram/handlers.go +++ b/telegram/handlers.go @@ -407,6 +407,15 @@ func (c *Client) updateMessageContent(update *client.UpdateMessageContent) { // message(s) deleted func (c *Client) updateDeleteMessages(update *client.UpdateDeleteMessages) { + c.locks.pinOutboxLock.Lock() + for _, messageId := range update.MessageIds { + ch, chOk := c.pinOutbox[IntPair{update.ChatId, messageId}] + if chOk { + ch <-0 + } + } + c.locks.pinOutboxLock.Unlock() + if update.IsPermanent { if c.Session.IsChatIgnored(update.ChatId) { return @@ -453,7 +462,7 @@ func (c *Client) updateAuthorizationState(update *client.UpdateAuthorizationStat func (c *Client) updateMessageSendSucceeded(update *client.UpdateMessageSendSucceeded) { c.locks.pinOutboxLock.Lock() - ch, chOk := c.pinOutbox[update.OldMessageId] + ch, chOk := c.pinOutbox[IntPair{update.Message.ChatId, update.OldMessageId}] if chOk { ch <-update.Message.Id } @@ -477,7 +486,7 @@ func (c *Client) updateMessageSendSucceeded(update *client.UpdateMessageSendSucc } func (c *Client) updateMessageSendFailed(update *client.UpdateMessageSendFailed) { c.locks.pinOutboxLock.Lock() - ch, chOk := c.pinOutbox[update.OldMessageId] + ch, chOk := c.pinOutbox[IntPair{update.Message.ChatId, update.OldMessageId}] if chOk { ch <-0 } diff --git a/telegram/utils.go b/telegram/utils.go index 1c78320..29d08d8 100644 --- a/telegram/utils.go +++ b/telegram/utils.go @@ -817,13 +817,14 @@ func (c *Client) NewPinnedMessage(chatID int64, text, returnJid string) bool { return false } ch := make(chan int64) - c.pinOutbox[msg.Id] = ch + key := IntPair{chatID, msg.Id} + c.pinOutbox[key] = ch c.locks.pinOutboxLock.Unlock() newId := <-ch c.locks.pinOutboxLock.Lock() - delete(c.pinOutbox, msg.Id) + delete(c.pinOutbox, key) c.locks.pinOutboxLock.Unlock() if newId == 0 {