aboutsummaryrefslogtreecommitdiff
path: root/telegram
diff options
context:
space:
mode:
authorBohdan Horbeshko <bodqhrohro@gmail.com>2023-03-04 05:41:45 +0300
committerBohdan Horbeshko <bodqhrohro@gmail.com>2023-03-04 05:41:45 +0300
commit6e32c62f8dac5ccc97dd0a6067965ba2689f3c86 (patch)
tree8991478d056f538ed1782bfb66e6071486b8c9bf /telegram
parentb3d66993e5962d2b961631e3afa578967a7b3d8a (diff)
Assign IDs from Telegram to XMPP messages
Diffstat (limited to 'telegram')
-rw-r--r--telegram/commands.go5
-rw-r--r--telegram/connect.go8
-rw-r--r--telegram/handlers.go4
-rw-r--r--telegram/utils.go14
4 files changed, 21 insertions, 10 deletions
diff --git a/telegram/commands.go b/telegram/commands.go
index 95afd8a..957c335 100644
--- a/telegram/commands.go
+++ b/telegram/commands.go
@@ -183,10 +183,13 @@ func (c *Client) unsubscribe(chatID int64) error {
func (c *Client) sendMessagesReverse(chatID int64, messages []*client.Message) {
for i := len(messages) - 1; i >= 0; i-- {
+ message := messages[i]
+
gateway.SendMessage(
c.jid,
strconv.FormatInt(chatID, 10),
- c.formatMessage(0, 0, false, messages[i]),
+ c.formatMessage(0, 0, false, message),
+ strconv.FormatInt(message.Id, 10),
c.xmpp,
)
}
diff --git a/telegram/connect.go b/telegram/connect.go
index 0b9a195..b4957b1 100644
--- a/telegram/connect.go
+++ b/telegram/connect.go
@@ -219,20 +219,20 @@ func (c *Client) interactor() {
if c.Session.Login != "" {
c.authorizer.PhoneNumber <- c.Session.Login
} else {
- gateway.SendMessage(c.jid, "", "Please, enter your Telegram login via /login 12345", c.xmpp)
+ gateway.SendMessage(c.jid, "", "Please, enter your Telegram login via /login 12345", "", c.xmpp)
}
// stage 1: wait for auth code
case client.TypeAuthorizationStateWaitCode:
log.Warn("Waiting for authorization code...")
- gateway.SendMessage(c.jid, "", "Please, enter authorization code via /code 12345", c.xmpp)
+ gateway.SendMessage(c.jid, "", "Please, enter authorization code via /code 12345", "", c.xmpp)
// stage 1b: wait for registration
case client.TypeAuthorizationStateWaitRegistration:
log.Warn("Waiting for full name...")
- gateway.SendMessage(c.jid, "", "This number is not registered yet! Please, enter your name via /setname John Doe", c.xmpp)
+ gateway.SendMessage(c.jid, "", "This number is not registered yet! Please, enter your name via /setname John Doe", "", c.xmpp)
// stage 2: wait for 2fa
case client.TypeAuthorizationStateWaitPassword:
log.Warn("Waiting for 2FA password...")
- gateway.SendMessage(c.jid, "", "Please, enter 2FA passphrase via /password 12345", c.xmpp)
+ gateway.SendMessage(c.jid, "", "Please, enter 2FA passphrase via /password 12345", "", c.xmpp)
}
}
}
diff --git a/telegram/handlers.go b/telegram/handlers.go
index 126d858..517fb54 100644
--- a/telegram/handlers.go
+++ b/telegram/handlers.go
@@ -242,7 +242,7 @@ func (c *Client) updateMessageContent(update *client.UpdateMessageContent) {
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, "e" + strconv.FormatInt(update.MessageId, 10), c.xmpp)
}
}
@@ -256,7 +256,7 @@ func (c *Client) updateDeleteMessages(update *client.UpdateDeleteMessages) {
deleteChar = "✗ "
}
text := deleteChar + strings.Join(int64SliceToStringSlice(update.MessageIds), ",")
- gateway.SendMessage(c.jid, strconv.FormatInt(update.ChatId, 10), text, c.xmpp)
+ gateway.SendMessage(c.jid, strconv.FormatInt(update.ChatId, 10), text, "", c.xmpp)
}
}
diff --git a/telegram/utils.go b/telegram/utils.go
index dabb8a2..e58f6bf 100644
--- a/telegram/utils.go
+++ b/telegram/utils.go
@@ -806,9 +806,11 @@ func (c *Client) ProcessIncomingMessage(chatId int64, message *client.Message) {
ForceRead: true,
})
// forward message to XMPP
- gateway.SendMessageWithOOB(c.jid, strconv.FormatInt(chatId, 10), text, c.xmpp, oob)
+ sId := strconv.FormatInt(message.Id, 10)
+ sChatId := strconv.FormatInt(chatId, 10)
+ gateway.SendMessageWithOOB(c.jid, sChatId, text, sId, c.xmpp, oob)
if auxText != "" {
- gateway.SendMessage(c.jid, strconv.FormatInt(chatId, 10), auxText, c.xmpp)
+ gateway.SendMessage(c.jid, sChatId, auxText, sId, c.xmpp)
}
}
@@ -823,7 +825,7 @@ func (c *Client) ProcessOutgoingMessage(chatID int64, text string, returnJid str
// try to execute commands
response, isCommand := c.ProcessChatCommand(chatID, text)
if response != "" {
- gateway.SendMessage(returnJid, strconv.FormatInt(chatID, 10), response, c.xmpp)
+ gateway.SendMessage(returnJid, strconv.FormatInt(chatID, 10), response, "", c.xmpp)
}
// do not send on success
if isCommand {
@@ -849,6 +851,7 @@ func (c *Client) ProcessOutgoingMessage(chatID int64, text string, returnJid str
returnJid,
strconv.FormatInt(chatID, 10),
fmt.Sprintf("Failed to fetch the uploaded file: %s", err.Error()),
+ "",
c.xmpp,
)
return nil
@@ -861,6 +864,7 @@ func (c *Client) ProcessOutgoingMessage(chatID int64, text string, returnJid str
returnJid,
strconv.FormatInt(chatID, 10),
fmt.Sprintf("Received status code %v", response.StatusCode),
+ "",
c.xmpp,
)
return nil
@@ -872,6 +876,7 @@ func (c *Client) ProcessOutgoingMessage(chatID int64, text string, returnJid str
returnJid,
strconv.FormatInt(chatID, 10),
fmt.Sprintf("Failed to create a temporary directory: %s", err.Error()),
+ "",
c.xmpp,
)
return nil
@@ -882,6 +887,7 @@ func (c *Client) ProcessOutgoingMessage(chatID int64, text string, returnJid str
returnJid,
strconv.FormatInt(chatID, 10),
fmt.Sprintf("Failed to create a temporary file: %s", err.Error()),
+ "",
c.xmpp,
)
return nil
@@ -893,6 +899,7 @@ func (c *Client) ProcessOutgoingMessage(chatID int64, text string, returnJid str
returnJid,
strconv.FormatInt(chatID, 10),
fmt.Sprintf("Failed to write a temporary file: %s", err.Error()),
+ "",
c.xmpp,
)
return nil
@@ -943,6 +950,7 @@ func (c *Client) ProcessOutgoingMessage(chatID int64, text string, returnJid str
returnJid,
strconv.FormatInt(chatID, 10),
fmt.Sprintf("Not sent: %s", err.Error()),
+ "",
c.xmpp,
)
}