Skip to content

Commit

Permalink
# Whatsappmulti reply
Browse files Browse the repository at this point in the history
Squashed commit of the following:

commit 0798b0c
Author: Iiro Laiho <[email protected]>
Date:   Fri Dec 9 15:52:11 2022 +0200

    Fix null pointer runtime panic (whatsapp)

commit 6afa93e
Author: Iiro Laiho <[email protected]>
Date:   Thu Dec 8 16:49:06 2022 +0200

    implement parsing of quotes/replies from whatsapp
  • Loading branch information
yousefmansy1 committed Feb 17, 2023
1 parent 476205c commit f8b3caf
Showing 1 changed file with 32 additions and 3 deletions.
35 changes: 32 additions & 3 deletions bridge/whatsappmulti/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func (b *Bwhatsapp) handleTextMessage(messageInfo types.MessageInfo, msg *proto.
}

var text string
var parent string = ""

// nolint:nestif
if msg.GetExtendedTextMessage() == nil {
Expand Down Expand Up @@ -87,6 +88,10 @@ func (b *Bwhatsapp) handleTextMessage(messageInfo types.MessageInfo, msg *proto.
text = strings.Replace(text, "@"+numberAndSuffix[0], "@"+mention, 1)
}
}

if ci.StanzaId != nil {
parent = *ci.StanzaId
}
}

rmsg := config.Message{
Expand All @@ -97,8 +102,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,
ParentID: parent,
ID: messageInfo.ID,
}

if avatarURL, exists := b.userAvatars[senderJID.String()]; exists {
Expand All @@ -123,6 +128,11 @@ func (b *Bwhatsapp) handleImageMessage(msg *events.Message) {
senderJID = types.NewJID(ci.GetParticipant(), types.DefaultUserServer)
}

var parent string = ""
if ci != nil && ci.StanzaId != nil {
parent = *ci.StanzaId
}

rmsg := config.Message{
UserID: senderJID.String(),
Username: senderName,
Expand All @@ -131,6 +141,7 @@ func (b *Bwhatsapp) handleImageMessage(msg *events.Message) {
Protocol: b.Protocol,
Extra: make(map[string][]interface{}),
ID: msg.Info.ID,
ParentID: parent,
}

if avatarURL, exists := b.userAvatars[senderJID.String()]; exists {
Expand Down Expand Up @@ -186,6 +197,11 @@ func (b *Bwhatsapp) handleVideoMessage(msg *events.Message) {
senderJID = types.NewJID(ci.GetParticipant(), types.DefaultUserServer)
}

var parent string = ""
if ci != nil && ci.StanzaId != nil {
parent = *ci.StanzaId
}

rmsg := config.Message{
UserID: senderJID.String(),
Username: senderName,
Expand All @@ -194,6 +210,7 @@ func (b *Bwhatsapp) handleVideoMessage(msg *events.Message) {
Protocol: b.Protocol,
Extra: make(map[string][]interface{}),
ID: msg.Info.ID,
ParentID: parent,
}

if avatarURL, exists := b.userAvatars[senderJID.String()]; exists {
Expand Down Expand Up @@ -251,6 +268,11 @@ func (b *Bwhatsapp) handleAudioMessage(msg *events.Message) {
if senderJID == (types.JID{}) && ci.Participant != nil {
senderJID = types.NewJID(ci.GetParticipant(), types.DefaultUserServer)
}

var parent string = ""
if ci != nil && ci.StanzaId != nil {
parent = *ci.StanzaId
}

rmsg := config.Message{
UserID: senderJID.String(),
Expand All @@ -260,6 +282,7 @@ func (b *Bwhatsapp) handleAudioMessage(msg *events.Message) {
Protocol: b.Protocol,
Extra: make(map[string][]interface{}),
ID: msg.Info.ID,
ParentID: parent,
}

if avatarURL, exists := b.userAvatars[senderJID.String()]; exists {
Expand All @@ -283,7 +306,7 @@ func (b *Bwhatsapp) handleAudioMessage(msg *events.Message) {

data, err := b.wc.Download(imsg)
if err != nil {
b.Log.Errorf("Download video failed: %s", err)
b.Log.Errorf("Download audio failed: %s", err)

return
}
Expand All @@ -309,6 +332,11 @@ func (b *Bwhatsapp) handleDocumentMessage(msg *events.Message) {
senderJID = types.NewJID(ci.GetParticipant(), types.DefaultUserServer)
}

var parent string = ""
if ci != nil && ci.StanzaId != nil {
parent = *ci.StanzaId
}

rmsg := config.Message{
UserID: senderJID.String(),
Username: senderName,
Expand All @@ -317,6 +345,7 @@ func (b *Bwhatsapp) handleDocumentMessage(msg *events.Message) {
Protocol: b.Protocol,
Extra: make(map[string][]interface{}),
ID: msg.Info.ID,
ParentID: parent,
}

if avatarURL, exists := b.userAvatars[senderJID.String()]; exists {
Expand Down

0 comments on commit f8b3caf

Please sign in to comment.