summaryrefslogtreecommitdiffstats
path: root/bridge/whatsappmulti/handlers.go
diff options
context:
space:
mode:
authorJoseph Mansy <36427684+yousefmansy1@users.noreply.github.com>2023-03-09 12:57:19 -0800
committerGitHub <noreply@github.com>2023-03-09 21:57:19 +0100
commitd00dcf3f58ba8f6a0919e8bdadfe9ba89864ed8d (patch)
treef3261b9d1963d5899fd267f414cd6867d9c44a78 /bridge/whatsappmulti/handlers.go
parentd5980303e5344b5c7c0804f712c4c5365fd6c929 (diff)
downloadmatterbridge-msglm-d00dcf3f58ba8f6a0919e8bdadfe9ba89864ed8d.tar.gz
matterbridge-msglm-d00dcf3f58ba8f6a0919e8bdadfe9ba89864ed8d.tar.bz2
matterbridge-msglm-d00dcf3f58ba8f6a0919e8bdadfe9ba89864ed8d.zip
Handle Whatsapp threading/replies (whatsapp) (#1974)
* Handle Whatsapp threading/replies. In this change we are updating whatsapp message IDs to include sender JID as this is necessary to reply to a message https://github.com/tulir/whatsmeow/issues/88#issuecomment-1093195237 https://github.com/tulir/whatsmeow/discussions/148#discussioncomment-3094325 Based on commit 6afa93e537c53b371db37f35a3546ff0fb669416 from #1934 Author: Iiro Laiho <iiro.laiho@iki.fi> * Fix replies. Sender JID can have a `:` inside of it, using `/` as a delimiter now. Added messageID parser + struct. messages sent with an attachment do not show replies But at least common `sendMessage` will make repies from whatsapp to an attachement bridge across. The new message ID format broke message deleting, so we change the messageID into the real id at the beginning of send. We really do need the extra info for when we reply to a message though. * Refactored message replies. file/Image/audio/replies all work now.
Diffstat (limited to 'bridge/whatsappmulti/handlers.go')
-rw-r--r--bridge/whatsappmulti/handlers.go24
1 files changed, 17 insertions, 7 deletions
diff --git a/bridge/whatsappmulti/handlers.go b/bridge/whatsappmulti/handlers.go
index fd75be09..b8e78572 100644
--- a/bridge/whatsappmulti/handlers.go
+++ b/bridge/whatsappmulti/handlers.go
@@ -1,3 +1,4 @@
+//go:build whatsappmulti
// +build whatsappmulti
package bwhatsapp
@@ -89,6 +90,12 @@ func (b *Bwhatsapp) handleTextMessage(messageInfo types.MessageInfo, msg *proto.
}
}
+ parentID := ""
+ if msg.GetExtendedTextMessage() != nil {
+ ci := msg.GetExtendedTextMessage().GetContextInfo()
+ parentID = getParentIdFromCtx(ci)
+ }
+
rmsg := config.Message{
UserID: senderJID.String(),
Username: senderName,
@@ -97,8 +104,8 @@ func (b *Bwhatsapp) handleTextMessage(messageInfo types.MessageInfo, msg *proto.
Account: b.Account,
Protocol: b.Protocol,
Extra: make(map[string][]interface{}),
- // ParentID: TODO, // TODO handle thread replies // map from Info.QuotedMessageID string
- ID: messageInfo.ID,
+ ID: getMessageIdFormat(senderJID, messageInfo.ID),
+ ParentID: parentID,
}
if avatarURL, exists := b.userAvatars[senderJID.String()]; exists {
@@ -130,7 +137,8 @@ func (b *Bwhatsapp) handleImageMessage(msg *events.Message) {
Account: b.Account,
Protocol: b.Protocol,
Extra: make(map[string][]interface{}),
- ID: msg.Info.ID,
+ ID: getMessageIdFormat(senderJID, msg.Info.ID),
+ ParentID: getParentIdFromCtx(ci),
}
if avatarURL, exists := b.userAvatars[senderJID.String()]; exists {
@@ -193,7 +201,8 @@ func (b *Bwhatsapp) handleVideoMessage(msg *events.Message) {
Account: b.Account,
Protocol: b.Protocol,
Extra: make(map[string][]interface{}),
- ID: msg.Info.ID,
+ ID: getMessageIdFormat(senderJID, msg.Info.ID),
+ ParentID: getParentIdFromCtx(ci),
}
if avatarURL, exists := b.userAvatars[senderJID.String()]; exists {
@@ -251,7 +260,6 @@ func (b *Bwhatsapp) handleAudioMessage(msg *events.Message) {
if senderJID == (types.JID{}) && ci.Participant != nil {
senderJID = types.NewJID(ci.GetParticipant(), types.DefaultUserServer)
}
-
rmsg := config.Message{
UserID: senderJID.String(),
Username: senderName,
@@ -259,7 +267,8 @@ func (b *Bwhatsapp) handleAudioMessage(msg *events.Message) {
Account: b.Account,
Protocol: b.Protocol,
Extra: make(map[string][]interface{}),
- ID: msg.Info.ID,
+ ID: getMessageIdFormat(senderJID, msg.Info.ID),
+ ParentID: getParentIdFromCtx(ci),
}
if avatarURL, exists := b.userAvatars[senderJID.String()]; exists {
@@ -316,7 +325,8 @@ func (b *Bwhatsapp) handleDocumentMessage(msg *events.Message) {
Account: b.Account,
Protocol: b.Protocol,
Extra: make(map[string][]interface{}),
- ID: msg.Info.ID,
+ ID: getMessageIdFormat(senderJID, msg.Info.ID),
+ ParentID: getParentIdFromCtx(ci),
}
if avatarURL, exists := b.userAvatars[senderJID.String()]; exists {