mirror of
https://github.com/tulir/mautrix-whatsapp
synced 2024-11-17 23:43:10 +01:00
Store server timestamp of outgoing messages in db
This commit is contained in:
parent
2bcc15cb47
commit
baf2482c3a
4 changed files with 9 additions and 8 deletions
|
@ -154,9 +154,10 @@ func (msg *Message) Insert() {
|
|||
}
|
||||
}
|
||||
|
||||
func (msg *Message) MarkSent() {
|
||||
func (msg *Message) MarkSent(ts time.Time) {
|
||||
msg.Sent = true
|
||||
_, err := msg.db.Exec("UPDATE message SET sent=true WHERE chat_jid=$1 AND chat_receiver=$2 AND jid=$3", msg.Chat.JID, msg.Chat.Receiver, msg.JID)
|
||||
msg.Timestamp = ts
|
||||
_, err := msg.db.Exec("UPDATE message SET sent=true, timestamp=$4 WHERE chat_jid=$1 AND chat_receiver=$2 AND jid=$3", msg.Chat.JID, msg.Chat.Receiver, msg.JID, ts.Unix())
|
||||
if err != nil {
|
||||
msg.log.Warnfln("Failed to update %s@%s: %v", msg.Chat, msg.JID, err)
|
||||
}
|
||||
|
|
2
go.mod
2
go.mod
|
@ -8,7 +8,7 @@ require (
|
|||
github.com/mattn/go-sqlite3 v1.14.9
|
||||
github.com/prometheus/client_golang v1.11.0
|
||||
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
|
||||
go.mau.fi/whatsmeow v0.0.0-20211031184143-96a325ea0d2e
|
||||
go.mau.fi/whatsmeow v0.0.0-20211031213406-f7df98c1e267
|
||||
golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d
|
||||
google.golang.org/protobuf v1.27.1
|
||||
gopkg.in/yaml.v2 v2.4.0
|
||||
|
|
4
go.sum
4
go.sum
|
@ -139,8 +139,8 @@ github.com/tidwall/sjson v1.2.3 h1:5+deguEhHSEjmuICXZ21uSSsXotWMA0orU783+Z7Cp8=
|
|||
github.com/tidwall/sjson v1.2.3/go.mod h1:5WdjKx3AQMvCJ4RG6/2UYT7dLrGvJUV1x4jdTAyGvZs=
|
||||
go.mau.fi/libsignal v0.0.0-20211024113310-f9fc6a1855f2 h1:xpQTMgJGGaF+c8jV/LA/FVXAPJxZbSAGeflOc+Ly6uQ=
|
||||
go.mau.fi/libsignal v0.0.0-20211024113310-f9fc6a1855f2/go.mod h1:3XlVlwOfp8f9Wri+C1D4ORqgUsN4ZvunJOoPjQMBhos=
|
||||
go.mau.fi/whatsmeow v0.0.0-20211031184143-96a325ea0d2e h1:XZzLOVrnccvvzZz+PhonjTRfHmycuToZiwBNiI+g1KM=
|
||||
go.mau.fi/whatsmeow v0.0.0-20211031184143-96a325ea0d2e/go.mod h1:ODEmmqeUn9eBDQHFc1S902YA3YFLtmaBujYRRFl53jI=
|
||||
go.mau.fi/whatsmeow v0.0.0-20211031213406-f7df98c1e267 h1:l4IhbH3HxCG121i1uqj5pU3NX0t4ERbwiJkKAguk1bQ=
|
||||
go.mau.fi/whatsmeow v0.0.0-20211031213406-f7df98c1e267/go.mod h1:ODEmmqeUn9eBDQHFc1S902YA3YFLtmaBujYRRFl53jI=
|
||||
golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
|
|
|
@ -2389,14 +2389,14 @@ func (portal *Portal) HandleMatrixMessage(sender *User, evt *event.Event) {
|
|||
info := portal.generateMessageInfo(sender)
|
||||
dbMsg := portal.markHandled(nil, info, evt.ID, false, true, false)
|
||||
portal.log.Debugln("Sending event", evt.ID, "to WhatsApp", info.ID)
|
||||
err := sender.Client.SendMessage(portal.Key.JID, info.ID, msg)
|
||||
ts, err := sender.Client.SendMessage(portal.Key.JID, info.ID, msg)
|
||||
if err != nil {
|
||||
portal.log.Errorln("Error sending message: %v", err)
|
||||
portal.sendErrorMessage(err.Error(), true)
|
||||
} else {
|
||||
portal.log.Debugfln("Handled Matrix event %s", evt.ID)
|
||||
portal.sendDeliveryReceipt(evt.ID)
|
||||
dbMsg.MarkSent()
|
||||
dbMsg.MarkSent(ts)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2415,7 +2415,7 @@ func (portal *Portal) HandleMatrixRedaction(sender *User, evt *event.Event) {
|
|||
}
|
||||
|
||||
portal.log.Debugfln("Sending redaction %s of %s/%s to WhatsApp", evt.ID, msg.MXID, msg.JID)
|
||||
err := sender.Client.RevokeMessage(portal.Key.JID, msg.JID)
|
||||
_, err := sender.Client.RevokeMessage(portal.Key.JID, msg.JID)
|
||||
if err != nil {
|
||||
portal.log.Errorfln("Error handling Matrix redaction %s: %v", evt.ID, err)
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue