diff --git a/.gitignore b/.gitignore index ec61c09..ea9c8b9 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,5 @@ *.db *.log -/mautrix-whatsapp +/matrix-groupme-go +.profile diff --git a/database/portal.go b/database/portal.go index c091d47..28f9a7b 100644 --- a/database/portal.go +++ b/database/portal.go @@ -122,7 +122,7 @@ type Portal struct { Name string Topic string Avatar string - AvatarURL id.ContentURI + AvatarURL types.ContentURI Encrypted bool `gorm:"notNull;default:false"` } diff --git a/database/puppet.go b/database/puppet.go index e7879b7..5ff4fae 100644 --- a/database/puppet.go +++ b/database/puppet.go @@ -101,7 +101,7 @@ type Puppet struct { JID types.GroupMeID `gorm:"primaryKey"` Avatar string - AvatarURL id.ContentURI + AvatarURL types.ContentURI Displayname string NameQuality int8 diff --git a/go.mod b/go.mod index 72692cf..0b8db30 100644 --- a/go.mod +++ b/go.mod @@ -29,5 +29,3 @@ require ( ) replace github.com/karmanyaahm/groupme => ../groupme - -replace maunium.net/go/mautrix => ../mautrix diff --git a/go.sum b/go.sum index 7673bbd..850c980 100644 --- a/go.sum +++ b/go.sum @@ -644,5 +644,7 @@ maunium.net/go/mauflag v1.0.0 h1:YiaRc0tEI3toYtJMRIfjP+jklH45uDHtT80nUamyD4M= maunium.net/go/mauflag v1.0.0/go.mod h1:nLivPOpTpHnpzEh8jEdSL9UqO9+/KBJFmNRlwKfkPeA= maunium.net/go/maulogger/v2 v2.1.1 h1:NAZNc6XUFJzgzfewCzVoGkxNAsblLCSSEdtDuIjP0XA= maunium.net/go/maulogger/v2 v2.1.1/go.mod h1:TYWy7wKwz/tIXTpsx8G3mZseIRiC5DoMxSZazOHy68A= +maunium.net/go/mautrix v0.8.2 h1:E3NudQ/QolmE/yhHau8iCkbmcq6gCLvoEvukdqPFJu4= +maunium.net/go/mautrix v0.8.2/go.mod h1:KiViCshKBUZwrVRvTOXsJBFfstvR/btxckHUbOPdu54= sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o= sourcegraph.com/sourcegraph/appdash v0.0.0-20190731080439-ebfcffb1b5c0/go.mod h1:hI742Nqp5OhwiqlzhgfbWU4mW4yO10fP+LoT9WOswdU= diff --git a/matrix.go b/matrix.go index e647146..a4900e9 100644 --- a/matrix.go +++ b/matrix.go @@ -171,7 +171,7 @@ func (mx *MatrixHandler) createPrivatePortalFromInvite(roomID id.RoomID, inviter print("possible bug with pointer above") portal.Avatar = puppet.Avatar _, _ = portal.MainIntent().SetRoomName(portal.MXID, portal.Name) - _, _ = portal.MainIntent().SetRoomAvatar(portal.MXID, portal.AvatarURL) + _, _ = portal.MainIntent().SetRoomAvatar(portal.MXID, portal.AvatarURL.ContentURI) } else { portal.Name = "" } diff --git a/portal.go b/portal.go index 65be844..6065e2c 100644 --- a/portal.go +++ b/portal.go @@ -1001,7 +1001,7 @@ func (portal *Portal) CreateMatrixRoom(user *User) error { initialState = append(initialState, &event.Event{ Type: event.StateRoomAvatar, Content: event.Content{ - Parsed: event.RoomAvatarEventContent{URL: portal.AvatarURL}, + Parsed: event.RoomAvatarEventContent{URL: portal.AvatarURL.ContentURI}, }, }) } diff --git a/puppet.go b/puppet.go index 7a5126a..ac5c165 100644 --- a/puppet.go +++ b/puppet.go @@ -188,7 +188,7 @@ func (puppet *Puppet) UpdateAvatar(source *User, avatar string) bool { if err != nil { puppet.log.Warnln("Failed to remove avatar:", err) } - puppet.AvatarURL = id.ContentURI{} + puppet.AvatarURL = types.ContentURI{} puppet.Avatar = avatar go puppet.updatePortalAvatar() return true @@ -222,8 +222,8 @@ func (puppet *Puppet) UpdateAvatar(source *User, avatar string) bool { return false } - puppet.AvatarURL = resp.ContentURI - err = puppet.DefaultIntent().SetAvatarURL(puppet.AvatarURL) + puppet.AvatarURL = types.ContentURI{resp.ContentURI} + err = puppet.DefaultIntent().SetAvatarURL(resp.ContentURI) if err != nil { puppet.log.Warnln("Failed to set avatar:", err) } @@ -260,7 +260,7 @@ func (puppet *Puppet) updatePortalMeta(meta func(portal *Portal)) { func (puppet *Puppet) updatePortalAvatar() { puppet.updatePortalMeta(func(portal *Portal) { if len(portal.MXID) > 0 { - _, err := portal.MainIntent().SetRoomAvatar(portal.MXID, puppet.AvatarURL) + _, err := portal.MainIntent().SetRoomAvatar(portal.MXID, puppet.AvatarURL.ContentURI) if err != nil { portal.log.Warnln("Failed to set avatar:", err) } diff --git a/types/contentURI.go b/types/contentURI.go new file mode 100644 index 0000000..23da91b --- /dev/null +++ b/types/contentURI.go @@ -0,0 +1,29 @@ +package types + +import ( + "database/sql/driver" + + "maunium.net/go/mautrix/id" +) + +type ContentURI struct { + id.ContentURI +} + +func (m *ContentURI) Scan(value interface{}) error { + bytes, ok := value.([]byte) + if !ok { + println(len(bytes)) + //return errors.New(fmt.Sprint("Failed to unmarshal value:", value)) + } + if len(bytes) == 0 { + uri, _ := id.ParseContentURI("") + *m = ContentURI{uri} + return nil + } + return m.UnmarshalText(bytes) +} + +func (m ContentURI) Value() (driver.Value, error) { + return m.String(), nil +}