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 * [ ] Typing notifications
* [ ] Read receipts * [ ] Read receipts
* Misc * Misc
* [ ] Automatic portal creation * [x] Automatic portal creation
* [ ] After login * [x] After login
* [x] When receiving message * [x] When receiving message
* [ ] Private chat creation by inviting Matrix ghost of remote user to new room * [ ] Private chat creation by inviting Matrix ghost of remote user to new room

29
user.go
View file

@ -541,6 +541,25 @@ func (user *User) HandleEvent(event interface{}) {
user.zlog.Err(err).Msg("Failed to update session in database") user.zlog.Err(err).Msg("Failed to update session in database")
} }
case *binary.Conversation: case *binary.Conversation:
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:
user.zlog.Trace().Any("data", v).Msg("Unknown event")
}
}
func (user *User) syncConversation(v *binary.Conversation) {
portal := user.GetPortalByID(v.GetConversationID()) portal := user.GetPortalByID(v.GetConversationID())
if portal.MXID != "" { if portal.MXID != "" {
portal.UpdateMetadata(user, v) portal.UpdateMetadata(user, v)
@ -550,16 +569,6 @@ func (user *User) HandleEvent(event interface{}) {
user.zlog.Err(err).Msg("Error creating Matrix room from conversation event") user.zlog.Err(err).Msg("Error creating Matrix room from conversation event")
} }
} }
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!")
case *events.BrowserActive:
user.zlog.Trace().Any("data", v).Msg("Browser active")
default:
user.zlog.Trace().Any("data", v).Msg("Unknown event")
}
} }
func (user *User) updateChatMute(portal *Portal, mutedUntil time.Time) { func (user *User) updateChatMute(portal *Portal, mutedUntil time.Time) {