login: add support for bot tokens

This commit is contained in:
Tulir Asokan
2025-12-06 21:08:46 +02:00
parent 48fed1c026
commit 10f1583da9
10 changed files with 158 additions and 24 deletions
+15 -5
View File
@@ -555,11 +555,9 @@ func (t *TelegramClient) PreHandleMatrixReaction(ctx context.Context, msg *bridg
return resp, fmt.Errorf("failed to get available reactions: %w", err)
} else if _, ok := availableReactions[keyNoVariation]; ok {
log.Debug().Msg("Not using custom emoji reaction since the emoji is available")
} else {
if documentID, ok := emojis.GetEmojiDocumentID(keyNoVariation); ok {
log.Debug().Msg("Using custom emoji reaction")
emojiID = ids.MakeEmojiIDFromDocumentID(documentID)
}
} else if documentID, ok := emojis.GetEmojiDocumentID(keyNoVariation); ok && !t.metadata.IsBot {
log.Debug().Msg("Using custom emoji reaction")
emojiID = ids.MakeEmojiIDFromDocumentID(documentID)
}
log.Debug().Str("emoji_id", string(emojiID)).Msg("Pre-handled reaction")
@@ -684,10 +682,15 @@ func (t *TelegramClient) HandleMatrixReadReceipt(ctx context.Context, msg *bridg
var readMentionsErr, readReactionsErr, readMessagesErr error
var wg sync.WaitGroup
isBot := t.metadata.IsBot
// Read mentions
wg.Add(1)
go func() {
defer wg.Done()
if isBot {
return
}
_, readMentionsErr = t.client.API().MessagesReadMentions(ctx, &tg.MessagesReadMentionsRequest{
Peer: inputPeer,
TopMsgID: topicID,
@@ -698,6 +701,9 @@ func (t *TelegramClient) HandleMatrixReadReceipt(ctx context.Context, msg *bridg
wg.Add(1)
go func() {
defer wg.Done()
if isBot {
return
}
_, readMentionsErr = t.client.API().MessagesReadReactions(ctx, &tg.MessagesReadReactionsRequest{
Peer: inputPeer,
TopMsgID: topicID,
@@ -709,6 +715,10 @@ func (t *TelegramClient) HandleMatrixReadReceipt(ctx context.Context, msg *bridg
go func() {
defer wg.Done()
if isBot {
return
}
message := msg.ExactMessage
if message == nil {
message, readMessagesErr = t.main.Bridge.DB.Message.GetLastPartAtOrBeforeTime(ctx, msg.Portal.PortalKey, time.Now())