Internalize id.ContentURI Valuer
Removes dependency on custom mautrix-go
This commit is contained in:
parent
2fe729bee0
commit
d8bff50005
3
.gitignore
vendored
3
.gitignore
vendored
@ -8,4 +8,5 @@
|
||||
*.db
|
||||
*.log
|
||||
|
||||
/mautrix-whatsapp
|
||||
/matrix-groupme-go
|
||||
.profile
|
||||
|
@ -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"`
|
||||
}
|
||||
|
||||
|
@ -101,7 +101,7 @@ type Puppet struct {
|
||||
|
||||
JID types.GroupMeID `gorm:"primaryKey"`
|
||||
Avatar string
|
||||
AvatarURL id.ContentURI
|
||||
AvatarURL types.ContentURI
|
||||
Displayname string
|
||||
NameQuality int8
|
||||
|
||||
|
2
go.mod
2
go.mod
@ -29,5 +29,3 @@ require (
|
||||
)
|
||||
|
||||
replace github.com/karmanyaahm/groupme => ../groupme
|
||||
|
||||
replace maunium.net/go/mautrix => ../mautrix
|
||||
|
2
go.sum
2
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=
|
||||
|
@ -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 = ""
|
||||
}
|
||||
|
@ -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},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
29
types/contentURI.go
Normal file
29
types/contentURI.go
Normal file
@ -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
|
||||
}
|
Loading…
Reference in New Issue
Block a user