mirror of
https://github.com/tulir/mautrix-whatsapp
synced 2024-12-14 09:23:51 +01:00
Don't mark messages older than chat info receive date as read after backfill
This commit is contained in:
parent
66f0b04a31
commit
b07412b421
4 changed files with 11 additions and 4 deletions
|
@ -21,6 +21,7 @@ import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/Rhymen/go-whatsapp"
|
"github.com/Rhymen/go-whatsapp"
|
||||||
waProto "github.com/Rhymen/go-whatsapp/binary/proto"
|
waProto "github.com/Rhymen/go-whatsapp/binary/proto"
|
||||||
|
@ -65,9 +66,13 @@ func (mq *MessageQuery) GetByMXID(mxid id.EventID) *Message {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mq *MessageQuery) GetLastInChat(chat PortalKey) *Message {
|
func (mq *MessageQuery) GetLastInChat(chat PortalKey) *Message {
|
||||||
|
return mq.GetLastInChatBefore(chat, time.Now().Unix()+60)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mq *MessageQuery) GetLastInChatBefore(chat PortalKey, maxTimestamp int64) *Message {
|
||||||
msg := mq.get("SELECT chat_jid, chat_receiver, jid, mxid, sender, timestamp, sent, content "+
|
msg := mq.get("SELECT chat_jid, chat_receiver, jid, mxid, sender, timestamp, sent, content "+
|
||||||
"FROM message WHERE chat_jid=$1 AND chat_receiver=$2 AND sent=true ORDER BY timestamp DESC LIMIT 1",
|
"FROM message WHERE chat_jid=$1 AND chat_receiver=$2 AND timestamp<=$3 AND sent=true ORDER BY timestamp DESC LIMIT 1",
|
||||||
chat.JID, chat.Receiver)
|
chat.JID, chat.Receiver, maxTimestamp)
|
||||||
if msg == nil || msg.Timestamp == 0 {
|
if msg == nil || msg.Timestamp == 0 {
|
||||||
// Old db, we don't know what the last message is.
|
// Old db, we don't know what the last message is.
|
||||||
return nil
|
return nil
|
||||||
|
|
2
go.mod
2
go.mod
|
@ -15,4 +15,4 @@ require (
|
||||||
maunium.net/go/mautrix v0.9.12
|
maunium.net/go/mautrix v0.9.12
|
||||||
)
|
)
|
||||||
|
|
||||||
replace github.com/Rhymen/go-whatsapp => github.com/tulir/go-whatsapp v0.5.2
|
replace github.com/Rhymen/go-whatsapp => github.com/tulir/go-whatsapp v0.5.3
|
||||||
|
|
2
go.sum
2
go.sum
|
@ -468,6 +468,8 @@ github.com/tulir/go-whatsapp v0.5.1 h1:nJ+ggQrO4kpNdE7VfM6y7J4xezoIHivrAlUjDpQSO
|
||||||
github.com/tulir/go-whatsapp v0.5.1/go.mod h1:7J3IIL3bEQiBJGtiZst1N4PgXHlWIartdVQLe6lcx9A=
|
github.com/tulir/go-whatsapp v0.5.1/go.mod h1:7J3IIL3bEQiBJGtiZst1N4PgXHlWIartdVQLe6lcx9A=
|
||||||
github.com/tulir/go-whatsapp v0.5.2 h1:CJcFSAoD/vXybamd9Hfa67Otg11G4EfoIgciQakunps=
|
github.com/tulir/go-whatsapp v0.5.2 h1:CJcFSAoD/vXybamd9Hfa67Otg11G4EfoIgciQakunps=
|
||||||
github.com/tulir/go-whatsapp v0.5.2/go.mod h1:7J3IIL3bEQiBJGtiZst1N4PgXHlWIartdVQLe6lcx9A=
|
github.com/tulir/go-whatsapp v0.5.2/go.mod h1:7J3IIL3bEQiBJGtiZst1N4PgXHlWIartdVQLe6lcx9A=
|
||||||
|
github.com/tulir/go-whatsapp v0.5.3 h1:e3bPLCmbBF146l8tnswqxnVLtGCWOEruJSR4luySh6I=
|
||||||
|
github.com/tulir/go-whatsapp v0.5.3/go.mod h1:7J3IIL3bEQiBJGtiZst1N4PgXHlWIartdVQLe6lcx9A=
|
||||||
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
|
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
|
||||||
github.com/urfave/cli v1.22.1 h1:+mkCCcOFKPnCmVYVcURKps1Xe+3zP90gSYGNfRkjoIY=
|
github.com/urfave/cli v1.22.1 h1:+mkCCcOFKPnCmVYVcURKps1Xe+3zP90gSYGNfRkjoIY=
|
||||||
github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
|
github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
|
||||||
|
|
2
user.go
2
user.go
|
@ -756,7 +756,7 @@ func (user *User) syncChatDoublePuppetDetails(doublePuppet *Puppet, chat Chat, j
|
||||||
}
|
}
|
||||||
intent := doublePuppet.CustomIntent()
|
intent := doublePuppet.CustomIntent()
|
||||||
if chat.UnreadCount == 0 && (justCreated || !user.bridge.Config.Bridge.MarkReadOnlyOnCreate) {
|
if chat.UnreadCount == 0 && (justCreated || !user.bridge.Config.Bridge.MarkReadOnlyOnCreate) {
|
||||||
lastMessage := user.bridge.DB.Message.GetLastInChat(chat.Portal.Key)
|
lastMessage := user.bridge.DB.Message.GetLastInChatBefore(chat.Portal.Key, chat.ReceivedAt.Unix())
|
||||||
if lastMessage != nil {
|
if lastMessage != nil {
|
||||||
err := intent.MarkReadWithContent(chat.Portal.MXID, lastMessage.MXID, &CustomReadReceipt{DoublePuppet: true})
|
err := intent.MarkReadWithContent(chat.Portal.MXID, lastMessage.MXID, &CustomReadReceipt{DoublePuppet: true})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in a new issue