Add MUC history limit (maxstanzas only)

muc
Bohdan Horbeshko 8 months ago
parent e8bde73164
commit b68c07025d

@ -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)
}

@ -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))
}
}
}

Loading…
Cancel
Save