Fall back to second media ID field if first is empty

This commit is contained in:
Tulir Asokan 2023-09-02 12:09:59 +03:00
parent 2439be0f71
commit 9137cdfc68

View file

@ -341,7 +341,7 @@ func (portal *Portal) isOutgoingMessage(msg *gmproto.Message) *database.Message
func hasInProgressMedia(msg *gmproto.Message) bool { func hasInProgressMedia(msg *gmproto.Message) bool {
for _, part := range msg.MessageInfo { for _, part := range msg.MessageInfo {
media, ok := part.GetData().(*gmproto.MessageInfo_MediaContent) media, ok := part.GetData().(*gmproto.MessageInfo_MediaContent)
if ok && media.MediaContent.GetMediaID() == "" { if ok && media.MediaContent.GetMediaID() == "" && media.MediaContent.GetMediaID2() == "" {
return true return true
} }
} }
@ -926,7 +926,7 @@ func (portal *Portal) convertGoogleMessage(ctx context.Context, source *User, ev
downloadStatus = "" downloadStatus = ""
} }
case *gmproto.MessageInfo_MediaContent: case *gmproto.MessageInfo_MediaContent:
if data.MediaContent.MediaID == "" { if data.MediaContent.MediaID == "" && data.MediaContent.MediaID2 == "" {
pendingMedia = true pendingMedia = true
content = event.MessageEventContent{ content = event.MessageEventContent{
MsgType: event.MsgNotice, MsgType: event.MsgNotice,
@ -1104,7 +1104,13 @@ func (msg *ConvertedMessage) MergeCaption() {
func (portal *Portal) convertGoogleMedia(source *User, intent *appservice.IntentAPI, msg *gmproto.MediaContent) (*event.MessageEventContent, error) { func (portal *Portal) convertGoogleMedia(source *User, intent *appservice.IntentAPI, msg *gmproto.MediaContent) (*event.MessageEventContent, error) {
var data []byte var data []byte
var err error var err error
if msg.MediaID != "" {
data, err = source.Client.DownloadMedia(msg.MediaID, msg.DecryptionKey) data, err = source.Client.DownloadMedia(msg.MediaID, msg.DecryptionKey)
} else if msg.MediaID2 != "" {
data, err = source.Client.DownloadMedia(msg.MediaID2, msg.DecryptionKey2)
} else {
err = fmt.Errorf("no media ID found")
}
if err != nil { if err != nil {
return nil, err return nil, err
} }