Cleanup name handling in RoomListModel
Replace NameRole with DisplayNameRole entirely.
This commit is contained in:
@@ -158,7 +158,7 @@ void RoomListModel::doAddRoom(Room *r)
|
|||||||
void RoomListModel::connectRoomSignals(NeoChatRoom *room)
|
void RoomListModel::connectRoomSignals(NeoChatRoom *room)
|
||||||
{
|
{
|
||||||
connect(room, &Room::displaynameChanged, this, [this, room] {
|
connect(room, &Room::displaynameChanged, this, [this, room] {
|
||||||
refresh(room, {DisplayNameRole, NameRole});
|
refresh(room, {DisplayNameRole});
|
||||||
});
|
});
|
||||||
connect(room, &Room::unreadMessagesChanged, this, [this, room] {
|
connect(room, &Room::unreadMessagesChanged, this, [this, room] {
|
||||||
refresh(room, {NotificationCountRole, HighlightCountRole});
|
refresh(room, {NotificationCountRole, HighlightCountRole});
|
||||||
@@ -333,9 +333,6 @@ QVariant RoomListModel::data(const QModelIndex &index, int role) const
|
|||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
NeoChatRoom *room = m_rooms.at(index.row());
|
NeoChatRoom *room = m_rooms.at(index.row());
|
||||||
if (role == NameRole) {
|
|
||||||
return !room->name().isEmpty() ? room->name() : room->displayName();
|
|
||||||
}
|
|
||||||
if (role == DisplayNameRole) {
|
if (role == DisplayNameRole) {
|
||||||
return room->displayName();
|
return room->displayName();
|
||||||
}
|
}
|
||||||
@@ -434,7 +431,6 @@ void RoomListModel::refresh(NeoChatRoom *room, const QVector<int> &roles)
|
|||||||
QHash<int, QByteArray> RoomListModel::roleNames() const
|
QHash<int, QByteArray> RoomListModel::roleNames() const
|
||||||
{
|
{
|
||||||
QHash<int, QByteArray> roles;
|
QHash<int, QByteArray> roles;
|
||||||
roles[NameRole] = "name";
|
|
||||||
roles[DisplayNameRole] = "displayName";
|
roles[DisplayNameRole] = "displayName";
|
||||||
roles[AvatarRole] = "avatar";
|
roles[AvatarRole] = "avatar";
|
||||||
roles[CanonicalAliasRole] = "canonicalAlias";
|
roles[CanonicalAliasRole] = "canonicalAlias";
|
||||||
|
|||||||
@@ -58,8 +58,7 @@ public:
|
|||||||
* @brief Defines the model roles.
|
* @brief Defines the model roles.
|
||||||
*/
|
*/
|
||||||
enum EventRoles {
|
enum EventRoles {
|
||||||
NameRole = Qt::UserRole + 1, /**< The name of the room. */
|
DisplayNameRole = Qt::DisplayRole, /**< The display name of the room. */
|
||||||
DisplayNameRole, /**< The display name of the room. */
|
|
||||||
AvatarRole, /**< The source URL for the room's avatar. */
|
AvatarRole, /**< The source URL for the room's avatar. */
|
||||||
CanonicalAliasRole, /**< The room canonical alias. */
|
CanonicalAliasRole, /**< The room canonical alias. */
|
||||||
TopicRole, /**< The room topic. */
|
TopicRole, /**< The room topic. */
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ void SortFilterRoomListModel::setRoomSortOrder(SortFilterRoomListModel::RoomSort
|
|||||||
m_sortOrder = sortOrder;
|
m_sortOrder = sortOrder;
|
||||||
Q_EMIT roomSortOrderChanged();
|
Q_EMIT roomSortOrderChanged();
|
||||||
if (sortOrder == SortFilterRoomListModel::Alphabetical) {
|
if (sortOrder == SortFilterRoomListModel::Alphabetical) {
|
||||||
setSortRole(RoomListModel::NameRole);
|
setSortRole(RoomListModel::DisplayNameRole);
|
||||||
} else if (sortOrder == SortFilterRoomListModel::LastActivity) {
|
} else if (sortOrder == SortFilterRoomListModel::LastActivity) {
|
||||||
setSortRole(RoomListModel::LastActiveTimeRole);
|
setSortRole(RoomListModel::LastActiveTimeRole);
|
||||||
}
|
}
|
||||||
@@ -78,7 +78,8 @@ bool SortFilterRoomListModel::filterAcceptsRow(int source_row, const QModelIndex
|
|||||||
{
|
{
|
||||||
Q_UNUSED(source_parent);
|
Q_UNUSED(source_parent);
|
||||||
|
|
||||||
bool acceptRoom = sourceModel()->data(sourceModel()->index(source_row, 0), RoomListModel::NameRole).toString().contains(m_filterText, Qt::CaseInsensitive)
|
bool acceptRoom =
|
||||||
|
sourceModel()->data(sourceModel()->index(source_row, 0), RoomListModel::DisplayNameRole).toString().contains(m_filterText, Qt::CaseInsensitive)
|
||||||
&& sourceModel()->data(sourceModel()->index(source_row, 0), RoomListModel::JoinStateRole).toString() != "upgraded"
|
&& sourceModel()->data(sourceModel()->index(source_row, 0), RoomListModel::JoinStateRole).toString() != "upgraded"
|
||||||
&& sourceModel()->data(sourceModel()->index(source_row, 0), RoomListModel::IsSpaceRole).toBool() == false;
|
&& sourceModel()->data(sourceModel()->index(source_row, 0), RoomListModel::IsSpaceRole).toBool() == false;
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ ColumnLayout {
|
|||||||
spacing: 0
|
spacing: 0
|
||||||
MobileForm.FormComboBoxDelegate {
|
MobileForm.FormComboBoxDelegate {
|
||||||
text: i18n("Room")
|
text: i18n("Room")
|
||||||
textRole: "name"
|
textRole: "displayName"
|
||||||
valueRole: "id"
|
valueRole: "id"
|
||||||
model: RoomListModel {
|
model: RoomListModel {
|
||||||
id: roomListModel
|
id: roomListModel
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ QQC2.Dialog {
|
|||||||
id: roomListItem
|
id: roomListItem
|
||||||
|
|
||||||
required property var currentRoom
|
required property var currentRoom
|
||||||
required property string name
|
required property string displayName
|
||||||
required property int index
|
required property int index
|
||||||
required property int notificationCount
|
required property int notificationCount
|
||||||
required property string subtitleText
|
required property string subtitleText
|
||||||
@@ -114,7 +114,7 @@ QQC2.Dialog {
|
|||||||
root.close();
|
root.close();
|
||||||
}
|
}
|
||||||
bold: roomListItem.notificationCount > 0
|
bold: roomListItem.notificationCount > 0
|
||||||
label: roomListItem.name ?? ""
|
label: roomListItem.displayName ?? ""
|
||||||
labelItem.textFormat: Text.PlainText
|
labelItem.textFormat: Text.PlainText
|
||||||
subtitle: roomListItem.subtitleText
|
subtitle: roomListItem.subtitleText
|
||||||
subtitleItem.textFormat: Text.PlainText
|
subtitleItem.textFormat: Text.PlainText
|
||||||
@@ -124,7 +124,7 @@ QQC2.Dialog {
|
|||||||
|
|
||||||
leading: Kirigami.Avatar {
|
leading: Kirigami.Avatar {
|
||||||
source: roomListItem.avatar ? "image://mxc/" + roomListItem.avatar : ""
|
source: roomListItem.avatar ? "image://mxc/" + roomListItem.avatar : ""
|
||||||
name: roomListItem.name || i18n("No Name")
|
name: roomListItem.displayName
|
||||||
implicitWidth: height
|
implicitWidth: height
|
||||||
sourceSize.width: Kirigami.Units.gridUnit + Kirigami.Units.largeSpacing * 2
|
sourceSize.width: Kirigami.Units.gridUnit + Kirigami.Units.largeSpacing * 2
|
||||||
sourceSize.height: Kirigami.Units.gridUnit + Kirigami.Units.largeSpacing * 2
|
sourceSize.height: Kirigami.Units.gridUnit + Kirigami.Units.largeSpacing * 2
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ QQC2.ItemDelegate {
|
|||||||
required property bool categoryVisible
|
required property bool categoryVisible
|
||||||
required property string filterText
|
required property string filterText
|
||||||
required property string avatar
|
required property string avatar
|
||||||
required property string name
|
required property string displayName
|
||||||
|
|
||||||
topPadding: Kirigami.Units.largeSpacing
|
topPadding: Kirigami.Units.largeSpacing
|
||||||
leftPadding: Kirigami.Units.largeSpacing
|
leftPadding: Kirigami.Units.largeSpacing
|
||||||
@@ -34,7 +34,7 @@ QQC2.ItemDelegate {
|
|||||||
|
|
||||||
contentItem: Kirigami.Avatar {
|
contentItem: Kirigami.Avatar {
|
||||||
source: root.avatar ? `image://mxc/${root.avatar}` : ""
|
source: root.avatar ? `image://mxc/${root.avatar}` : ""
|
||||||
name: root.name || i18n("No Name")
|
name: root.displayName
|
||||||
|
|
||||||
sourceSize {
|
sourceSize {
|
||||||
width: Kirigami.Units.gridUnit + Kirigami.Units.largeSpacing * 2
|
width: Kirigami.Units.gridUnit + Kirigami.Units.largeSpacing * 2
|
||||||
@@ -48,6 +48,6 @@ QQC2.ItemDelegate {
|
|||||||
Keys.onReturnPressed: RoomManager.enterRoom(root.currentRoom)
|
Keys.onReturnPressed: RoomManager.enterRoom(root.currentRoom)
|
||||||
|
|
||||||
QQC2.ToolTip.visible: text.length > 0 && hovered
|
QQC2.ToolTip.visible: text.length > 0 && hovered
|
||||||
QQC2.ToolTip.text: root.name ?? ""
|
QQC2.ToolTip.text: root.displayName ?? ""
|
||||||
QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
|
QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ Kirigami.BasicListItem {
|
|||||||
required property string avatar
|
required property string avatar
|
||||||
required property string subtitleText
|
required property string subtitleText
|
||||||
|
|
||||||
required property string name
|
required property string displayName
|
||||||
|
|
||||||
readonly property bool hasNotifications: notificationCount > 0
|
readonly property bool hasNotifications: notificationCount > 0
|
||||||
|
|
||||||
@@ -38,7 +38,7 @@ Kirigami.BasicListItem {
|
|||||||
icon: undefined
|
icon: undefined
|
||||||
bold: root.hasNotifications
|
bold: root.hasNotifications
|
||||||
|
|
||||||
label: root.name ?? ""
|
label: root.displayName
|
||||||
labelItem.textFormat: Text.PlainText
|
labelItem.textFormat: Text.PlainText
|
||||||
|
|
||||||
subtitle: root.subtitleText
|
subtitle: root.subtitleText
|
||||||
@@ -61,7 +61,7 @@ Kirigami.BasicListItem {
|
|||||||
|
|
||||||
leading: Kirigami.Avatar {
|
leading: Kirigami.Avatar {
|
||||||
source: root.avatar ? `image://mxc/${root.avatar}` : ""
|
source: root.avatar ? `image://mxc/${root.avatar}` : ""
|
||||||
name: root.name || i18n("No Name")
|
name: root.displayName
|
||||||
implicitWidth: visible ? height : 0
|
implicitWidth: visible ? height : 0
|
||||||
visible: Config.showAvatarInRoomDrawer
|
visible: Config.showAvatarInRoomDrawer
|
||||||
sourceSize {
|
sourceSize {
|
||||||
|
|||||||
@@ -81,9 +81,9 @@ QQC2.Control {
|
|||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
Layout.preferredHeight: width
|
Layout.preferredHeight: width
|
||||||
display: Kirigami.NavigationTabButton.IconOnly
|
display: Kirigami.NavigationTabButton.IconOnly
|
||||||
text: model.name
|
text: model.displayName
|
||||||
source: model.avatar ? ("image://mxc/" + model.avatar) : ""
|
source: model.avatar ? ("image://mxc/" + model.avatar) : ""
|
||||||
name: model.name
|
name: model.displayName
|
||||||
onClicked: root.selectedSpaceId = model.id
|
onClicked: root.selectedSpaceId = model.id
|
||||||
QQC2.ToolTip.visible: hovered
|
QQC2.ToolTip.visible: hovered
|
||||||
QQC2.ToolTip.text: text
|
QQC2.ToolTip.text: text
|
||||||
|
|||||||
Reference in New Issue
Block a user