From 1d3ef74817d7893962f1a354eab08ab40e6d85d5 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Tue, 16 Apr 2024 17:44:34 +0300 Subject: [PATCH] Add support for sending captions and fix some fields in send requests --- libgm/gmproto/client.pb.go | 6 +++--- libgm/gmproto/client.pb.raw | Bin 6219 -> 6215 bytes libgm/gmproto/client.proto | 2 +- libgm/gmproto/conversations.pb.go | 8 ++++++++ libgm/gmproto/conversations.pb.raw | Bin 9546 -> 9574 bytes libgm/gmproto/conversations.proto | 1 + libgm/media.go | 1 + portal.go | 9 ++++++++- 8 files changed, 22 insertions(+), 5 deletions(-) diff --git a/libgm/gmproto/client.pb.go b/libgm/gmproto/client.pb.go index fc81144..7849c05 100644 --- a/libgm/gmproto/client.pb.go +++ b/libgm/gmproto/client.pb.go @@ -2383,7 +2383,7 @@ type SendMessageRequest struct { MessagePayload *MessagePayload `protobuf:"bytes,3,opt,name=messagePayload,proto3" json:"messagePayload,omitempty"` SIMPayload *SIMPayload `protobuf:"bytes,4,opt,name=SIMPayload,proto3" json:"SIMPayload,omitempty"` TmpID string `protobuf:"bytes,5,opt,name=tmpID,proto3" json:"tmpID,omitempty"` - IsReply bool `protobuf:"varint,6,opt,name=isReply,proto3" json:"isReply,omitempty"` // not sure + IsRCS bool `protobuf:"varint,6,opt,name=isRCS,proto3" json:"isRCS,omitempty"` // not sure Reply *ReplyPayload `protobuf:"bytes,8,opt,name=reply,proto3" json:"reply,omitempty"` } @@ -2447,9 +2447,9 @@ func (x *SendMessageRequest) GetTmpID() string { return "" } -func (x *SendMessageRequest) GetIsReply() bool { +func (x *SendMessageRequest) GetIsRCS() bool { if x != nil { - return x.IsReply + return x.IsRCS } return false } diff --git a/libgm/gmproto/client.pb.raw b/libgm/gmproto/client.pb.raw index 451ef995ee1bacfe3a49a0597e11159d5dea6fd0..eb5e3a5bd1df9b69e84c230613c4ff6c798c5c0a 100644 GIT binary patch delta 40 rcmX?YaNJ;ngb-ubWJ#e@q9RPd<{v`-tN=JV4bK1o diff --git a/libgm/gmproto/client.proto b/libgm/gmproto/client.proto index 886260d..e12da56 100644 --- a/libgm/gmproto/client.proto +++ b/libgm/gmproto/client.proto @@ -254,7 +254,7 @@ message SendMessageRequest { MessagePayload messagePayload = 3; settings.SIMPayload SIMPayload = 4; string tmpID = 5; - bool isReply = 6; // not sure + bool isRCS = 6; // not sure ReplyPayload reply = 8; } diff --git a/libgm/gmproto/conversations.pb.go b/libgm/gmproto/conversations.pb.go index a4ec03a..6bc266e 100644 --- a/libgm/gmproto/conversations.pb.go +++ b/libgm/gmproto/conversations.pb.go @@ -1501,6 +1501,7 @@ type MediaContent struct { MediaID2 string `protobuf:"bytes,9,opt,name=mediaID2,proto3" json:"mediaID2,omitempty"` DecryptionKey []byte `protobuf:"bytes,11,opt,name=decryptionKey,proto3" json:"decryptionKey,omitempty"` DecryptionKey2 []byte `protobuf:"bytes,12,opt,name=decryptionKey2,proto3" json:"decryptionKey2,omitempty"` + MimeType string `protobuf:"bytes,14,opt,name=mimeType,proto3" json:"mimeType,omitempty"` } func (x *MediaContent) Reset() { @@ -1598,6 +1599,13 @@ func (x *MediaContent) GetDecryptionKey2() []byte { return nil } +func (x *MediaContent) GetMimeType() string { + if x != nil { + return x.MimeType + } + return "" +} + type Dimensions struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache diff --git a/libgm/gmproto/conversations.pb.raw b/libgm/gmproto/conversations.pb.raw index 429adf3995bda4ed772b18351c41c7f3abfe6759..657a899b62e1967c9dd7f22a242b77ab49e7480d 100644 GIT binary patch delta 48 xcmX@*^~`I-bS}nsn`dwZGs*}_adG5k=B9>J7Nkn>DKKhq2EqB8UvtMx0sx$55Dx$V delta 19 bcmaFnb;@hQbS}nAn`dwZGj3+*iI)TbSP%zL diff --git a/libgm/gmproto/conversations.proto b/libgm/gmproto/conversations.proto index b8e485c..e38b6d9 100644 --- a/libgm/gmproto/conversations.proto +++ b/libgm/gmproto/conversations.proto @@ -130,6 +130,7 @@ message MediaContent { string mediaID2 = 9; bytes decryptionKey = 11; bytes decryptionKey2 = 12; + string mimeType = 14; } message Dimensions { diff --git a/libgm/media.go b/libgm/media.go index adb222d..6dc352d 100644 --- a/libgm/media.go +++ b/libgm/media.go @@ -115,6 +115,7 @@ func (c *Client) UploadMedia(data []byte, fileName, mime string) (*gmproto.Media MediaName: fileName, Size: int64(len(data)), DecryptionKey: decryptionKey, + MimeType: mime, }, nil } diff --git a/portal.go b/portal.go index 3ccc3d6..ab48498 100644 --- a/portal.go +++ b/portal.go @@ -1932,10 +1932,10 @@ func (portal *Portal) convertMatrixMessage(ctx context.Context, sender *User, co } else if replyToMsg == nil { log.Warn().Str("reply_to_mxid", replyToMXID.String()).Msg("Reply target message not found") } else { - req.IsReply = true req.Reply = &gmproto.ReplyPayload{MessageID: replyToMsg.ID} } } + req.IsRCS = portal.Type == gmproto.ConversationType_RCS switch content.MsgType { case event.MsgText, event.MsgEmote, event.MsgNotice: @@ -1956,6 +1956,13 @@ func (portal *Portal) convertMatrixMessage(ctx context.Context, sender *User, co req.MessagePayload.MessageInfo = []*gmproto.MessageInfo{{ Data: &gmproto.MessageInfo_MediaContent{MediaContent: resp}, }} + if content.FileName != "" && content.FileName != content.Body { + req.MessagePayload.MessageInfo = append(req.MessagePayload.MessageInfo, &gmproto.MessageInfo{ + Data: &gmproto.MessageInfo_MessageContent{MessageContent: &gmproto.MessageContent{ + Content: content.Body, + }}, + }) + } case event.MsgBeeperGallery: for i, part := range content.BeeperGalleryImages { convertedPart, err := portal.reuploadMedia(ctx, sender, part, nil)