aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBohdan Horbeshko <bodqhrohro@gmail.com>2023-09-19 14:57:52 +0300
committerBohdan Horbeshko <bodqhrohro@gmail.com>2023-09-19 14:57:52 +0300
commitb68c07025d1dd077c73ec3b4052ea453612e3e9c (patch)
tree2e1cc8733919633b7849f4b94371fc2863f00019
parente8bde731642f50c8d272c33343ec78ca70405377 (diff)
Add MUC history limit (maxstanzas only)
-rw-r--r--telegram/utils.go4
-rw-r--r--xmpp/handlers.go10
2 files changed, 9 insertions, 5 deletions
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))
}
}
}