forked from MirrorHub/mautrix-whatsapp
backfill: fix bridging of ephemeral and view-once messages
This commit is contained in:
parent
159ece3e64
commit
a1e2e673dc
1 changed files with 25 additions and 8 deletions
|
@ -240,22 +240,30 @@ func (user *User) handleHistorySync(reCheckQueue chan bool, evt *waProto.History
|
||||||
conv.GetUnreadCount())
|
conv.GetUnreadCount())
|
||||||
historySyncConversation.Upsert()
|
historySyncConversation.Upsert()
|
||||||
|
|
||||||
for _, msg := range conv.GetMessages() {
|
for _, rawMsg := range conv.GetMessages() {
|
||||||
// Don't store messages that will just be skipped.
|
// Don't store messages that will just be skipped.
|
||||||
wmi := msg.GetMessage()
|
wmi := rawMsg.GetMessage()
|
||||||
msgType := getMessageType(wmi.GetMessage())
|
msg := wmi.GetMessage()
|
||||||
|
if msg.GetEphemeralMessage().GetMessage() != nil {
|
||||||
|
msg = msg.GetEphemeralMessage().GetMessage()
|
||||||
|
}
|
||||||
|
if msg.GetViewOnceMessage().GetMessage() != nil {
|
||||||
|
msg = msg.GetViewOnceMessage().GetMessage()
|
||||||
|
}
|
||||||
|
|
||||||
|
msgType := getMessageType(msg)
|
||||||
if msgType == "unknown" || msgType == "ignore" || msgType == "unknown_protocol" {
|
if msgType == "unknown" || msgType == "ignore" || msgType == "unknown_protocol" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't store unsupported messages.
|
// Don't store unsupported messages.
|
||||||
if !containsSupportedMessage(msg.GetMessage().GetMessage()) {
|
if !containsSupportedMessage(msg) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
message, err := user.bridge.DB.HistorySyncQuery.NewMessageWithValues(user.MXID, conv.GetId(), msg.Message.GetKey().GetId(), msg)
|
message, err := user.bridge.DB.HistorySyncQuery.NewMessageWithValues(user.MXID, conv.GetId(), wmi.GetKey().GetId(), rawMsg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
user.log.Warnfln("Failed to save message %s in %s. Error: %+v", msg.Message.Key.Id, conv.GetId(), err)
|
user.log.Warnfln("Failed to save message %s in %s. Error: %+v", wmi.GetKey().Id, conv.GetId(), err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
message.Insert()
|
message.Insert()
|
||||||
|
@ -410,7 +418,15 @@ func (portal *Portal) backfill(source *User, messages []*waProto.WebMessageInfo)
|
||||||
// The messages are ordered newest to oldest, so iterate them in reverse order.
|
// The messages are ordered newest to oldest, so iterate them in reverse order.
|
||||||
for i := len(messages) - 1; i >= 0; i-- {
|
for i := len(messages) - 1; i >= 0; i-- {
|
||||||
webMsg := messages[i]
|
webMsg := messages[i]
|
||||||
msgType := getMessageType(webMsg.GetMessage())
|
msg := webMsg.GetMessage()
|
||||||
|
if msg.GetEphemeralMessage().GetMessage() != nil {
|
||||||
|
msg = msg.GetEphemeralMessage().GetMessage()
|
||||||
|
}
|
||||||
|
if msg.GetViewOnceMessage().GetMessage() != nil {
|
||||||
|
msg = msg.GetViewOnceMessage().GetMessage()
|
||||||
|
}
|
||||||
|
|
||||||
|
msgType := getMessageType(msg)
|
||||||
if msgType == "unknown" || msgType == "ignore" || msgType == "unknown_protocol" {
|
if msgType == "unknown" || msgType == "ignore" || msgType == "unknown_protocol" {
|
||||||
if msgType != "ignore" {
|
if msgType != "ignore" {
|
||||||
portal.log.Debugfln("Skipping message %s with unknown type in backfill", webMsg.GetKey().GetId())
|
portal.log.Debugfln("Skipping message %s with unknown type in backfill", webMsg.GetKey().GetId())
|
||||||
|
@ -446,7 +462,8 @@ func (portal *Portal) backfill(source *User, messages []*waProto.WebMessageInfo)
|
||||||
if intent.IsCustomPuppet && !portal.bridge.Config.CanDoublePuppetBackfill(puppet.CustomMXID) {
|
if intent.IsCustomPuppet && !portal.bridge.Config.CanDoublePuppetBackfill(puppet.CustomMXID) {
|
||||||
intent = puppet.DefaultIntent()
|
intent = puppet.DefaultIntent()
|
||||||
}
|
}
|
||||||
converted := portal.convertMessage(intent, source, info, webMsg.GetMessage())
|
|
||||||
|
converted := portal.convertMessage(intent, source, info, msg)
|
||||||
if converted == nil {
|
if converted == nil {
|
||||||
portal.log.Debugfln("Skipping unsupported message %s in backfill", info.ID)
|
portal.log.Debugfln("Skipping unsupported message %s in backfill", info.ID)
|
||||||
continue
|
continue
|
||||||
|
|
Loading…
Reference in a new issue