Correctly hide avatar and name change events when configured

This commit is contained in:
Tobias Fella
2022-11-10 14:53:39 +01:00
parent 962a1b228c
commit 95345973cb
4 changed files with 39 additions and 2 deletions

View File

@@ -61,6 +61,8 @@ QHash<int, QByteArray> MessageEventModel::roleNames() const
roles[VerifiedRole] = "verified";
roles[DisplayNameForInitialsRole] = "displayNameForInitials";
roles[AuthorDisplayNameRole] = "authorDisplayName";
roles[IsNameChangeRole] = "isNameChange";
roles[IsAvatarChangeRole] = "isAvatarChange";
return roles;
}
@@ -853,6 +855,22 @@ QVariant MessageEventModel::data(const QModelIndex &idx, int role) const
}
}
if (role == IsNameChangeRole) {
auto roomMemberEvent = eventCast<const RoomMemberEvent>(&evt);
if (roomMemberEvent) {
return roomMemberEvent->isRename();
}
return false;
}
if (role == IsAvatarChangeRole) {
auto roomMemberEvent = eventCast<const RoomMemberEvent>(&evt);
if (roomMemberEvent) {
return roomMemberEvent->isAvatarUpdate();
}
return false;
}
return {};
}

View File

@@ -68,6 +68,8 @@ public:
DisplayNameForInitialsRole,
// The displayname for the event's sender; for name change events, the old displayname
AuthorDisplayNameRole,
IsNameChangeRole,
IsAvatarChangeRole,
LastRole, // Keep this last
};
Q_ENUM(EventRoles)

View File

@@ -15,6 +15,16 @@ MessageFilterModel::MessageFilterModel(QObject *parent)
beginResetModel();
endResetModel();
});
connect(NeoChatConfig::self(), &NeoChatConfig::ShowRenameChanged, this, [this] {
beginResetModel();
endResetModel();
});
connect(NeoChatConfig::self(), &NeoChatConfig::ShowAvatarUpdateChanged, this, [this] {
beginResetModel();
endResetModel();
});
}
bool MessageFilterModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
@@ -22,6 +32,13 @@ bool MessageFilterModel::filterAcceptsRow(int sourceRow, const QModelIndex &sour
const QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
const int specialMarks = index.data(MessageEventModel::SpecialMarksRole).toInt();
if (index.data(MessageEventModel::IsNameChangeRole).toBool() && !NeoChatConfig::self()->showRename()) {
return false;
}
if (index.data(MessageEventModel::IsAvatarChangeRole).toBool() && !NeoChatConfig::self()->showAvatarUpdate()) {
return false;
}
if (specialMarks == EventStatus::Hidden || specialMarks == EventStatus::Replaced) {
return false;

View File

@@ -518,14 +518,14 @@ QString NeoChatRoom::eventToString(const RoomEvent &evt, Qt::TextFormat format,
return text;
}
// Part 2: profile changes of joined members
if (e.isRename() && NeoChatConfig::self()->showRename()) {
if (e.isRename()) {
if (e.displayName().isEmpty()) {
text = i18nc("their refers to a singular user", "cleared their display name");
} else {
text = i18nc("their refers to a singular user", "changed their display name to %1", e.displayName().toHtmlEscaped());
}
}
if (e.isAvatarUpdate() && NeoChatConfig::self()->showAvatarUpdate()) {
if (e.isAvatarUpdate()) {
if (!text.isEmpty()) {
text += i18n(" and ");
}