Use enum instead of strings for message type
This commit is contained in:
committed by
Carl Schwan
parent
bba947e508
commit
92ec441594
@@ -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
|
||||
|
||||
@@ -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<const RoomMessageEvent>(&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<const StickerEvent>(evt)) {
|
||||
return "sticker";
|
||||
return DelegateType::Sticker;
|
||||
}
|
||||
if (evt.isStateEvent()) {
|
||||
return "state";
|
||||
return DelegateType::State;
|
||||
}
|
||||
if (is<const EncryptedEvent>(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<const RoomMessageEvent>(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<const StickerEvent>(*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();
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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 {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 { }
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user