Set avatar in room create request and sync participants before filling history
This commit is contained in:
parent
14f96bd96f
commit
7b067b4737
35
portal.go
35
portal.go
@ -132,6 +132,8 @@ type Portal struct {
|
|||||||
bridge *Bridge
|
bridge *Bridge
|
||||||
log log.Logger
|
log log.Logger
|
||||||
|
|
||||||
|
avatarURL string
|
||||||
|
|
||||||
roomCreateLock sync.Mutex
|
roomCreateLock sync.Mutex
|
||||||
messageLocksLock sync.Mutex
|
messageLocksLock sync.Mutex
|
||||||
messageLocks map[types.WhatsAppMessageID]sync.Mutex
|
messageLocks map[types.WhatsAppMessageID]sync.Mutex
|
||||||
@ -347,11 +349,14 @@ func (portal *Portal) UpdateAvatar(user *User, avatar *whatsappExt.ProfilePicInf
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
portal.avatarURL = resp.ContentURI
|
||||||
|
if len(portal.MXID) > 0 {
|
||||||
_, err = portal.MainIntent().SetRoomAvatar(portal.MXID, resp.ContentURI)
|
_, err = portal.MainIntent().SetRoomAvatar(portal.MXID, resp.ContentURI)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
portal.log.Warnln("Failed to set room topic:", err)
|
portal.log.Warnln("Failed to set room topic:", err)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
}
|
||||||
portal.Avatar = avatar.Tag
|
portal.Avatar = avatar.Tag
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@ -644,6 +649,7 @@ func (portal *Portal) CreateMatrixRoom(user *User) error {
|
|||||||
|
|
||||||
portal.log.Infoln("Creating Matrix room. Info source:", user.MXID)
|
portal.log.Infoln("Creating Matrix room. Info source:", user.MXID)
|
||||||
|
|
||||||
|
var metadata *whatsappExt.GroupInfo
|
||||||
isPrivateChat := false
|
isPrivateChat := false
|
||||||
if portal.IsPrivateChat() {
|
if portal.IsPrivateChat() {
|
||||||
portal.Name = ""
|
portal.Name = ""
|
||||||
@ -653,11 +659,28 @@ func (portal *Portal) CreateMatrixRoom(user *User) error {
|
|||||||
portal.Name = "WhatsApp Status Broadcast"
|
portal.Name = "WhatsApp Status Broadcast"
|
||||||
portal.Topic = "WhatsApp status updates from your contacts"
|
portal.Topic = "WhatsApp status updates from your contacts"
|
||||||
} else {
|
} else {
|
||||||
metadata, err := user.Conn.GetGroupMetaData(portal.Key.JID)
|
var err error
|
||||||
|
metadata, err = user.Conn.GetGroupMetaData(portal.Key.JID)
|
||||||
if err == nil && metadata.Status == 0 {
|
if err == nil && metadata.Status == 0 {
|
||||||
portal.Name = metadata.Name
|
portal.Name = metadata.Name
|
||||||
portal.Topic = metadata.Topic
|
portal.Topic = metadata.Topic
|
||||||
}
|
}
|
||||||
|
portal.UpdateAvatar(user, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
initialState := []*mautrix.Event{{
|
||||||
|
Type: mautrix.StatePowerLevels,
|
||||||
|
Content: mautrix.Content{
|
||||||
|
PowerLevels: portal.GetBasePowerLevels(),
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
if len(portal.avatarURL) > 0 {
|
||||||
|
initialState = append(initialState, &mautrix.Event{
|
||||||
|
Type: mautrix.StateRoomAvatar,
|
||||||
|
Content: mautrix.Content{
|
||||||
|
URL: portal.avatarURL,
|
||||||
|
},
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := intent.CreateRoom(&mautrix.ReqCreateRoom{
|
resp, err := intent.CreateRoom(&mautrix.ReqCreateRoom{
|
||||||
@ -667,18 +690,16 @@ func (portal *Portal) CreateMatrixRoom(user *User) error {
|
|||||||
Invite: []string{user.MXID},
|
Invite: []string{user.MXID},
|
||||||
Preset: "private_chat",
|
Preset: "private_chat",
|
||||||
IsDirect: isPrivateChat,
|
IsDirect: isPrivateChat,
|
||||||
InitialState: []*mautrix.Event{{
|
InitialState: initialState,
|
||||||
Type: mautrix.StatePowerLevels,
|
|
||||||
Content: mautrix.Content{
|
|
||||||
PowerLevels: portal.GetBasePowerLevels(),
|
|
||||||
},
|
|
||||||
}},
|
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
portal.MXID = resp.RoomID
|
portal.MXID = resp.RoomID
|
||||||
portal.Update()
|
portal.Update()
|
||||||
|
if metadata != nil {
|
||||||
|
portal.SyncParticipants(metadata)
|
||||||
|
}
|
||||||
err = portal.FillInitialHistory(user)
|
err = portal.FillInitialHistory(user)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
portal.log.Errorln("Failed to fill history:", err)
|
portal.log.Errorln("Failed to fill history:", err)
|
||||||
|
2
user.go
2
user.go
@ -286,7 +286,7 @@ func (user *User) PostLogin() {
|
|||||||
user.log.Debugln("Waiting a second for contacts to arrive")
|
user.log.Debugln("Waiting a second for contacts to arrive")
|
||||||
// Hacky way to wait for chats and contacts to arrive automatically
|
// Hacky way to wait for chats and contacts to arrive automatically
|
||||||
time.Sleep(1 * time.Second)
|
time.Sleep(1 * time.Second)
|
||||||
user.log.Debugln("Waited 3 seconds:", len(user.Conn.Store.Chats), len(user.Conn.Store.Contacts))
|
user.log.Debugln("Waited a second, have", len(user.Conn.Store.Chats), "chats and", len(user.Conn.Store.Contacts), "contacts")
|
||||||
|
|
||||||
go user.syncPuppets()
|
go user.syncPuppets()
|
||||||
user.syncPortals()
|
user.syncPortals()
|
||||||
|
Loading…
Reference in New Issue
Block a user