Don't log re-finding other user ID all the time

This commit is contained in:
Tulir Asokan 2023-07-03 00:13:36 +03:00
parent 1ca32927eb
commit 44e1cf7464

View file

@ -417,7 +417,7 @@ func (portal *Portal) markHandled(info *binary.Message, mxids map[string]id.Even
return msg return msg
} }
func (portal *Portal) SyncParticipants(source *User, metadata *binary.Conversation) (userIDs []id.UserID) { func (portal *Portal) SyncParticipants(source *User, metadata *binary.Conversation) (userIDs []id.UserID, changed bool) {
var firstParticipant *binary.Participant var firstParticipant *binary.Participant
var manyParticipants bool var manyParticipants bool
for _, participant := range metadata.Participants { for _, participant := range metadata.Participants {
@ -445,14 +445,15 @@ func (portal *Portal) SyncParticipants(source *User, metadata *binary.Conversati
} }
} }
} }
if !metadata.IsGroupChat && !manyParticipants { if !metadata.IsGroupChat && !manyParticipants && portal.OtherUserID != firstParticipant.Id.ParticipantID {
portal.zlog.Info(). portal.zlog.Info().
Str("old_other_user_id", portal.OtherUserID). Str("old_other_user_id", portal.OtherUserID).
Str("new_other_user_id", firstParticipant.Id.ParticipantID). Str("new_other_user_id", firstParticipant.Id.ParticipantID).
Msg("Found other user ID in DM") Msg("Found other user ID in DM")
portal.OtherUserID = firstParticipant.Id.ParticipantID portal.OtherUserID = firstParticipant.Id.ParticipantID
changed = true
} }
return userIDs return userIDs, changed
} }
func (portal *Portal) UpdateName(name string, updateInfo bool) bool { func (portal *Portal) UpdateName(name string, updateInfo bool) bool {
@ -492,8 +493,7 @@ func (portal *Portal) UpdateName(name string, updateInfo bool) bool {
} }
func (portal *Portal) UpdateMetadata(user *User, info *binary.Conversation) []id.UserID { func (portal *Portal) UpdateMetadata(user *User, info *binary.Conversation) []id.UserID {
participants := portal.SyncParticipants(user, info) participants, update := portal.SyncParticipants(user, info)
update := false
if portal.SelfUserID != info.SelfParticipantID { if portal.SelfUserID != info.SelfParticipantID {
portal.SelfUserID = info.SelfParticipantID portal.SelfUserID = info.SelfParticipantID
update = true update = true