mirror of
https://dev.narayana.im/narayana/telegabber.git
synced 2026-08-05 12:17:06 +00:00
Take flip-page into account when calculating MAM RSM count/index
This commit is contained in:
parent
b9109d48d5
commit
0f10dbff8c
1 changed files with 20 additions and 5 deletions
|
|
@ -2549,11 +2549,21 @@ func handleSetQueryMAM2(s xmpp.Sender, iq *stanza.IQ, query *extensions.MAM2Quer
|
||||||
log.Debugf("MAM: beyond")
|
log.Debugf("MAM: beyond")
|
||||||
} else {
|
} else {
|
||||||
if len(messages) > 0 {
|
if len(messages) > 0 {
|
||||||
|
firstMsgId := messages[0].Id
|
||||||
|
lastMsgId := messages[len(messages)-1].Id
|
||||||
if fromStart {
|
if fromStart {
|
||||||
overallyFirstMessageId = messages[0].Id
|
if reverse {
|
||||||
|
overallyFirstMessageId = lastMsgId
|
||||||
|
} else {
|
||||||
|
overallyFirstMessageId = firstMsgId
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if complete {
|
if complete {
|
||||||
overallyLastMessageId = messages[len(messages)-1].Id
|
if reverse {
|
||||||
|
overallyLastMessageId = firstMsgId
|
||||||
|
} else {
|
||||||
|
overallyLastMessageId = lastMsgId
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2581,17 +2591,22 @@ func handleSetQueryMAM2(s xmpp.Sender, iq *stanza.IQ, query *extensions.MAM2Quer
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(messages) > 0 {
|
if len(messages) > 0 {
|
||||||
|
firstMsgId := messages[0].Id
|
||||||
|
lastMsgId := messages[len(messages)-1].Id
|
||||||
|
if reverse {
|
||||||
|
firstMsgId, lastMsgId = lastMsgId, firstMsgId
|
||||||
|
}
|
||||||
rs.First = &stanza.First{
|
rs.First = &stanza.First{
|
||||||
Content: strconv.FormatInt(messages[0].Id, 10),
|
Content: strconv.FormatInt(firstMsgId, 10),
|
||||||
}
|
}
|
||||||
if firstMsgPositionCount != 0 {
|
if firstMsgPositionCount != 0 {
|
||||||
rsmFirstMsgPosition, rsmFirstMsgPositionErr := session.GetChatMessagePosition(toID, messages[0].Id)
|
rsmFirstMsgPosition, rsmFirstMsgPositionErr := session.GetChatMessagePosition(toID, firstMsgId)
|
||||||
if rsmFirstMsgPositionErr == nil && rsmFirstMsgPosition != nil {
|
if rsmFirstMsgPositionErr == nil && rsmFirstMsgPosition != nil {
|
||||||
index := int(firstMsgPositionCount - rsmFirstMsgPosition.Count)
|
index := int(firstMsgPositionCount - rsmFirstMsgPosition.Count)
|
||||||
rs.First.Index = &index
|
rs.First.Index = &index
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
last := strconv.FormatInt(messages[len(messages)-1].Id, 10)
|
last := strconv.FormatInt(lastMsgId, 10)
|
||||||
rs.Last = &last
|
rs.Last = &last
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue