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[VerifiedRole] = "verified";
roles[DisplayNameForInitialsRole] = "displayNameForInitials"; roles[DisplayNameForInitialsRole] = "displayNameForInitials";
roles[AuthorDisplayNameRole] = "authorDisplayName"; roles[AuthorDisplayNameRole] = "authorDisplayName";
roles[IsNameChangeRole] = "isNameChange";
roles[IsAvatarChangeRole] = "isAvatarChange";
return roles; 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 {}; return {};
} }

View File

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

View File

@@ -15,6 +15,16 @@ MessageFilterModel::MessageFilterModel(QObject *parent)
beginResetModel(); beginResetModel();
endResetModel(); 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 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 QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
const int specialMarks = index.data(MessageEventModel::SpecialMarksRole).toInt(); 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) { if (specialMarks == EventStatus::Hidden || specialMarks == EventStatus::Replaced) {
return false; return false;

View File

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