diff --git a/src/apps/qml/ActiveChat.qml b/src/apps/qml/ActiveChat.qml index 607922cd..3954650f 100644 --- a/src/apps/qml/ActiveChat.qml +++ b/src/apps/qml/ActiveChat.qml @@ -1,162 +1,162 @@ /* Copyright (c) 2017-2019 Montel Laurent This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License or ( at your option ) version 3 or, at the discretion of KDE e.V. ( which shall act as a proxy as in section 14 of the GPLv3 ), any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import QtQuick 2.9 import org.kde.kirigami 2.7 as Kirigami ListView { id: activeChat clip: true signal openDirectChannel(string userName) signal openChannel(string channel) signal jitsiCallConfActivated() signal deleteMessage(string messageId) signal reportMessage(string messageId) signal downloadAttachment(string url) signal editMessage(string messageId, string messageStr) signal copyMessage(string messageId, string messageStr) signal replyMessage(string messageId) signal setFavoriteMessage(string messageId, bool starred) signal displayImage(url imageUrl, string title, bool isAnimatedImage) signal deleteReaction(string messageId, string emoji) signal addReaction(string messageId, string emoji) signal ignoreUser(string userId, bool ignored) signal pinMessage(string messageId, bool pinned) signal createDiscussion(string messageId) signal openDiscussion(string discussionRoomId) signal openThread(string threadMessageId) property QtObject rcAccount property string roomId: "" property bool enableEditingMode: false spacing: Kirigami.Units.smallSpacing highlightRangeMode: ListView.ApplyRange preferredHighlightBegin: currentItem === null ? parent.height : parent.height - currentItem.height preferredHighlightEnd: parent.height onCountChanged: { //if (atYEnd) { currentIndex = count - 1 //} } Component.onCompleted: positionViewAtEnd() visible: count > 0 onDragEnded : { if (roomId !== "") { rcAccount.loadHistory(roomId) } } delegate: FancyMessageDelegate { anchors.left: parent.left anchors.right: parent.right anchors.rightMargin: Kirigami.Units.largeSpacing anchors.leftMargin: Kirigami.Units.largeSpacing i_originalMessage: originalMessage i_messageText: messageConverted i_username: username i_usernameurl: usernameurl i_aliasname: alias i_systemMessageType: type i_timestamp: timestamp i_messageID: messageID i_messageType: messagetype i_avatar: avatar == "" ? rcAccount.avatarUrl(userID) : avatar i_urls: urls i_attachments: attachments i_reactions: reactions i_roles: roles i_date: date i_own_username: rcAccount.userName i_can_editing_message: canEditingMessage i_starred: starred i_pinned: pinned i_editedByUserName: editedByUsername i_user_ignored: userIsIgnored i_dcount: discussionCount i_drid: discussionRoomId i_tcount: threadCount i_tmid: threadMessageId - + i_groupable: groupable onOpenChannel: { activeChat.openChannel(channel) } onPinMessage: { activeChat.pinMessage(messageId, pinned) } onOpenDirectChannel: { if (rcAccount.userName !== userName) { activeChat.openDirectChannel(userName) } } onJitsiCallConfActivated: { activeChat.jitsiCallConfActivated() } onDeleteMessage: { activeChat.deleteMessage(messageId) } onReportMessage: { activeChat.reportMessage(messageId) } onDownloadAttachment: { activeChat.downloadAttachment(url) } onEditMessage: { activeChat.editMessage(messageId, messageStr) } onCopyMessage: { activeChat.copyMessage(messageId, messageStr) } onReplyMessage: { activeChat.replyMessage(messageId) } onSetFavoriteMessage: { activeChat.setFavoriteMessage(messageId, starred) } onDisplayImage: { activeChat.displayImage(imageUrl, title, isAnimatedImage) } onDeleteReaction: { activeChat.deleteReaction(messageId, emoji) } onAddReaction: { activeChat.addReaction(messageId, emoji) } onIgnoreUser: { activeChat.ignoreUser(userID, ignored) } onCreateDiscussion: { activeChat.createDiscussion(messageId) } onOpenDiscussion: { activeChat.openDiscussion(discussionRoomId) } onOpenThread: { activeChat.openThread(threadMessageId) } } } diff --git a/src/apps/qml/FancyMessageDelegate.qml b/src/apps/qml/FancyMessageDelegate.qml index 4184cfbb..2e536185 100644 --- a/src/apps/qml/FancyMessageDelegate.qml +++ b/src/apps/qml/FancyMessageDelegate.qml @@ -1,312 +1,318 @@ /* * Copyright 2016 Riccardo Iaconelli * Copyright (c) 2017-2019 Montel Laurent * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License or (at your option) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * */ import QtQuick 2.9 import KDE.Ruqola.RuqolaUtils 1.0 import KDE.Ruqola.Message 1.0 import QtQuick.Controls 2.2 import org.kde.kirigami 2.7 as Kirigami import KDE.Ruqola.ExtraColors 1.0 import QtQuick.Layouts 1.12 import KDE.Ruqola.RocketChatAccount 1.0 import KDE.Ruqola.DebugCategory 1.0 Rectangle { id: messageMain property string i_messageID property string i_originalMessage property string i_messageText property string i_username property string i_usernameurl property bool i_systemMessage property string i_systemMessageType property string i_avatar property string i_aliasname property string i_editedByUserName property var i_timestamp property var i_messageType property var i_urls property var i_attachments property var i_reactions property var i_roles property string i_date property string i_own_username property bool i_can_editing_message property bool i_starred property bool i_user_ignored property bool i_pinned property int i_dcount property string i_drid property string i_tmid property int i_tcount + property bool i_groupable color: RuqolaSingleton.backgroundColor implicitHeight: 4*Kirigami.Units.smallSpacing + loaded.item.implicitHeight implicitWidth: 150 signal openDirectChannel(string userName) signal openChannel(string channel) signal jitsiCallConfActivated() signal deleteMessage(string messageId) signal reportMessage(string messageId) signal downloadAttachment(string url) signal editMessage(string messageId, string messageStr) signal copyMessage(string messageId, string messageStr) signal replyMessage(string messageId) signal setFavoriteMessage(string messageId, bool starred) signal displayImage(url imageUrl, string title, bool isAnimatedImage) signal deleteReaction(string messageId, string emoji) signal addReaction(string messageId, string emoji) signal ignoreUser(bool ignored) signal pinMessage(string messageId, bool pinned) signal createDiscussion(string messageId) signal openDiscussion(string discussionRoomId) signal openThread(string threadMessageId) Loader { id: loaded anchors.fill: parent Component.onCompleted: { if (i_messageType === Message.System) { if (i_systemMessageType === "jitsi_call_started") { console.log(RuqolaDebugCategorySingleton.category, "Jitsi"); setSource("messages/JitsiVideoMessage.qml", { i_messageText: i_messageText, i_username: i_username, i_aliasname: i_aliasname, i_timestamp: i_timestamp, i_systemMessageType: i_systemMessageType, i_messageID: i_messageID, i_avatar: i_avatar, i_date: i_date, rcAccount: appid.rocketChatAccount } ) } else { console.log(RuqolaDebugCategorySingleton.category, "System Message"); setSource("messages/SystemMessage.qml", { i_messageText: i_messageText, i_username: i_username, i_aliasname: i_aliasname, i_timestamp: i_timestamp, i_systemMessageType: i_systemMessageType, i_messageID: i_messageID, i_date: i_date, rcAccount: appid.rocketChatAccount, i_dcount: i_dcount, i_drid: i_drid, i_tcount: i_tcount, + i_groupable: i_groupable, i_tmid: i_tmid } ) } } else if (i_messageType === Message.NormalText || i_messageType === Message.File) { console.log(RuqolaDebugCategorySingleton.category, "User Message"); setSource("messages/UserMessage.qml", { i_originalMessage: i_originalMessage, i_messageText: i_messageText, i_username: i_username, i_usernameurl: i_usernameurl, i_aliasname: i_aliasname, i_timestamp: i_timestamp, i_messageID: i_messageID, i_avatar: i_avatar, i_urls: i_urls, i_reactions: i_reactions, i_roles: i_roles, i_attachments: i_attachments, i_date: i_date, i_own_username: i_own_username, rcAccount: appid.rocketChatAccount, i_can_editing_message: i_can_editing_message, i_editedByUserName: i_editedByUserName, i_starred: i_starred, i_pinned: i_pinned, i_user_ignored : i_user_ignored, i_dcount: i_dcount, i_drid: i_drid, i_tcount: i_tcount, + i_groupable: i_groupable, i_tmid: i_tmid } ) } else if (i_messageType === Message.Audio) { console.log(RuqolaDebugCategorySingleton.category, "Audio"); setSource("messages/AttachmentMessageAudio.qml", { i_messageText: i_messageText, i_username: i_username, i_usernameurl: i_usernameurl, i_aliasname: i_aliasname, i_timestamp: i_timestamp, i_messageID: i_messageID, i_avatar: i_avatar, i_reactions: i_reactions, i_roles: i_roles, i_urls: i_urls, i_attachments: i_attachments, i_date: i_date, i_editedByUserName: i_editedByUserName, rcAccount: appid.rocketChatAccount, i_editedByUserName: i_editedByUserName, i_starred: i_starred, i_pinned: i_pinned, i_dcount: i_dcount, i_drid: i_drid, i_tcount: i_tcount, + i_groupable: i_groupable, i_tmid: i_tmid }) } else if (i_messageType === Message.Video) { console.log(RuqolaDebugCategorySingleton.category, "Video"); setSource("messages/AttachmentMessageVideo.qml", { i_messageText: i_messageText, i_username: i_username, i_usernameurl: i_usernameurl, i_aliasname: i_aliasname, i_timestamp: i_timestamp, i_messageID: i_messageID, i_avatar: i_avatar, i_reactions: i_reactions, i_roles: i_roles, i_urls: i_urls, i_attachments: i_attachments, i_date: i_date, i_editedByUserName: i_editedByUserName, rcAccount: appid.rocketChatAccount, i_editedByUserName: i_editedByUserName, i_starred: i_starred, i_pinned: i_pinned, i_dcount: i_dcount, i_drid: i_drid, i_tcount: i_tcount, + i_groupable: i_groupable, i_tmid: i_tmid }) } else if (i_messageType === Message.Image) { console.log(RuqolaDebugCategorySingleton.category, "Image"); setSource("messages/AttachmentMessageImage.qml", { i_messageText: i_messageText, i_username: i_username, i_usernameurl: i_usernameurl, i_aliasname: i_aliasname, i_timestamp: i_timestamp, i_messageID: i_messageID, i_avatar: i_avatar, i_reactions: i_reactions, i_roles: i_roles, i_urls: i_urls, i_attachments: i_attachments, i_date: i_date, i_editedByUserName: i_editedByUserName, rcAccount: appid.rocketChatAccount, i_editedByUserName: i_editedByUserName, i_starred: i_starred, i_pinned: i_pinned, i_dcount: i_dcount, i_drid: i_drid, i_tcount: i_tcount, + i_groupable: i_groupable, i_tmid: i_tmid }) } else { console.log(RuqolaDebugCategorySingleton.category, "Unknown message type: " + i_messageType) } } } Connections { target: loaded.item onLinkActivated: { var username = RuqolaUtils.extractRoomUserFromUrl(link); if (link.startsWith("ruqola:/room/")) { messageMain.openChannel(username) } else if (link.startsWith("ruqola:/user/")) { if (username !== appid.rocketChatAccount.userName) { messageMain.openDirectChannel(username) } } else { RuqolaUtils.openUrl(link); } } onJitsiCallConfActivated: { messageMain.jitsiCallConfActivated() } onPinMessage: { messageMain.pinMessage(messageId, pinned) } onReportMessage: { messageMain.reportMessage(messageId) } onDeleteMessage: { messageMain.deleteMessage(messageId) } onDownloadAttachment: { messageMain.downloadAttachment(url) } onEditMessage: { console.log(RuqolaDebugCategorySingleton.category, "i_messageText " + i_messageText); messageMain.editMessage(messageId, messageStr) } onCopyMessage: { console.log(RuqolaDebugCategorySingleton.category, "i_messageText " + i_messageText); messageMain.copyMessage(messageId, messageStr) } onReplyMessage: { messageMain.replyMessage(messageId) } onSetFavoriteMessage: { messageMain.setFavoriteMessage(messageId, starred) } onDisplayImage: { messageMain.displayImage(imageUrl, title, isAnimatedImage) } onDeleteReaction: { messageMain.deleteReaction(messageId, emoji) } onAddReaction: { messageMain.addReaction(messageId, emoji) } onIgnoreUser: { messageMain.ignoreUser(ignored) } onCreateDiscussion: { messageMain.createDiscussion(messageId) } onOpenDiscussion: { messageMain.openDiscussion(discussionRoomId) } onOpenThread: { messageMain.openThread(threadMessageId) } } } diff --git a/src/apps/qml/messages/MessageBase.qml b/src/apps/qml/messages/MessageBase.qml index 519310f0..c39a9f25 100644 --- a/src/apps/qml/messages/MessageBase.qml +++ b/src/apps/qml/messages/MessageBase.qml @@ -1,74 +1,75 @@ /* Copyright (c) 2017-2019 Montel Laurent This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License or ( at your option ) version 3 or, at the discretion of KDE e.V. ( which shall act as a proxy as in section 14 of the GPLv3 ), any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import QtQuick 2.9 import QtQuick.Layouts 1.12 ColumnLayout { signal linkActivated(string link) signal jitsiCallConfActivated() signal deleteMessage(string messageId) signal reportMessage(string messageId) signal copyMessage(string messageId, string messageStr) signal editMessage(string messageId, string messageStr) signal replyMessage(string messageId) signal setFavoriteMessage(string messageId, bool starred) signal downloadAttachment(string url) signal displayImage(url imageUrl, string title, bool isAnimatedImage) signal deleteReaction(string messageId, string emoji) signal addReaction(string messageId, string emoji) signal ignoreUser(bool ignored) signal pinMessage(string messageId, bool pinned) signal createDiscussion(string messageId) signal openDiscussion(string discussionRoomId) signal openThread(string threadMessageId) property string i_date property string i_username property string i_usernameurl property string i_aliasname property string i_avatar property var i_timestamp property string i_messageText property string i_originalMessage property var i_urls property var i_attachments property var i_reactions property var i_roles property string i_editedByUserName property bool i_starred property bool i_can_editing_message property bool i_user_ignored property bool i_pinned property int i_dcount property string i_drid property int i_tcount property string i_tmid + property bool i_groupable property QtObject rcAccount NewDateLabel { id: newDateRect date: i_date } } diff --git a/src/ruqolacore/model/messagemodel.cpp b/src/ruqolacore/model/messagemodel.cpp index 02a81acb..938ae6c8 100644 --- a/src/ruqolacore/model/messagemodel.cpp +++ b/src/ruqolacore/model/messagemodel.cpp @@ -1,371 +1,373 @@ /* * Copyright 2016 Riccardo Iaconelli * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License or (at your option) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * */ #include #include #include #include #include #include "messagemodel.h" #include "ruqolaserverconfig.h" #include "room.h" #include "ruqola_debug.h" #include "utils.h" #include "rocketchataccount.h" #include "texthighlighter.h" #include "textconverter.h" #include "loadrecenthistorymanager.h" #include //TODO reactivate when we will able to load message between cache and official server. //#define STORE_MESSAGE 1 MessageModel::MessageModel(const QString &roomID, RocketChatAccount *account, Room *room, QObject *parent) : QAbstractListModel(parent) , mRoomID(roomID) , mRocketChatAccount(account) , mRoom(room) { mTextConverter = new TextConverter(mRocketChatAccount ? mRocketChatAccount->emojiManager() : nullptr); mLoadRecentHistoryManager = new LoadRecentHistoryManager; qCDebug(RUQOLA_LOG) << "Creating message Model"; #ifdef STORE_MESSAGE if (mRocketChatAccount) { const QString cachePath = mRocketChatAccount->settings()->cacheBasePath(); if (cachePath.isEmpty()) { qCWarning(RUQOLA_LOG) << " Cache Path is not defined"; return; } QDir cacheDir(cachePath + QStringLiteral("/rooms_cache")); // load cache if (QFile::exists(cacheDir.absoluteFilePath(roomID)) && !roomID.isEmpty()) { QFile f(cacheDir.absoluteFilePath(roomID)); if (f.open(QIODevice::ReadOnly)) { QDataStream in(&f); while (!f.atEnd()) { char *byteArray; quint32 length; in.readBytes(byteArray, length); const QByteArray arr = QByteArray::fromRawData(byteArray, length); Message m = Message::fromJSon(QJsonDocument::fromBinaryData(arr).object()); addMessage(m); } } } } #endif connect(mRoom, &Room::rolesChanged, this, &MessageModel::refresh); connect(mRoom, &Room::ignoredUsersChanged, this, &MessageModel::refresh); } MessageModel::~MessageModel() { #ifdef STORE_MESSAGE if (mRocketChatAccount) { const QString cachePath = mRocketChatAccount->settings()->cacheBasePath(); if (cachePath.isEmpty()) { qCWarning(RUQOLA_LOG) << " Cache Path is not defined"; return; } QDir cacheDir(cachePath + QStringLiteral("/rooms_cache")); qCDebug(RUQOLA_LOG) << "Caching to..." << cacheDir.path(); if (!cacheDir.exists(cacheDir.path())) { cacheDir.mkpath(cacheDir.path()); } QFile f(cacheDir.absoluteFilePath(mRoomID)); if (f.open(QIODevice::WriteOnly)) { QDataStream out(&f); for (const Message &m : qAsConst(mAllMessages)) { const QByteArray ms = Message::serialize(m); out.writeBytes(ms, ms.size()); } } } #endif delete mTextConverter; delete mLoadRecentHistoryManager; } void MessageModel::refresh() { beginResetModel(); endResetModel(); } QHash MessageModel::roleNames() const { QHash roles; roles[OriginalMessage] = QByteArrayLiteral("originalMessage"); roles[MessageConvertedText] = QByteArrayLiteral("messageConverted"); roles[Username] = QByteArrayLiteral("username"); roles[Timestamp] = QByteArrayLiteral("timestamp"); roles[UserId] = QByteArrayLiteral("userID"); roles[SystemMessageType] = QByteArrayLiteral("type"); roles[MessageId] = QByteArrayLiteral("messageID"); roles[RoomId] = QByteArrayLiteral("roomID"); roles[UpdatedAt] = QByteArrayLiteral("updatedAt"); roles[EditedAt] = QByteArrayLiteral("editedAt"); roles[EditedByUserName] = QByteArrayLiteral("editedByUsername"); roles[EditedByUserId] = QByteArrayLiteral("editedByUserID"); roles[Alias] = QByteArrayLiteral("alias"); roles[Avatar] = QByteArrayLiteral("avatar"); roles[Groupable] = QByteArrayLiteral("groupable"); roles[MessageType] = QByteArrayLiteral("messagetype"); roles[Attachments] = QByteArrayLiteral("attachments"); roles[Urls] = QByteArrayLiteral("urls"); roles[Date] = QByteArrayLiteral("date"); roles[CanEditingMessage] = QByteArrayLiteral("canEditingMessage"); roles[Starred] = QByteArrayLiteral("starred"); roles[UsernameUrl] = QByteArrayLiteral("usernameurl"); roles[Roles] = QByteArrayLiteral("roles"); roles[Reactions] = QByteArrayLiteral("reactions"); roles[Ignored] = QByteArrayLiteral("userIsIgnored"); roles[Pinned] = QByteArrayLiteral("pinned"); roles[DiscussionCount] = QByteArrayLiteral("discussionCount"); roles[DiscussionRoomId] = QByteArrayLiteral("discussionRoomId"); roles[DiscussionLastMessage] = QByteArrayLiteral("discussionLastMessage"); roles[ThreadCount] = QByteArrayLiteral("threadCount"); roles[ThreadLastMessage] = QByteArrayLiteral("threadLastMessage"); roles[ThreadMessageId] = QByteArrayLiteral("threadMessageId"); return roles; } qint64 MessageModel::lastTimestamp() const { if (!mAllMessages.isEmpty()) { //qCDebug(RUQOLA_LOG) << "returning timestamp" << mAllMessages.last().timeStamp(); return mAllMessages.first().timeStamp(); } else { return 0; } } int MessageModel::rowCount(const QModelIndex &parent) const { Q_UNUSED(parent); return mAllMessages.size(); } void MessageModel::addMessage(const Message &message) { auto it = std::upper_bound(mAllMessages.begin(), mAllMessages.end(), message, [](const Message &lhs, const Message &rhs) -> bool { return lhs.timeStamp() < rhs.timeStamp(); } ); //When we have 1 element. if (mAllMessages.count() == 1 && (*mAllMessages.begin()).messageId() == message.messageId()) { (*mAllMessages.begin()) = message; //const QModelIndex index = createIndex(0, 0); qCDebug(RUQOLA_LOG) << "Update Message"; //Q_EMIT dataChanged(index, index); //For the moment !!!! It's not optimal but Q_EMIT dataChanged(index, index); doesn't work beginRemoveRows(QModelIndex(), 0, 0); endRemoveRows(); beginInsertRows(QModelIndex(), 0, 0); endInsertRows(); } else if (((it) != mAllMessages.begin() && (*(it - 1)).messageId() == message.messageId())) { qCDebug(RUQOLA_LOG) << "Update Message"; (*(it-1)) = message; //const QModelIndex index = createIndex(it - 1 - mAllMessages.begin(), 0); //For the moment !!!! It's not optimal but Q_EMIT dataChanged(index, index); doesn't work beginRemoveRows(QModelIndex(), it - 1 - mAllMessages.begin(), it - 1 - mAllMessages.begin()); endRemoveRows(); beginInsertRows(QModelIndex(), it - 1 - mAllMessages.begin(), it - 1 - mAllMessages.begin()); endInsertRows(); //Q_EMIT dataChanged(index, index); } else { const int pos = it - mAllMessages.begin(); beginInsertRows(QModelIndex(), pos, pos); mAllMessages.insert(it, message); endInsertRows(); } } QVariant MessageModel::data(const QModelIndex &index, int role) const { if (!index.isValid()) { qCWarning(RUQOLA_LOG) << "ERROR: invalid index"; return {}; } const int idx = index.row(); switch (role) { case MessageModel::Username: return mAllMessages.at(idx).username(); case MessageModel::OriginalMessage: return mAllMessages.at(idx).text(); case MessageModel::MessageConvertedText: //TODO improve it. if (mAllMessages.at(idx).messageType() == Message::System) { return mAllMessages.at(idx).messageTypeText(); } else { if (mRoom && mRoom->userIsIgnored(mAllMessages.at(idx).userId())) { return QString(QStringLiteral("") + i18n("Ignored Message") + QStringLiteral("")); } const QString userName = mRocketChatAccount ? mRocketChatAccount->userName() : QString(); return convertMessageText(mAllMessages.at(idx).text(), mAllMessages.at(idx).mentions(), userName); } case MessageModel::Timestamp: return mAllMessages.at(idx).timeStamp(); case MessageModel::UserId: return mAllMessages.at(idx).userId(); case MessageModel::SystemMessageType: return mAllMessages.at(idx).systemMessageType(); case MessageModel::MessageId: return mAllMessages.at(idx).messageId(); case MessageModel::Alias: return mAllMessages.at(idx).alias(); case MessageModel::MessageType: return mAllMessages.at(idx).messageType(); case MessageModel::Avatar: return mAllMessages.at(idx).avatar(); case MessageModel::EditedAt: return mAllMessages.at(idx).editedAt(); case MessageModel::EditedByUserName: return mAllMessages.at(idx).editedByUsername(); case MessageModel::Attachments: { QVariantList lst; lst.reserve(mAllMessages.at(idx).attachements().count()); const auto attachs = mAllMessages.at(idx).attachements(); for (const MessageAttachment &att : attachs) { lst.append(QVariant::fromValue(att)); } return lst; } case MessageModel::Urls: { QVariantList lst; lst.reserve(mAllMessages.at(idx).urls().count()); const auto urls = mAllMessages.at(idx).urls(); for (const MessageUrl &url : urls) { lst.append(QVariant::fromValue(url)); } return lst; } case MessageModel::Date: if (idx > 0) { QDateTime previewDate; previewDate.setMSecsSinceEpoch(mAllMessages.at(idx - 1).timeStamp()); QDateTime currentDate; currentDate.setMSecsSinceEpoch(mAllMessages.at(idx).timeStamp()); if (previewDate.date() != currentDate.date()) { return currentDate.date().toString(); } } return QString(); case MessageModel::CanEditingMessage: return (mAllMessages.at(idx).timeStamp() + (mRocketChatAccount ? mRocketChatAccount->ruqolaServerConfig()->blockEditingMessageInMinutes() * 60 * 1000 : 0)) > QDateTime::currentMSecsSinceEpoch(); case MessageModel::Starred: return mAllMessages.at(idx).starred(); case MessageModel::UsernameUrl: { const QString username = mAllMessages.at(idx).username(); if (username.isEmpty()) { return {}; } return QStringLiteral("@%1").arg(mAllMessages.at(idx).username()); } case MessageModel::Roles: return roomRoles(mAllMessages.at(idx).userId()); case MessageModel::Reactions: { QVariantList lst; const auto reactions = mAllMessages.at(idx).reactions().reactions(); lst.reserve(reactions.count()); for (const Reaction &react : reactions) { //Convert reactions lst.append(QVariant::fromValue(react)); } return lst; } case MessageModel::Ignored: return mRoom && mRoom->userIsIgnored(mAllMessages.at(idx).userId()); case MessageModel::Pinned: return mAllMessages.at(idx).messagePinned().pinned(); case MessageModel::DiscussionCount: return mAllMessages.at(idx).discussionCount(); case MessageModel::DiscussionRoomId: return mAllMessages.at(idx).discussionRoomId(); case MessageModel::DiscussionLastMessage: return mAllMessages.at(idx).discussionLastMessage(); case MessageModel::ThreadCount: return mAllMessages.at(idx).threadCount(); case MessageModel::ThreadLastMessage: return mAllMessages.at(idx).threadLastMessage(); case MessageModel::ThreadMessageId: return mAllMessages.at(idx).threadMessageId(); + case MessageModel::Groupable: + return mAllMessages.at(idx).groupable(); } Q_UNREACHABLE(); return {}; } QStringList MessageModel::roomRoles(const QString &userId) const { if (mRoom) { return mRoom->rolesForUserId(userId); } return QStringList(); } QString MessageModel::convertMessageText(const QString &str, const QMap &mentions, const QString &userName) const { return mTextConverter->convertMessageText(str, mentions, userName); } void MessageModel::setRoomID(const QString &roomID) { mRoomID = roomID; } bool MessageModel::isEmpty() const { return mAllMessages.isEmpty(); } void MessageModel::deleteMessage(const QString &messageId) { for (int i = 0, total = mAllMessages.count(); i < total; ++i) { if (mAllMessages.at(i).messageId() == messageId) { beginRemoveRows(QModelIndex(), i, i); mAllMessages.remove(i); endRemoveRows(); break; } } } qint64 MessageModel::generateNewStartTimeStamp(qint64 lastTimeStamp) { return mLoadRecentHistoryManager->generateNewStartTimeStamp(lastTimeStamp); }