Safeguards for MUC subject change

This commit is contained in:
Bohdan Horbeshko 2025-05-26 21:58:35 -04:00
parent 2c8c7f029d
commit dd8267df2c
3 changed files with 22 additions and 6 deletions

View file

@ -47,6 +47,12 @@ type HashedAvatar struct {
File int32 File int32
} }
// IntPair holds two int64 values
type IntPair struct {
ChatId int64
MessageId int64
}
// Client stores the metadata for lazily invoked TDlib instance // Client stores the metadata for lazily invoked TDlib instance
type Client struct { type Client struct {
client *client.Client client *client.Client
@ -69,7 +75,7 @@ type Client struct {
outbox map[string]string outbox map[string]string
editOutbox map[string]string editOutbox map[string]string
pinOutbox map[int64]chan int64 pinOutbox map[IntPair]chan int64
DelayedStatuses map[int64]*DelayedStatus DelayedStatuses map[int64]*DelayedStatus
DelayedStatusesLock sync.Mutex DelayedStatusesLock sync.Mutex
@ -169,7 +175,7 @@ func NewClient(conf config.TelegramConfig, jid string, component *xmpp.Component
cache: cache.NewCache(), cache: cache.NewCache(),
outbox: make(map[string]string), outbox: make(map[string]string),
editOutbox: 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), mucCache: make(map[int64]*MUCState),
options: options, options: options,
DelayedStatuses: make(map[int64]*DelayedStatus), DelayedStatuses: make(map[int64]*DelayedStatus),

View file

@ -407,6 +407,15 @@ func (c *Client) updateMessageContent(update *client.UpdateMessageContent) {
// message(s) deleted // message(s) deleted
func (c *Client) updateDeleteMessages(update *client.UpdateDeleteMessages) { 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 update.IsPermanent {
if c.Session.IsChatIgnored(update.ChatId) { if c.Session.IsChatIgnored(update.ChatId) {
return return
@ -453,7 +462,7 @@ func (c *Client) updateAuthorizationState(update *client.UpdateAuthorizationStat
func (c *Client) updateMessageSendSucceeded(update *client.UpdateMessageSendSucceeded) { func (c *Client) updateMessageSendSucceeded(update *client.UpdateMessageSendSucceeded) {
c.locks.pinOutboxLock.Lock() c.locks.pinOutboxLock.Lock()
ch, chOk := c.pinOutbox[update.OldMessageId] ch, chOk := c.pinOutbox[IntPair{update.Message.ChatId, update.OldMessageId}]
if chOk { if chOk {
ch <-update.Message.Id ch <-update.Message.Id
} }
@ -477,7 +486,7 @@ func (c *Client) updateMessageSendSucceeded(update *client.UpdateMessageSendSucc
} }
func (c *Client) updateMessageSendFailed(update *client.UpdateMessageSendFailed) { func (c *Client) updateMessageSendFailed(update *client.UpdateMessageSendFailed) {
c.locks.pinOutboxLock.Lock() c.locks.pinOutboxLock.Lock()
ch, chOk := c.pinOutbox[update.OldMessageId] ch, chOk := c.pinOutbox[IntPair{update.Message.ChatId, update.OldMessageId}]
if chOk { if chOk {
ch <-0 ch <-0
} }

View file

@ -817,13 +817,14 @@ func (c *Client) NewPinnedMessage(chatID int64, text, returnJid string) bool {
return false return false
} }
ch := make(chan int64) ch := make(chan int64)
c.pinOutbox[msg.Id] = ch key := IntPair{chatID, msg.Id}
c.pinOutbox[key] = ch
c.locks.pinOutboxLock.Unlock() c.locks.pinOutboxLock.Unlock()
newId := <-ch newId := <-ch
c.locks.pinOutboxLock.Lock() c.locks.pinOutboxLock.Lock()
delete(c.pinOutbox, msg.Id) delete(c.pinOutbox, key)
c.locks.pinOutboxLock.Unlock() c.locks.pinOutboxLock.Unlock()
if newId == 0 { if newId == 0 {