forked from MirrorHub/mautrix-whatsapp
Merge pull request #486 from mautrix/sumner/bri-3092
backfill: add notification of disappearing messages at correct timestamp
This commit is contained in:
commit
2abbf160a7
2 changed files with 43 additions and 2 deletions
|
@ -40,7 +40,14 @@ func (bq *BackfillQueue) RunLoop(user *User) {
|
||||||
if backfill.BackfillType == database.BackfillImmediate || backfill.BackfillType == database.BackfillForward {
|
if backfill.BackfillType == database.BackfillImmediate || backfill.BackfillType == database.BackfillForward {
|
||||||
bq.ImmediateBackfillRequests <- backfill
|
bq.ImmediateBackfillRequests <- backfill
|
||||||
} else {
|
} else {
|
||||||
bq.DeferredBackfillRequests <- backfill
|
select {
|
||||||
|
case <-bq.ReCheckQueue:
|
||||||
|
// If a queue re-check is requested, interrupt sending the
|
||||||
|
// backfill request to the deferred channel so that
|
||||||
|
// immediate backfills can happen ASAP.
|
||||||
|
continue
|
||||||
|
case bq.DeferredBackfillRequests <- backfill:
|
||||||
|
}
|
||||||
}
|
}
|
||||||
backfill.MarkDone()
|
backfill.MarkDone()
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -158,7 +158,19 @@ func (user *User) backfillInChunks(req *database.Backfill, conv *database.Histor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
allMsgs := user.bridge.DB.HistorySyncQuery.GetMessagesBetween(user.MXID, conv.ConversationID, req.TimeStart, req.TimeEnd, req.MaxTotalEvents)
|
allMsgs := user.bridge.DB.HistorySyncQuery.GetMessagesBetween(user.MXID, conv.ConversationID, req.TimeStart, req.TimeEnd, req.MaxTotalEvents)
|
||||||
if len(allMsgs) == 0 {
|
|
||||||
|
sendDisappearedNotice := false
|
||||||
|
// If expired messages are on, and a notice has not been sent to this chat
|
||||||
|
// about it having disappeared messages at the conversation timestamp, send
|
||||||
|
// a notice indicating so.
|
||||||
|
if len(allMsgs) == 0 && conv.EphemeralExpiration != nil && *conv.EphemeralExpiration > 0 {
|
||||||
|
lastMessage := portal.bridge.DB.Message.GetLastInChat(portal.Key)
|
||||||
|
if lastMessage == nil || !conv.LastMessageTimestamp.Equal(lastMessage.Timestamp) {
|
||||||
|
sendDisappearedNotice = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !sendDisappearedNotice && len(allMsgs) == 0 {
|
||||||
user.log.Debugfln("Not backfilling %s: no bridgeable messages found", portal.Key.JID)
|
user.log.Debugfln("Not backfilling %s: no bridgeable messages found", portal.Key.JID)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -172,6 +184,28 @@ func (user *User) backfillInChunks(req *database.Backfill, conv *database.Histor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if sendDisappearedNotice {
|
||||||
|
user.log.Debugfln("Sending notice to %s that there are disappeared messages ending at %v", portal.Key.JID, conv.LastMessageTimestamp)
|
||||||
|
resp, err := portal.sendMessage(portal.MainIntent(), event.EventMessage, &event.MessageEventContent{
|
||||||
|
MsgType: event.MsgNotice,
|
||||||
|
Body: portal.formatDisappearingMessageNotice(),
|
||||||
|
}, nil, conv.LastMessageTimestamp.UnixMilli())
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
portal.log.Errorln("Error sending disappearing messages notice event")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
msg := portal.bridge.DB.Message.New()
|
||||||
|
msg.Chat = portal.Key
|
||||||
|
msg.MXID = resp.EventID
|
||||||
|
msg.JID = types.MessageID(resp.EventID)
|
||||||
|
msg.Timestamp = conv.LastMessageTimestamp
|
||||||
|
msg.Sent = true
|
||||||
|
msg.Insert()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
user.log.Infofln("Backfilling %d messages in %s, %d messages at a time (queue ID: %d)", len(allMsgs), portal.Key.JID, req.MaxBatchEvents, req.QueueID)
|
user.log.Infofln("Backfilling %d messages in %s, %d messages at a time (queue ID: %d)", len(allMsgs), portal.Key.JID, req.MaxBatchEvents, req.QueueID)
|
||||||
toBackfill := allMsgs[0:]
|
toBackfill := allMsgs[0:]
|
||||||
var insertionEventIds []id.EventID
|
var insertionEventIds []id.EventID
|
||||||
|
|
Loading…
Reference in a new issue