Create portals for recent chats automatically

This commit is contained in:
Tulir Asokan 2023-07-09 17:26:34 +03:00
parent 7e90ec8c14
commit e94ea17dad
2 changed files with 20 additions and 11 deletions

View file

@ -16,7 +16,7 @@
* [ ] Typing notifications
* [ ] Read receipts
* Misc
* [ ] Automatic portal creation
* [ ] After login
* [x] Automatic portal creation
* [x] After login
* [x] When receiving message
* [ ] Private chat creation by inviting Matrix ghost of remote user to new room

27
user.go
View file

@ -541,20 +541,17 @@ func (user *User) HandleEvent(event interface{}) {
user.zlog.Err(err).Msg("Failed to update session in database")
}
case *binary.Conversation:
portal := user.GetPortalByID(v.GetConversationID())
if portal.MXID != "" {
portal.UpdateMetadata(user, v)
} else {
err := portal.CreateMatrixRoom(user, v)
if err != nil {
user.zlog.Err(err).Msg("Error creating Matrix room from conversation event")
}
}
user.syncConversation(v)
case *binary.Message:
portal := user.GetPortalByID(v.GetConversationID())
portal.messages <- PortalMessage{evt: v, source: user}
case *events.ClientReady:
user.zlog.Trace().Any("data", v).Msg("Client is ready!")
go func() {
for _, conv := range v.Conversations {
user.syncConversation(conv)
}
}()
case *events.BrowserActive:
user.zlog.Trace().Any("data", v).Msg("Browser active")
default:
@ -562,6 +559,18 @@ func (user *User) HandleEvent(event interface{}) {
}
}
func (user *User) syncConversation(v *binary.Conversation) {
portal := user.GetPortalByID(v.GetConversationID())
if portal.MXID != "" {
portal.UpdateMetadata(user, v)
} else {
err := portal.CreateMatrixRoom(user, v)
if err != nil {
user.zlog.Err(err).Msg("Error creating Matrix room from conversation event")
}
}
}
func (user *User) updateChatMute(portal *Portal, mutedUntil time.Time) {
intent := user.DoublePuppetIntent
if intent == nil || len(portal.MXID) == 0 {