diff options
author | Bohdan Horbeshko <bodqhrohro@gmail.com> | 2023-09-19 11:23:39 +0300 |
---|---|---|
committer | Bohdan Horbeshko <bodqhrohro@gmail.com> | 2023-09-19 11:23:39 +0300 |
commit | e77caf2c42c079062ade31f928a40b7654ac9bfd (patch) | |
tree | 81893edc63a503e277778370f5aa5509ef86eed4 /telegram/commands.go | |
parent | c1887e5a1ed80fd06795a1017c821375562ff70b (diff) |
Send recent history on MUC join
Diffstat (limited to 'telegram/commands.go')
-rw-r--r-- | telegram/commands.go | 48 |
1 files changed, 5 insertions, 43 deletions
diff --git a/telegram/commands.go b/telegram/commands.go index 87fff72..d365d4e 100644 --- a/telegram/commands.go +++ b/telegram/commands.go @@ -193,23 +193,6 @@ 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] - reply, _ := c.getMessageReply(message) - - gateway.SendMessage( - c.jid, - strconv.FormatInt(chatID, 10), - c.formatMessage(0, 0, false, message), - strconv.FormatInt(message.Id, 10), - c.xmpp, - reply, - false, - ) - } -} - func (c *Client) usernameOrIDToID(username string) (int64, error) { userID, err := strconv.ParseInt(username, 10, 64) // couldn't parse the id, try to lookup as a username @@ -1005,7 +988,7 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool) return err.Error(), true } - c.sendMessagesReverse(chatID, messages.Messages) + c.sendMessagesReverse(chatID, messages.Messages, true, "") // get latest entries from history case "history": var limit int32 = 10 @@ -1016,32 +999,11 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool) } } - var newMessages *client.Messages - var messages []*client.Message - var err error - var fromId int64 - for _ = range make([]struct{}, limit) { // safety limit - if len(messages) > 0 { - fromId = messages[len(messages)-1].Id - } - - newMessages, err = c.client.GetChatHistory(&client.GetChatHistoryRequest{ - ChatId: chatID, - FromMessageId: fromId, - Limit: limit, - }) - if err != nil { - return err.Error(), true - } - - messages = append(messages, newMessages.Messages...) - - if len(newMessages.Messages) == 0 || len(messages) >= int(limit) { - break - } + messages, err := c.getNLastMessages(chatID, limit) + if err != nil { + return err.Error(), true } - - c.sendMessagesReverse(chatID, messages) + c.sendMessagesReverse(chatID, messages, true, "") // chat members case "members": var query string |