implement parsing of quotes/replies from whatsapp

This commit is contained in:
Iiro Laiho 2022-12-08 16:49:06 +02:00
parent 0a6d64ab48
commit 6afa93e537

View File

@ -62,6 +62,7 @@ func (b *Bwhatsapp) handleTextMessage(messageInfo types.MessageInfo, msg *proto.
} }
var text string var text string
var parent string
// nolint:nestif // nolint:nestif
if msg.GetExtendedTextMessage() == nil { if msg.GetExtendedTextMessage() == nil {
@ -89,6 +90,10 @@ func (b *Bwhatsapp) handleTextMessage(messageInfo types.MessageInfo, msg *proto.
text = strings.Replace(text, "@"+numberAndSuffix[0], "@"+mention, 1) text = strings.Replace(text, "@"+numberAndSuffix[0], "@"+mention, 1)
} }
} }
if ci.StanzaId != nil {
parent = *ci.StanzaId
}
} }
rmsg := config.Message{ rmsg := config.Message{
@ -99,7 +104,7 @@ func (b *Bwhatsapp) handleTextMessage(messageInfo types.MessageInfo, msg *proto.
Account: b.Account, Account: b.Account,
Protocol: b.Protocol, Protocol: b.Protocol,
Extra: make(map[string][]interface{}), Extra: make(map[string][]interface{}),
// ParentID: TODO, // TODO handle thread replies // map from Info.QuotedMessageID string ParentID: parent,
ID: messageInfo.ID, ID: messageInfo.ID,
} }
@ -125,6 +130,11 @@ func (b *Bwhatsapp) handleImageMessage(msg *events.Message) {
senderJID = types.NewJID(ci.GetParticipant(), types.DefaultUserServer) senderJID = types.NewJID(ci.GetParticipant(), types.DefaultUserServer)
} }
var parent string
if ci.StanzaId != nil {
parent = *ci.StanzaId
}
rmsg := config.Message{ rmsg := config.Message{
UserID: senderJID.String(), UserID: senderJID.String(),
Username: senderName, Username: senderName,
@ -133,6 +143,7 @@ func (b *Bwhatsapp) handleImageMessage(msg *events.Message) {
Protocol: b.Protocol, Protocol: b.Protocol,
Extra: make(map[string][]interface{}), Extra: make(map[string][]interface{}),
ID: msg.Info.ID, ID: msg.Info.ID,
ParentID: parent,
} }
if avatarURL, exists := b.userAvatars[senderJID.String()]; exists { if avatarURL, exists := b.userAvatars[senderJID.String()]; exists {
@ -188,6 +199,11 @@ func (b *Bwhatsapp) handleVideoMessage(msg *events.Message) {
senderJID = types.NewJID(ci.GetParticipant(), types.DefaultUserServer) senderJID = types.NewJID(ci.GetParticipant(), types.DefaultUserServer)
} }
var parent string
if ci.StanzaId != nil {
parent = *ci.StanzaId
}
rmsg := config.Message{ rmsg := config.Message{
UserID: senderJID.String(), UserID: senderJID.String(),
Username: senderName, Username: senderName,
@ -196,6 +212,7 @@ func (b *Bwhatsapp) handleVideoMessage(msg *events.Message) {
Protocol: b.Protocol, Protocol: b.Protocol,
Extra: make(map[string][]interface{}), Extra: make(map[string][]interface{}),
ID: msg.Info.ID, ID: msg.Info.ID,
ParentID: parent,
} }
if avatarURL, exists := b.userAvatars[senderJID.String()]; exists { if avatarURL, exists := b.userAvatars[senderJID.String()]; exists {
@ -245,6 +262,11 @@ func (b *Bwhatsapp) handleAudioMessage(msg *events.Message) {
senderJID = types.NewJID(ci.GetParticipant(), types.DefaultUserServer) senderJID = types.NewJID(ci.GetParticipant(), types.DefaultUserServer)
} }
var parent string
if ci.StanzaId != nil {
parent = *ci.StanzaId
}
rmsg := config.Message{ rmsg := config.Message{
UserID: senderJID.String(), UserID: senderJID.String(),
Username: senderName, Username: senderName,
@ -253,6 +275,7 @@ func (b *Bwhatsapp) handleAudioMessage(msg *events.Message) {
Protocol: b.Protocol, Protocol: b.Protocol,
Extra: make(map[string][]interface{}), Extra: make(map[string][]interface{}),
ID: msg.Info.ID, ID: msg.Info.ID,
ParentID: parent,
} }
if avatarURL, exists := b.userAvatars[senderJID.String()]; exists { if avatarURL, exists := b.userAvatars[senderJID.String()]; exists {
@ -276,7 +299,7 @@ func (b *Bwhatsapp) handleAudioMessage(msg *events.Message) {
data, err := b.wc.Download(imsg) data, err := b.wc.Download(imsg)
if err != nil { if err != nil {
b.Log.Errorf("Download video failed: %s", err) b.Log.Errorf("Download audio failed: %s", err)
return return
} }
@ -302,6 +325,11 @@ func (b *Bwhatsapp) handleDocumentMessage(msg *events.Message) {
senderJID = types.NewJID(ci.GetParticipant(), types.DefaultUserServer) senderJID = types.NewJID(ci.GetParticipant(), types.DefaultUserServer)
} }
var parent string
if ci.StanzaId != nil {
parent = *ci.StanzaId
}
rmsg := config.Message{ rmsg := config.Message{
UserID: senderJID.String(), UserID: senderJID.String(),
Username: senderName, Username: senderName,
@ -310,6 +338,7 @@ func (b *Bwhatsapp) handleDocumentMessage(msg *events.Message) {
Protocol: b.Protocol, Protocol: b.Protocol,
Extra: make(map[string][]interface{}), Extra: make(map[string][]interface{}),
ID: msg.Info.ID, ID: msg.Info.ID,
ParentID: parent,
} }
if avatarURL, exists := b.userAvatars[senderJID.String()]; exists { if avatarURL, exists := b.userAvatars[senderJID.String()]; exists {