Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions bridgev2/ghost.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,3 +404,30 @@ func (ghost *Ghost) pushProfileChanges(ctx context.Context, nameChanged, avatarC
}
}
}

// Check that the ghosts profile information matches the current content of an event. This allows
// member events and ghosts to self heal in case they ever drift due to bugs.
func (ghost *Ghost) reconcileProfile(ctx context.Context, current *event.MemberEventContent) {
nameDrift := ghost.NameSet && ghost.Name != "" && current.Displayname != ghost.Name
avatarDrift := ghost.AvatarSet && ghost.AvatarMXC != "" && current.AvatarURL != ghost.AvatarMXC
if !nameDrift && !avatarDrift {
return
}
zerolog.Ctx(ctx).Warn().
Str("ghost_id", string(ghost.ID)).
Bool("name_drift", nameDrift).
Bool("avatar_drift", avatarDrift).
Str("expected_name", ghost.Name).
Str("actual_name", current.Displayname).
Msg("Ghost profile drifted from the server copy, re-pushing")
if nameDrift {
ghost.NameSet = false
}
if avatarDrift {
ghost.AvatarSet = false
}
ghost.pushProfileChanges(ctx, nameDrift, avatarDrift, false)
if err := ghost.Bridge.DB.Ghost.Update(ctx, ghost.Ghost); err != nil {
zerolog.Ctx(ctx).Err(err).Msg("Failed to save ghost after profile reconcile")
}
}
3 changes: 3 additions & 0 deletions bridgev2/portal.go
Original file line number Diff line number Diff line change
Expand Up @@ -4828,6 +4828,9 @@ func (portal *Portal) syncParticipants(
zerolog.Ctx(ctx).Err(err).Str("ghost_id", string(member.Sender)).Msg("Failed to get ghost from member list to update info")
} else {
ghost.UpdateInfo(ctx, member.UserInfo)
if current, ok := currentMembers[ghost.Intent.GetMXID()]; ok && current.Membership == event.MembershipJoin {
ghost.reconcileProfile(ctx, current)
}
}
}
intent, extraUserID, err := portal.getIntentAndUserMXIDFor(ctx, member.EventSender, source, loginsInPortal, 0)
Expand Down
Loading