Add more logs for syncing conversations

This commit is contained in:
Tulir Asokan 2023-08-02 14:54:08 +03:00
parent 7618afed7f
commit 13a8d9b9a9
3 changed files with 7 additions and 13 deletions

View file

@ -842,16 +842,6 @@ func (portal *Portal) ensureUserInvited(user *User) bool {
return user.ensureInvited(portal.MainIntent(), portal.MXID, portal.IsPrivateChat())
}
func (portal *Portal) UpdateMatrixRoom(user *User, groupInfo *gmproto.Conversation) bool {
if len(portal.MXID) == 0 {
return false
}
portal.ensureUserInvited(user)
portal.UpdateMetadata(user, groupInfo)
return true
}
func (portal *Portal) GetBasePowerLevels() *event.PowerLevelsEventContent {
anyone := 0
nope := 99

View file

@ -238,6 +238,9 @@ func (prov *ProvisioningAPI) StartChat(w http.ResponseWriter, r *http.Request) {
})
return
}
convCopy := proto.Clone(resp.Conversation).(*gmproto.Conversation)
convCopy.LatestMessage = nil
prov.zlog.Debug().Any("conversation_data", convCopy).Msg("Got conversation data for start chat")
portal := user.GetPortalByID(resp.Conversation.ConversationID)
err = portal.CreateMatrixRoom(user, resp.Conversation)
if err != nil {

View file

@ -650,7 +650,7 @@ func (user *User) HandleEvent(event interface{}) {
user.zlog.Err(err).Msg("Failed to update session in database")
}
case *gmproto.Conversation:
user.syncConversation(v)
user.syncConversation(v, "event")
case *gmproto.Message:
portal := user.GetPortalByID(v.GetConversationID())
portal.messages <- PortalMessage{evt: v, source: user}
@ -692,7 +692,7 @@ func (user *User) fetchAndSyncConversations() {
}
user.zlog.Info().Int("count", len(resp.GetConversations())).Msg("Syncing conversations")
for _, conv := range resp.GetConversations() {
user.syncConversation(conv)
user.syncConversation(conv, "sync")
}
}
@ -793,7 +793,7 @@ func (user *User) Logout(state status.BridgeState, unpair bool) (logoutOK bool)
return
}
func (user *User) syncConversation(v *gmproto.Conversation) {
func (user *User) syncConversation(v *gmproto.Conversation, source string) {
updateType := v.GetStatus()
portal := user.GetPortalByID(v.GetConversationID())
convCopy := proto.Clone(v).(*gmproto.Conversation)
@ -801,6 +801,7 @@ func (user *User) syncConversation(v *gmproto.Conversation) {
log := portal.zlog.With().
Str("action", "sync conversation").
Str("conversation_status", updateType.String()).
Str("data_source", source).
Str("room_id", portal.MXID.String()).
Interface("conversation_data", convCopy).
Logger()