Create portals for recent chats automatically
This commit is contained in:
parent
7e90ec8c14
commit
e94ea17dad
2 changed files with 20 additions and 11 deletions
|
@ -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
|
||||||
|
|
27
user.go
27
user.go
|
@ -541,20 +541,17 @@ 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:
|
||||||
portal := user.GetPortalByID(v.GetConversationID())
|
user.syncConversation(v)
|
||||||
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")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case *binary.Message:
|
case *binary.Message:
|
||||||
portal := user.GetPortalByID(v.GetConversationID())
|
portal := user.GetPortalByID(v.GetConversationID())
|
||||||
portal.messages <- PortalMessage{evt: v, source: user}
|
portal.messages <- PortalMessage{evt: v, source: user}
|
||||||
case *events.ClientReady:
|
case *events.ClientReady:
|
||||||
user.zlog.Trace().Any("data", v).Msg("Client is ready!")
|
user.zlog.Trace().Any("data", v).Msg("Client is ready!")
|
||||||
|
go func() {
|
||||||
|
for _, conv := range v.Conversations {
|
||||||
|
user.syncConversation(conv)
|
||||||
|
}
|
||||||
|
}()
|
||||||
case *events.BrowserActive:
|
case *events.BrowserActive:
|
||||||
user.zlog.Trace().Any("data", v).Msg("Browser active")
|
user.zlog.Trace().Any("data", v).Msg("Browser active")
|
||||||
default:
|
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) {
|
func (user *User) updateChatMute(portal *Portal, mutedUntil time.Time) {
|
||||||
intent := user.DoublePuppetIntent
|
intent := user.DoublePuppetIntent
|
||||||
if intent == nil || len(portal.MXID) == 0 {
|
if intent == nil || len(portal.MXID) == 0 {
|
||||||
|
|
Loading…
Reference in a new issue