Add support for sending captions and fix some fields in send requests

This commit is contained in:
Tulir Asokan 2024-04-16 17:44:34 +03:00
parent d0a8b8406c
commit 1d3ef74817
8 changed files with 22 additions and 5 deletions

View file

@ -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
}

Binary file not shown.

View file

@ -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;
}

View file

@ -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

Binary file not shown.

View file

@ -130,6 +130,7 @@ message MediaContent {
string mediaID2 = 9;
bytes decryptionKey = 11;
bytes decryptionKey2 = 12;
string mimeType = 14;
}
message Dimensions {

View file

@ -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
}

View file

@ -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)