diff --git a/telegram/utils.go b/telegram/utils.go index fd7a433..40553a4 100644 --- a/telegram/utils.go +++ b/telegram/utils.go @@ -304,7 +304,7 @@ func (c *Client) ProcessStatusUpdate(chatID int64, status string, show string, o } // JoinMUC saves MUC join fact and sends initialization data -func (c *Client) JoinMUC(chatId int64, resource string) { +func (c *Client) JoinMUC(chatId int64, resource string, limit int32) { // save the nickname in this MUC, also as a marker of join c.locks.mucResourcesLock.Lock() oldMap, ok := c.mucResources[chatId] @@ -324,7 +324,7 @@ func (c *Client) JoinMUC(chatId int64, resource string) { c.sendMUCStatuses(chatId) - messages, err := c.getNLastMessages(chatId, 20) + messages, err := c.getNLastMessages(chatId, limit) if err == nil { c.sendMessagesReverse(chatId, messages, false, c.jid+"/"+resource) } diff --git a/xmpp/handlers.go b/xmpp/handlers.go index bb2064a..ff8fb21 100644 --- a/xmpp/handlers.go +++ b/xmpp/handlers.go @@ -292,7 +292,7 @@ func HandlePresence(s xmpp.Sender, p stanza.Packet) { var mucExt stanza.MucPresence prs.Get(&mucExt) if mucExt.XMLName.Space != "" { - handleMUCPresence(s, prs) + handleMUCPresence(s, prs, mucExt) } } @@ -403,7 +403,7 @@ func handlePresence(s xmpp.Sender, p stanza.Presence) { } } -func handleMUCPresence(s xmpp.Sender, p stanza.Presence) { +func handleMUCPresence(s xmpp.Sender, p stanza.Presence, mucExt stanza.MucPresence) { log.WithFields(log.Fields{ "type": p.Type, "from": p.From, @@ -458,7 +458,11 @@ func handleMUCPresence(s xmpp.Sender, p stanza.Presence) { return } - session.JoinMUC(chatId, fromResource) + limit, ok := mucExt.History.MaxStanzas.Get() + if !ok { + limit = 20 + } + session.JoinMUC(chatId, fromResource, int32(limit)) } } }