Thumbnail

rani/matterbridge.git

Clone URL: https://git.buni.party/rani/matterbridge.git

commit 09f0e21b6fc424eccff36d9502b2caadb4673a2f Author: Christoph Holtermann <mail@c-holtermann.net> Date: Fri May 09 21:00:36 2025 +0000 matrix: Add metadata for image messages diff --git a/bridge/matrix/matrix.go b/bridge/matrix/matrix.go index fc71f6d..301d634 100644 --- a/bridge/matrix/matrix.go +++ b/bridge/matrix/matrix.go @@ -148 +1413 @@ import (   "github.com/matterbridge-org/matterbridge/bridge"   "github.com/matterbridge-org/matterbridge/bridge/config"   "github.com/matterbridge-org/matterbridge/bridge/helper" - // Custom fork of unmaintained library, needs replacement: + "image" + // Initialize specific format decoders, + // see https://pkg.go.dev/image   matrix "github.com/matterbridge/gomatrix" + _ "image/gif" + _ "image/jpeg" + _ "image/png"  )    var ( @@ -6969 +70129 @@ func (b *Bmatrix) handleUploadFile(msg *config.Message, channel string, fi *conf   }   case strings.Contains(mtype, "image"):   b.Log.Debugf("sendImage %s", res.ContentURI) - err = b.retry(func() error { - _, err = b.mc.SendImage(channel, fi.Name, res.ContentURI)   + cfg, format, err2 := image.DecodeConfig(bytes.NewReader(*fi.Data)) + if err2 != nil { + b.Log.WithError(err2).Errorf("Failed to decode image %s", fi.Name) + return + } + + b.Log.Debugf("Image format detected: %s (%dx%d)", format, cfg.Width, cfg.Height) + + img := matrix.ImageMessage{ + MsgType: "m.image", + Body: fi.Name, + URL: res.ContentURI, + Info: matrix.ImageInfo{ + Mimetype: mtype, + Size: uint(len(*fi.Data)), + Width: uint(cfg.Width), // #nosec G115 -- go std will not returned negative size + Height: uint(cfg.Height), // #nosec G115 -- go std will not returned negative size + }, + } + + err = b.retry(func() error { + _, err = b.mc.SendMessageEvent(channel, "m.room.message", img)   return err   })   if err != nil { diff --git a/changelog.md b/changelog.md index c5bce57..52e9f55 100644 --- a/changelog.md +++ b/changelog.md @@ -336 +337 @@ the return code is not 200 to avoid saving trash data ([#20](https://github.com/matterbridge-org/matterbridge/pull/20))  - matrix   - attachments received from matrix are working again, with authenticated media (MSC3916) implemented ([#61](https://github.com/matterbridge-org/matterbridge/pull/61)) + - image attachments are now send as images with more metadata ([#61](https://github.com/matterbridge-org/matterbridge/pull/61))    ## Upstream