diff --git a/directmedia.go b/directmedia.go index dd56ce1..3be8702 100644 --- a/directmedia.go +++ b/directmedia.go @@ -326,6 +326,22 @@ func (dma *DirectMediaAPI) FetchNewAttachmentURL(ctx context.Context, meta *Atta return url, nil } +func (dma *DirectMediaAPI) GetEmojiInfo(contentURI id.ContentURI) *EmojiMediaData { + if dma == nil || contentURI.IsEmpty() || contentURI.Homeserver != dma.cfg.ServerName { + return nil + } + mediaID, err := ParseMediaID(contentURI.FileID, dma.signatureKey) + if err != nil { + return nil + } + emojiData, ok := mediaID.Data.(*EmojiMediaData) + if !ok { + return nil + } + return emojiData + +} + func (dma *DirectMediaAPI) GetMediaURL(ctx context.Context, encodedMediaID string) (url string, expiry time.Time, err error) { var mediaID *MediaID mediaID, err = ParseMediaID(encodedMediaID, dma.signatureKey) diff --git a/portal.go b/portal.go index f32ba28..e63c83f 100644 --- a/portal.go +++ b/portal.go @@ -1832,13 +1832,15 @@ func (portal *Portal) handleMatrixReaction(sender *User, evt *event.Event) { emojiID := reaction.RelatesTo.Key if strings.HasPrefix(emojiID, "mxc://") { uri, _ := id.ParseContentURI(emojiID) - emojiFile := portal.bridge.DB.File.GetEmojiByMXC(uri) - if emojiFile == nil || emojiFile.ID == "" || emojiFile.EmojiName == "" { + emojiInfo := portal.bridge.DMA.GetEmojiInfo(uri) + if emojiInfo != nil { + emojiID = fmt.Sprintf("%s:%d", emojiInfo.Name, emojiInfo.EmojiID) + } else if emojiFile := portal.bridge.DB.File.GetEmojiByMXC(uri); emojiFile != nil && emojiFile.ID != "" && emojiFile.EmojiName != "" { + emojiID = fmt.Sprintf("%s:%s", emojiFile.EmojiName, emojiFile.ID) + } else { go portal.sendMessageMetrics(evt, fmt.Errorf("%w %s", errUnknownEmoji, emojiID), "Ignoring") return } - - emojiID = fmt.Sprintf("%s:%s", emojiFile.EmojiName, emojiFile.ID) } else { emojiID = variationselector.FullyQualify(emojiID) }