fix: improving internal protocol - pass messageID and parentMessageID

messageID and parentMessageID are cleared in the gateway.
We need this info in Status to handle replies.

Issue #13258
This commit is contained in:
Michal Iskierko 2024-03-07 15:25:27 +01:00 committed by Michał Iskierko
parent 6d31343205
commit 1c7da47b09
3 changed files with 30 additions and 2 deletions

View File

@ -48,6 +48,11 @@ type Message struct {
Extra map[string][]interface{}
}
type OriginalMessageIds struct {
ID string `json:"id"`
ParentID string `json:"parent_id"`
}
func (m Message) ParentNotFound() bool {
return m.ParentID == ParentIDNotFound
}

View File

@ -228,6 +228,19 @@ func (b *Bstatus) toStatusMsg(msg config.Message) *common.Message {
message := common.NewMessage()
message.ChatId = msg.Channel
message.ContentType = protobuf.ChatMessage_BRIDGE_MESSAGE
var originalID, originalParentID string
if msg.Extra != nil {
originalMessageIdsList := msg.Extra["OriginalMessageIds"]
if len(originalMessageIdsList) == 1 {
originalMessageIds, ok := originalMessageIdsList[0].(config.OriginalMessageIds)
if ok {
originalID = originalMessageIds.ID
originalParentID = originalMessageIds.ParentID
}
}
}
message.Payload = &protobuf.ChatMessage_BridgeMessage{
BridgeMessage: &protobuf.BridgeMessage{
BridgeName: msg.Protocol,
@ -235,8 +248,8 @@ func (b *Bstatus) toStatusMsg(msg config.Message) *common.Message {
UserAvatar: msg.Avatar,
UserID: msg.UserID,
Content: msg.Text,
MessageID: msg.ID,
ParentMessageID: msg.ParentID,
MessageID: originalID,
ParentMessageID: originalParentID,
},
}

View File

@ -464,6 +464,16 @@ func (gw *Gateway) SendMessage(
msg.Avatar = gw.modifyAvatar(rmsg, dest)
msg.Username = gw.modifyUsername(rmsg, dest)
// ID and ParentID are for some reason cleared by getDestMsgID
// We need them to send to Status
if msg.Extra == nil {
msg.Extra = make(map[string][]interface{})
}
msg.Extra["OriginalMessageIds"] = []interface{}{config.OriginalMessageIds{
ID: msg.ID,
ParentID: msg.ParentID,
}}
// exclude file delete event as the msg ID here is the native file ID that needs to be deleted
if msg.Event != config.EventFileDelete {
msg.ID = gw.getDestMsgID(rmsg.Protocol+" "+rmsg.ID, dest, channel)