diff --git a/src/collapsestateproxymodel.cpp b/src/collapsestateproxymodel.cpp index b72de49b2..92917cdb6 100644 --- a/src/collapsestateproxymodel.cpp +++ b/src/collapsestateproxymodel.cpp @@ -10,9 +10,9 @@ bool CollapseStateProxyModel::filterAcceptsRow(int source_row, const QModelIndex { Q_UNUSED(source_parent); return sourceModel()->data(sourceModel()->index(source_row, 0), MessageEventModel::EventTypeRole) - != QLatin1String("state") // If this is not a state, show it + != MessageEventModel::DelegateType::State // If this is not a state, show it || sourceModel()->data(sourceModel()->index(source_row + 1, 0), MessageEventModel::EventTypeRole) - != QLatin1String("state") // If this is the first state in a block, show it. TODO hidden events? + != MessageEventModel::DelegateType::State // If this is the first state in a block, show it. TODO hidden events? || sourceModel()->data(sourceModel()->index(source_row, 0), MessageEventModel::ShowSectionRole).toBool() // If it's a new day, show it || sourceModel()->data(sourceModel()->index(source_row, 0), MessageEventModel::EventResolvedTypeRole) != sourceModel()->data(sourceModel()->index(source_row + 1, 0), @@ -41,7 +41,8 @@ QString CollapseStateProxyModel::aggregateEventToString(int sourceRow) const QStringList parts; for (int i = sourceRow; i >= 0; i--) { parts += sourceModel()->data(sourceModel()->index(i, 0), Qt::DisplayRole).toString(); - if (sourceModel()->data(sourceModel()->index(i, 0), MessageEventModel::EventTypeRole) != QLatin1String("state") // If it's not a state event + if (sourceModel()->data(sourceModel()->index(i, 0), MessageEventModel::EventTypeRole) + != MessageEventModel::DelegateType::State // If it's not a state event || (i > 0 && sourceModel()->data(sourceModel()->index(i, 0), MessageEventModel::EventResolvedTypeRole) != sourceModel()->data(sourceModel()->index(i - 1, 0), MessageEventModel::EventResolvedTypeRole)) // or of a different type diff --git a/src/messageeventmodel.cpp b/src/messageeventmodel.cpp index e2c8db638..9234569be 100644 --- a/src/messageeventmodel.cpp +++ b/src/messageeventmodel.cpp @@ -420,7 +420,7 @@ QVariant MessageEventModel::data(const QModelIndex &idx, int role) const if (m_lastReadEventIndex.row() == row) { switch (role) { case EventTypeRole: - return QStringLiteral("readMarker"); + return DelegateType::ReadMarker; case TimeRole: { const QDateTime eventDate = data(index(m_lastReadEventIndex.row() + 1, 0), TimeRole).toDateTime(); const KFormat format; @@ -467,35 +467,34 @@ QVariant MessageEventModel::data(const QModelIndex &idx, int role) const if (auto e = eventCast(&evt)) { switch (e->msgtype()) { case MessageEventType::Emote: - return "emote"; + return DelegateType::Emote; case MessageEventType::Notice: - return "notice"; + return DelegateType::Notice; case MessageEventType::Image: - return "image"; + return DelegateType::Image; case MessageEventType::Audio: - return "audio"; + return DelegateType::Audio; case MessageEventType::Video: - return "video"; + return DelegateType::Video; default: break; } if (e->hasFileContent()) { - return "file"; + return DelegateType::File; } - return "message"; + return DelegateType::Message; } if (is(evt)) { - return "sticker"; + return DelegateType::Sticker; } if (evt.isStateEvent()) { - return "state"; + return DelegateType::State; } if (is(evt)) { - return "encrypted"; + return DelegateType::Encrypted; } - - return "other"; + return DelegateType::Other; } if (role == EventResolvedTypeRole) { @@ -671,36 +670,36 @@ QVariant MessageEventModel::data(const QModelIndex &idx, int role) const return {}; } - QString type; + DelegateType type; if (auto e = eventCast(replyPtr)) { switch (e->msgtype()) { case MessageEventType::Emote: - type = "emote"; + type = DelegateType::Emote; break; case MessageEventType::Notice: - type = "notice"; + type = DelegateType::Notice; break; case MessageEventType::Image: - type = "image"; + type = DelegateType::Image; break; case MessageEventType::Audio: - type = "audio"; + type = DelegateType::Audio; break; case MessageEventType::Video: - type = "video"; + type = DelegateType::Video; break; default: if (e->hasFileContent()) { - type = "file"; + type = DelegateType::File; break; } - type = "message"; + type = DelegateType::Message; } } else if (is(*replyPtr)) { - type = "sticker"; + type = DelegateType::Sticker; } else { - type = "other"; + type = DelegateType::Other; } QVariant content; @@ -729,7 +728,7 @@ QVariant MessageEventModel::data(const QModelIndex &idx, int role) const // While the row is removed the subsequent row indexes are not changed so we need to skip over the removed index. // See - https://doc.qt.io/qt-5/qabstractitemmodel.html#beginRemoveRows if (data(i, SpecialMarksRole) != EventStatus::Hidden && !itemData(i).empty()) { - return data(i, AuthorRole) != data(idx, AuthorRole) || data(i, EventTypeRole) == "state" + return data(i, AuthorRole) != data(idx, AuthorRole) || data(i, EventTypeRole) == MessageEventModel::State || data(i, TimeRole).toDateTime().msecsTo(data(idx, TimeRole).toDateTime()) > 600000 || data(i, TimeRole).toDateTime().toLocalTime().date().day() != data(idx, TimeRole).toDateTime().toLocalTime().date().day(); } diff --git a/src/messageeventmodel.h b/src/messageeventmodel.h index 387c6ce83..135fe7061 100644 --- a/src/messageeventmodel.h +++ b/src/messageeventmodel.h @@ -13,6 +13,22 @@ class MessageEventModel : public QAbstractListModel Q_PROPERTY(NeoChatRoom *room READ room WRITE setRoom NOTIFY roomChanged) public: + enum DelegateType { + Emote, + Notice, + Image, + Audio, + Video, + File, + Message, + Sticker, + State, + Encrypted, + ReadMarker, + Other, + }; + Q_ENUM(DelegateType); + enum EventRoles { EventTypeRole = Qt::UserRole + 1, MessageRole, diff --git a/src/messagefiltermodel.cpp b/src/messagefiltermodel.cpp index cf51a031f..084062a91 100644 --- a/src/messagefiltermodel.cpp +++ b/src/messagefiltermodel.cpp @@ -29,11 +29,11 @@ bool MessageFilterModel::filterAcceptsRow(int sourceRow, const QModelIndex &sour const QString eventType = index.data(MessageEventModel::EventTypeRole).toString(); - if (eventType == QLatin1String("other")) { + if (eventType == MessageEventModel::Other) { return false; } - if (!NeoChatConfig::self()->showLeaveJoinEvent() && eventType == QLatin1String("state")) { + if (!NeoChatConfig::self()->showLeaveJoinEvent() && eventType == MessageEventModel::State) { return false; } diff --git a/src/qml/Component/Timeline/EventDelegate.qml b/src/qml/Component/Timeline/EventDelegate.qml index f8ef4f372..6410cccf9 100644 --- a/src/qml/Component/Timeline/EventDelegate.qml +++ b/src/qml/Component/Timeline/EventDelegate.qml @@ -14,64 +14,64 @@ DelegateChooser { role: "eventType" DelegateChoice { - roleValue: "state" + roleValue: MessageEventModel.State delegate: StateDelegate {} } DelegateChoice { - roleValue: "emote" + roleValue: MessageEventModel.Emote delegate: MessageDelegate { isEmote: true } } DelegateChoice { - roleValue: "message" + roleValue: MessageEventModel.Message delegate: MessageDelegate {} } DelegateChoice { - roleValue: "notice" + roleValue: MessageEventModel.Notice delegate: MessageDelegate {} } DelegateChoice { - roleValue: "image" + roleValue: MessageEventModel.Image delegate: ImageDelegate {} } DelegateChoice { - roleValue: "sticker" + roleValue: MessageEventModel.Sticker delegate: ImageDelegate {} } DelegateChoice { - roleValue: "audio" + roleValue: MessageEventModel.Audio delegate: AudioDelegate {} } DelegateChoice { - roleValue: "video" + roleValue: MessageEventModel.Video delegate: VideoDelegate {} } DelegateChoice { - roleValue: "file" + roleValue: MessageEventModel.File delegate: FileDelegate {} } DelegateChoice { - roleValue: "encrypted" + roleValue: MessageEventModel.Encrypted delegate: EncryptedDelegate {} } DelegateChoice { - roleValue: "readMarker" + roleValue: MessageEventModel.ReadMarker delegate: ReadMarkerDelegate {} } DelegateChoice { - roleValue: "other" + roleValue: MessageEventModel.Other delegate: Item {} } } diff --git a/src/qml/Component/Timeline/ReplyComponent.qml b/src/qml/Component/Timeline/ReplyComponent.qml index 8dd772ca1..db2fd7eb7 100644 --- a/src/qml/Component/Timeline/ReplyComponent.qml +++ b/src/qml/Component/Timeline/ReplyComponent.qml @@ -65,17 +65,17 @@ Item { sourceComponent: { switch (reply.type) { - case "image": - case "sticker": + case MessageEventModel.Image: + case MessageEventModel.Sticker: return imageComponent; - case "message": - case "notice": + case MessageEventModel.Message: + case MessageEventModel.Notice: return textComponent; - case "file": - case "video": - case "audio": + case MessageEventModel.File: + case MessageEventModel.Video: + case MessageEventModel.Audio: return mimeComponent; - case "encrypted": + case MessageEventModel.Encrypted: return encryptedComponent; default: return textComponent; @@ -114,7 +114,7 @@ Item { MimeComponent { mimeIconSource: reply.content.info.mimetype.replace("/", "-") label: reply.display - subLabel: reply.type === "file" ? Controller.formatByteSize(reply.content.info ? reply.content.info.size : 0) : Controller.formatDuration(reply.content.info.duration) + subLabel: reply.type === MessageEventModel.File ? Controller.formatByteSize(reply.content.info ? reply.content.info.size : 0) : Controller.formatDuration(reply.content.info.duration) } } Component { diff --git a/src/qml/Component/Timeline/TimelineContainer.qml b/src/qml/Component/Timeline/TimelineContainer.qml index 2fc9213d2..6a59c8772 100644 --- a/src/qml/Component/Timeline/TimelineContainer.qml +++ b/src/qml/Component/Timeline/TimelineContainer.qml @@ -308,7 +308,7 @@ QQC2.ItemDelegate { } height: active ? item.implicitHeight : 0 //Layout.bottomMargin: readMarker ? Kirigami.Units.smallSpacing : 0 - active: eventType !== "state" && eventType !== "notice" && reaction != undefined && reaction.length > 0 + active: eventType !== MessageEventModel.State && eventType !== MessageEventModel.Notice && reaction != undefined && reaction.length > 0 visible: active sourceComponent: ReactionDelegate { } } diff --git a/src/qml/Menu/Timeline/MessageDelegateContextMenu.qml b/src/qml/Menu/Timeline/MessageDelegateContextMenu.qml index 03847354c..6393dcd76 100644 --- a/src/qml/Menu/Timeline/MessageDelegateContextMenu.qml +++ b/src/qml/Menu/Timeline/MessageDelegateContextMenu.qml @@ -31,7 +31,7 @@ Loader { currentRoom.chatBoxEditId = eventId; currentRoom.chatBoxReplyId = ""; } - visible: eventType.length > 0 && author.id === Controller.activeConnection.localUserId && (eventType === "emote" || eventType === "message") + visible: eventType.length > 0 && author.id === Controller.activeConnection.localUserId && (eventType === MessageEventModel.Emote || eventType === MessageEventModel.Message) }, Kirigami.Action { text: i18n("Reply") diff --git a/src/qml/Page/RoomPage.qml b/src/qml/Page/RoomPage.qml index e6d496f50..27a77399e 100644 --- a/src/qml/Page/RoomPage.qml +++ b/src/qml/Page/RoomPage.qml @@ -420,7 +420,7 @@ Kirigami.ScrollablePage { id: hoverActions property var event: null property bool userMsg: event && event.author.id === Controller.activeConnection.localUserId - property bool showEdit: event && (userMsg && (event.eventType === "emote" || event.eventType === "message")) + property bool showEdit: event && (userMsg && (event.eventType === MessageEventType.Emote || event.eventType === MessageEventModel.Message)) property var delegate: null property var bubble: null property var hovered: bubble && bubble.hovered