Skip to content

Commit

Permalink
implement parsing of quotes/replies from whatsapp
Browse files Browse the repository at this point in the history
  • Loading branch information
ilmaisin committed Dec 8, 2022
1 parent 0a6d64a commit 6afa93e
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 @@ -62,6 +62,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 @@ -89,6 +90,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 @@ -99,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,
ParentID: parent,
ID: messageInfo.ID,
}

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

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

rmsg := config.Message{
UserID: senderJID.String(),
Username: senderName,
Expand All @@ -133,6 +143,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 @@ -188,6 +199,11 @@ func (b *Bwhatsapp) handleVideoMessage(msg *events.Message) {
senderJID = types.NewJID(ci.GetParticipant(), types.DefaultUserServer)
}

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

rmsg := config.Message{
UserID: senderJID.String(),
Username: senderName,
Expand All @@ -196,6 +212,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 @@ -244,6 +261,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.StanzaId != nil {
parent = *ci.StanzaId
}

rmsg := config.Message{
UserID: senderJID.String(),
Expand All @@ -253,6 +275,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 @@ -276,7 +299,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 @@ -302,6 +325,11 @@ func (b *Bwhatsapp) handleDocumentMessage(msg *events.Message) {
senderJID = types.NewJID(ci.GetParticipant(), types.DefaultUserServer)
}

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

rmsg := config.Message{
UserID: senderJID.String(),
Username: senderName,
Expand All @@ -310,6 +338,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 6afa93e

Please sign in to comment.