diff --git a/linphone-app/CMakeLists.txt b/linphone-app/CMakeLists.txt
index 8d27697a4..322749cf3 100644
--- a/linphone-app/CMakeLists.txt
+++ b/linphone-app/CMakeLists.txt
@@ -122,8 +122,9 @@ set(SOURCES
src/components/calls/CallsListProxyModel.cpp
src/components/camera/Camera.cpp
src/components/camera/CameraPreview.cpp
- src/components/chat/ChatModel.cpp
- src/components/chat/ChatProxyModel.cpp
+ src/components/chat-room/ChatRoomModel.cpp
+ src/components/chat-room/ChatRoomListModel.cpp
+ src/components/chat-room/ChatRoomProxyModel.cpp
src/components/codecs/AbstractCodecsModel.cpp
src/components/codecs/AudioCodecsModel.cpp
src/components/codecs/VideoCodecsModel.cpp
@@ -153,6 +154,7 @@ set(SOURCES
src/components/other/colors/Colors.cpp
src/components/other/text-to-speech/TextToSpeech.cpp
src/components/other/units/Units.cpp
+ src/components/participant/ParticipantModel.cpp
src/components/presence/OwnPresenceModel.cpp
src/components/presence/Presence.cpp
src/components/search/SearchHandler.cpp
@@ -198,8 +200,9 @@ set(HEADERS
src/components/calls/CallsListProxyModel.hpp
src/components/camera/Camera.hpp
src/components/camera/CameraPreview.hpp
- src/components/chat/ChatModel.hpp
- src/components/chat/ChatProxyModel.hpp
+ src/components/chat-room/ChatRoomModel.hpp
+ src/components/chat-room/ChatRoomListModel.hpp
+ src/components/chat-room/ChatRoomProxyModel.hpp
src/components/codecs/AbstractCodecsModel.hpp
src/components/codecs/AudioCodecsModel.hpp
src/components/codecs/VideoCodecsModel.hpp
@@ -231,6 +234,7 @@ set(HEADERS
src/components/other/desktop-tools/DesktopTools.hpp
src/components/other/text-to-speech/TextToSpeech.hpp
src/components/other/units/Units.hpp
+ src/components/participant/ParticipantModel.hpp
src/components/presence/OwnPresenceModel.hpp
src/components/presence/Presence.hpp
src/components/search/SearchHandler.hpp
diff --git a/linphone-app/resources.qrc b/linphone-app/resources.qrc
index a65070a06..aca2f24d0 100644
--- a/linphone-app/resources.qrc
+++ b/linphone-app/resources.qrc
@@ -432,6 +432,7 @@
ui/views/App/Main/Dialogs/AuthenticationRequest.qml
ui/views/App/Main/Dialogs/ManageAccount.js
ui/views/App/Main/Dialogs/ManageAccounts.qml
+ ui/views/App/Main/Dialogs/ManageChatRoom.qml
ui/views/App/Main/Home.qml
ui/views/App/Main/HistoryView.qml
ui/views/App/Main/HistoryView.js
diff --git a/linphone-app/src/app/App.cpp b/linphone-app/src/app/App.cpp
index 01649ce7d..57c589499 100644
--- a/linphone-app/src/app/App.cpp
+++ b/linphone-app/src/app/App.cpp
@@ -582,17 +582,17 @@ void App::registerTypes () {
qInfo() << QStringLiteral("Registering types...");
qRegisterMetaType>();
- qRegisterMetaType();
+ qRegisterMetaType();
qRegisterMetaType>();
qRegisterMetaType > >();
- qRegisterMetaType>();
+ qRegisterMetaType>();
registerType("AssistantModel");
registerType("AuthenticationNotifier");
registerType("CallsListProxyModel");
registerType("Camera");
registerType("CameraPreview");
- registerType("ChatProxyModel");
+ registerType("ChatRoomProxyModel");
registerType("ConferenceHelperModel");
registerType("ConferenceModel");
registerType("ContactsListProxyModel");
@@ -616,7 +616,7 @@ void App::registerTypes () {
registerSingletonType("VideoCodecsModel");
registerUncreatableType("CallModel");
- registerUncreatableType("ChatModel");
+ registerUncreatableType("ChatRoomModel");
registerUncreatableType("ConferenceAddModel");
registerUncreatableType("ContactModel");
registerUncreatableType("ContactsImporterModel");
diff --git a/linphone-app/src/app/logger/Logger.cpp b/linphone-app/src/app/logger/Logger.cpp
index 8080e3910..f66363d14 100644
--- a/linphone-app/src/app/logger/Logger.cpp
+++ b/linphone-app/src/app/logger/Logger.cpp
@@ -23,6 +23,7 @@
#include
#include
#include
+#include
#include "config.h"
@@ -192,7 +193,7 @@ void Logger::enable (bool status) {
void Logger::init (const shared_ptr &config) {
if (mInstance)
return;
-
+ QLoggingCategory::setFilterRules("qt.qml.connections.warning=false");
const QString folder = SettingsModel::getLogsFolder(config);
Q_ASSERT(!folder.isEmpty());
diff --git a/linphone-app/src/components/Components.hpp b/linphone-app/src/components/Components.hpp
index 60cc7c5fc..f17758b70 100644
--- a/linphone-app/src/components/Components.hpp
+++ b/linphone-app/src/components/Components.hpp
@@ -28,7 +28,7 @@
#include "calls/CallsListProxyModel.hpp"
#include "camera/Camera.hpp"
#include "camera/CameraPreview.hpp"
-#include "chat/ChatProxyModel.hpp"
+#include "chat-room/ChatRoomProxyModel.hpp"
#include "codecs/AudioCodecsModel.hpp"
#include "codecs/VideoCodecsModel.hpp"
#include "conference/ConferenceAddModel.hpp"
diff --git a/linphone-app/src/components/call/CallModel.cpp b/linphone-app/src/components/call/CallModel.cpp
index edbd923e2..9daf94b5b 100644
--- a/linphone-app/src/components/call/CallModel.cpp
+++ b/linphone-app/src/components/call/CallModel.cpp
@@ -26,6 +26,8 @@
#include "app/App.hpp"
#include "components/calls/CallsListModel.hpp"
+#include "components/contact/ContactModel.hpp"
+#include "components/contacts/ContactsListModel.hpp"
#include "components/core/CoreHandlers.hpp"
#include "components/core/CoreManager.hpp"
#include "components/notifier/Notifier.hpp"
@@ -112,6 +114,13 @@ QString CallModel::getFullLocalAddress () const {
}
// -----------------------------------------------------------------------------
+ContactModel *CallModel::getContactModel() const{
+ auto contact = CoreManager::getInstance()->getContactsListModel()->findContactModelFromSipAddress(QString::fromStdString(mCall->getRemoteAddress()->asString()));
+ return contact;
+}
+
+
+// -----------------------------------------------------------------------------
void CallModel::setRecordFile (const shared_ptr &callParams) {
callParams->setRecordFile(Utils::appStringToCoreString(
CoreManager::getInstance()->getSettingsModel()->getSavedCallsFolder()
diff --git a/linphone-app/src/components/call/CallModel.hpp b/linphone-app/src/components/call/CallModel.hpp
index 71ccbf486..92b2ead41 100644
--- a/linphone-app/src/components/call/CallModel.hpp
+++ b/linphone-app/src/components/call/CallModel.hpp
@@ -26,6 +26,7 @@
#include "../search/SearchHandler.hpp"
// =============================================================================
+class ContactModel;
class CallModel : public QObject {
Q_OBJECT;
@@ -34,6 +35,12 @@ class CallModel : public QObject {
Q_PROPERTY(QString localAddress READ getLocalAddress CONSTANT);
Q_PROPERTY(QString fullPeerAddress READ getFullPeerAddress NOTIFY fullPeerAddressChanged);
Q_PROPERTY(QString fullLocalAddress READ getFullLocalAddress CONSTANT);
+
+ Q_PROPERTY(ContactModel *contact READ getContactModel CONSTANT )/*
+ Q_PROPERTY(QString sipAddress READ getFullPeerAddress NOTIFY fullPeerAddressChanged)
+ Q_PROPERTY(QString username READ getUsername NOTIFY usernameChanged)
+ Q_PROPERTY(QString avatar READ getAvatar NOTIFY avatarChanged)
+ Q_PROPERTY(int presenceStatus READ getPresenceStatus NOTIFY presenceStatusChanged)*/
Q_PROPERTY(CallStatus status READ getStatus NOTIFY statusChanged);
Q_PROPERTY(QString callError READ getCallError NOTIFY callErrorChanged);
@@ -98,6 +105,8 @@ public:
QString getLocalAddress () const;
QString getFullPeerAddress () const;
QString getFullLocalAddress () const;
+
+ ContactModel *getContactModel() const;
bool isInConference () const {
return mIsInConference;
diff --git a/linphone-app/src/components/calls/CallsListModel.cpp b/linphone-app/src/components/calls/CallsListModel.cpp
index 7d0f789c1..91da689da 100644
--- a/linphone-app/src/components/calls/CallsListModel.cpp
+++ b/linphone-app/src/components/calls/CallsListModel.cpp
@@ -183,6 +183,29 @@ bool CallsListModel::launchSecureChat (const QString &sipAddress) const {
*/
return false;
}
+
+bool CallsListModel::createSecureChat (const QString& subject, const QString &participantAddress) const{
+ shared_ptr core = CoreManager::getInstance()->getCore();
+ shared_ptr address = core->interpretUrl(Utils::appStringToCoreString(participantAddress));
+ if (!address)
+ return false;
+
+ std::shared_ptr params = core->createDefaultChatRoomParams();
+ std::list > participants;
+ std::shared_ptr localAddress;
+ participants.push_back(address);
+ auto proxy = core->getDefaultProxyConfig();
+ params->enableEncryption(true);
+
+ params->setSubject(subject.toStdString());
+ params->setBackend(linphone::ChatRoomBackend::FlexisipChat);
+ params->setEncryptionBackend(linphone::ChatRoomEncryptionBackend::Lime);
+ params->enableGroup(true);
+
+ std::shared_ptr chatRoom = core->createChatRoom(params, localAddress, participants);
+ return chatRoom != nullptr;
+}
+
// -----------------------------------------------------------------------------
int CallsListModel::getRunningCallsNumber () const {
diff --git a/linphone-app/src/components/calls/CallsListModel.hpp b/linphone-app/src/components/calls/CallsListModel.hpp
index 0edb7193c..7a978dfcf 100644
--- a/linphone-app/src/components/calls/CallsListModel.hpp
+++ b/linphone-app/src/components/calls/CallsListModel.hpp
@@ -45,6 +45,7 @@ public:
Q_INVOKABLE void launchAudioCall (const QString &sipAddress, const QHash &headers = {}) const;
Q_INVOKABLE void launchVideoCall (const QString &sipAddress) const;
Q_INVOKABLE bool launchSecureChat (const QString &sipAddress) const;
+ Q_INVOKABLE bool createSecureChat (const QString& subject, const QString &participantAddress) const;
Q_INVOKABLE int getRunningCallsNumber () const;
diff --git a/linphone-app/src/components/chat-room/ChatRoomListModel.cpp b/linphone-app/src/components/chat-room/ChatRoomListModel.cpp
new file mode 100644
index 000000000..ee74d4ba0
--- /dev/null
+++ b/linphone-app/src/components/chat-room/ChatRoomListModel.cpp
@@ -0,0 +1,96 @@
+/*
+ * Copyright (c) 2021 Belledonne Communications SARL.
+ *
+ * This file is part of linphone-desktop
+ * (see https://www.linphone.org).
+ *
+ * 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * 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 "app/App.hpp"
+#include "components/conference/ConferenceAddModel.hpp"
+#include "components/conference/ConferenceHelperModel.hpp"
+#include "components/core/CoreHandlers.hpp"
+#include "components/core/CoreManager.hpp"
+#include "components/settings/SettingsModel.hpp"
+#include "utils/Utils.hpp"
+
+#include "ChatRoomListModel.hpp"
+#include "ChatRoomModel.hpp"
+
+// =============================================================================
+
+using namespace std;
+
+namespace {
+ // Delay before removing call in ms.
+ constexpr int DelayBeforeRemoveCall = 3000;
+}
+
+
+// -----------------------------------------------------------------------------
+
+ChatRoomListModel::ChatRoomListModel (QObject *parent) : QAbstractListModel(parent) {
+}
+
+int ChatRoomListModel::rowCount (const QModelIndex &) const {
+ return mList.count();
+}
+
+QHash ChatRoomListModel::roleNames () const {
+ QHash roles;
+ roles[Qt::DisplayRole] = "$chatRoom";
+ return roles;
+}
+
+QVariant ChatRoomListModel::data (const QModelIndex &index, int role) const {
+ int row = index.row();
+
+ if (!index.isValid() || row < 0 || row >= mList.count())
+ return QVariant();
+
+ if (role == Qt::DisplayRole)
+ return QVariant::fromValue(mList[row]);
+
+ return QVariant();
+}
+
+// -----------------------------------------------------------------------------
+
+
+bool ChatRoomListModel::removeRow (int row, const QModelIndex &parent) {
+ return removeRows(row, 1, parent);
+}
+
+bool ChatRoomListModel::removeRows (int row, int count, const QModelIndex &parent) {
+ int limit = row + count - 1;
+
+ if (row < 0 || count < 0 || limit >= mList.count())
+ return false;
+
+ beginRemoveRows(parent, row, limit);
+
+ for (int i = 0; i < count; ++i)
+ mList.takeAt(row)->deleteLater();
+
+ endRemoveRows();
+
+ return true;
+}
+
+// -----------------------------------------------------------------------------
diff --git a/linphone-app/src/components/chat-room/ChatRoomListModel.hpp b/linphone-app/src/components/chat-room/ChatRoomListModel.hpp
new file mode 100644
index 000000000..68fe0c747
--- /dev/null
+++ b/linphone-app/src/components/chat-room/ChatRoomListModel.hpp
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2021 Belledonne Communications SARL.
+ *
+ * This file is part of linphone-desktop
+ * (see https://www.linphone.org).
+ *
+ * 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * 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 .
+ */
+
+#ifndef _CHAT_ROOM_LIST_MODEL_H_
+#define _CHAT_ROOM_LIST_MODEL_H_
+
+#include
+#include
+
+// =============================================================================
+
+class ChatRoomModel;
+
+class ChatRoomListModel : public QAbstractListModel {
+ Q_OBJECT;
+
+public:
+ ChatRoomListModel (QObject *parent = Q_NULLPTR);
+
+ int rowCount (const QModelIndex &index = QModelIndex()) const override;
+
+ QHash roleNames () const override;
+ QVariant data (const QModelIndex &index, int role = Qt::DisplayRole) const override;
+
+
+private:
+ bool removeRow (int row, const QModelIndex &parent = QModelIndex());
+ bool removeRows (int row, int count, const QModelIndex &parent = QModelIndex()) override;
+
+ QList mList;
+
+};
+
+#endif // _CHAT_ROOM_LIST_MODEL_H_
diff --git a/linphone-app/src/components/chat/ChatModel.cpp b/linphone-app/src/components/chat-room/ChatRoomModel.cpp
similarity index 65%
rename from linphone-app/src/components/chat/ChatModel.cpp
rename to linphone-app/src/components/chat-room/ChatRoomModel.cpp
index 887beb170..99879af52 100644
--- a/linphone-app/src/components/chat/ChatModel.cpp
+++ b/linphone-app/src/components/chat-room/ChatRoomModel.cpp
@@ -34,14 +34,19 @@
#include "app/App.hpp"
#include "app/paths/Paths.hpp"
#include "app/providers/ThumbnailProvider.hpp"
+#include "components/contact/ContactModel.hpp"
+#include "components/contact/VcardModel.hpp"
+#include "components/contacts/ContactsListModel.hpp"
#include "components/core/CoreHandlers.hpp"
#include "components/core/CoreManager.hpp"
#include "components/notifier/Notifier.hpp"
#include "components/settings/SettingsModel.hpp"
+#include "components/participant/ParticipantModel.hpp"
+#include "components/presence/Presence.hpp"
#include "utils/QExifImageHeader.hpp"
#include "utils/Utils.hpp"
-#include "ChatModel.hpp"
+#include "ChatRoomModel.hpp"
// =============================================================================
@@ -204,9 +209,9 @@ static inline void fillMessageEntry (QVariantMap &dest, const shared_ptrgetState();
if (state == linphone::ChatMessage::State::InProgress)
- dest["status"] = ChatModel::MessageStatusNotDelivered;
+ dest["status"] = ChatRoomModel::MessageStatusNotDelivered;
else
- dest["status"] = static_cast(message->getState());
+ dest["status"] = static_cast(message->getState());
shared_ptr content = message->getFileTransferInformation();
if (content) {
@@ -220,39 +225,39 @@ static inline void fillMessageEntry (QVariantMap &dest, const shared_ptr &callLog) {
- dest["type"] = ChatModel::CallEntry;
+ dest["type"] = ChatRoomModel::CallEntry;
dest["timestamp"] = QDateTime::fromMSecsSinceEpoch(callLog->getStartDate() * 1000);
dest["isOutgoing"] = callLog->getDir() == linphone::Call::Dir::Outgoing;
- dest["status"] = static_cast(callLog->getStatus());
+ dest["status"] = static_cast(callLog->getStatus());
dest["isStart"] = true;
}
static inline void fillCallEndEntry (QVariantMap &dest, const shared_ptr &callLog) {
- dest["type"] = ChatModel::CallEntry;
+ dest["type"] = ChatRoomModel::CallEntry;
dest["timestamp"] = QDateTime::fromMSecsSinceEpoch((callLog->getStartDate() + callLog->getDuration()) * 1000);
dest["isOutgoing"] = callLog->getDir() == linphone::Call::Dir::Outgoing;
- dest["status"] = static_cast(callLog->getStatus());
+ dest["status"] = static_cast(callLog->getStatus());
dest["isStart"] = false;
}
// -----------------------------------------------------------------------------
-class ChatModel::MessageHandlers : public linphone::ChatMessageListener {
- friend class ChatModel;
+class ChatRoomModel::MessageHandlers : public linphone::ChatMessageListener {
+ friend class ChatRoomModel;
public:
- MessageHandlers (ChatModel *chatModel) : mChatModel(chatModel) {}
+ MessageHandlers (ChatRoomModel *ChatRoomModel) : mChatRoomModel(ChatRoomModel) {}
private:
QList::iterator findMessageEntry (const shared_ptr &message) {
- return find_if(mChatModel->mEntries.begin(), mChatModel->mEntries.end(), [&message](const ChatEntryData &entry) {
+ return find_if(mChatRoomModel->mEntries.begin(), mChatRoomModel->mEntries.end(), [&message](const ChatEntryData &entry) {
return entry.second == message;
});
}
void signalDataChanged (const QList::iterator &it) {
- int row = int(distance(mChatModel->mEntries.begin(), it));
- emit mChatModel->dataChanged(mChatModel->index(row, 0), mChatModel->index(row, 0));
+ int row = int(distance(mChatRoomModel->mEntries.begin(), it));
+ emit mChatRoomModel->dataChanged(mChatRoomModel->index(row, 0), mChatRoomModel->index(row, 0));
}
shared_ptr onFileTransferSend (
@@ -271,11 +276,11 @@ private:
size_t offset,
size_t
) override {
- if (!mChatModel)
+ if (!mChatRoomModel)
return;
auto it = findMessageEntry(message);
- if (it == mChatModel->mEntries.end())
+ if (it == mChatRoomModel->mEntries.end())
return;
(*it).first["fileOffset"] = quint64(offset);
@@ -284,11 +289,11 @@ private:
}
void onMsgStateChanged (const shared_ptr &message, linphone::ChatMessage::State state) override {
- if (!mChatModel)
+ if (!mChatRoomModel)
return;
auto it = findMessageEntry(message);
- if (it == mChatModel->mEntries.end())
+ if (it == mChatRoomModel->mEntries.end())
return;
// File message downloaded.
@@ -304,12 +309,12 @@ private:
signalDataChanged(it);
}
- ChatModel *mChatModel;
+ ChatRoomModel *mChatRoomModel;
};
// -----------------------------------------------------------------------------
-
-ChatModel::ChatModel (const QString &peerAddress, const QString &localAddress, const bool& isSecure) {
+/*
+ChatRoomModel::ChatRoomModel (const QString &peerAddress, const QString &localAddress, const bool& isSecure) {
CoreManager *coreManager = CoreManager::getInstance();
mCoreHandlers = coreManager->getHandlers();
@@ -319,21 +324,10 @@ ChatModel::ChatModel (const QString &peerAddress, const QString &localAddress, c
shared_ptr factory(linphone::Factory::get());
std::shared_ptr params = core->createDefaultChatRoomParams();
std::list> participants;
-
- //params->enableEncryption(isSecure);
- //if(isSecure){
- // params->setBackend(linphone::ChatRoomBackend::FlexisipChat);
-// params->setEncryptionBackend(linphone::ChatRoomEncryptionBackend::Lime);
-// }
-
+
mChatRoom = core->searchChatRoom(params, factory->createAddress(localAddress.toStdString())
, factory->createAddress(peerAddress.toStdString())
, participants);
- /*
- mChatRoom = core->getChatRoom(
- factory->createAddress(peerAddress.toStdString()),
- factory->createAddress(localAddress.toStdString())
- );*/
Q_ASSERT(mChatRoom);
handleIsComposingChanged(mChatRoom);
@@ -358,7 +352,7 @@ ChatModel::ChatModel (const QString &peerAddress, const QString &localAddress, c
for (auto &callLog : core->getCallHistory(mChatRoom->getPeerAddress(), mChatRoom->getLocalAddress()))
insertCall(callLog);
- qInfo() << QStringLiteral("ChatModel (%1, %2) loaded in %3 milliseconds.")
+ qInfo() << QStringLiteral("ChatRoomModel (%1, %2) loaded in %3 milliseconds.")
.arg(peerAddress).arg(localAddress).arg(timer.elapsed());
// Rebind lost handlers
@@ -371,15 +365,16 @@ ChatModel::ChatModel (const QString &peerAddress, const QString &localAddress, c
}
{
CoreHandlers *coreHandlers = mCoreHandlers.get();
- QObject::connect(coreHandlers, &CoreHandlers::messageReceived, this, &ChatModel::handleMessageReceived);
- QObject::connect(coreHandlers, &CoreHandlers::callStateChanged, this, &ChatModel::handleCallStateChanged);
- QObject::connect(coreHandlers, &CoreHandlers::isComposingChanged, this, &ChatModel::handleIsComposingChanged);
+ QObject::connect(coreHandlers, &CoreHandlers::messageReceived, this, &ChatRoomModel::handleMessageReceived);
+ QObject::connect(coreHandlers, &CoreHandlers::callStateChanged, this, &ChatRoomModel::handleCallStateChanged);
+ QObject::connect(coreHandlers, &CoreHandlers::isComposingChanged, this, &ChatRoomModel::handleIsComposingChanged);
}
if(!mChatRoom)
qWarning("TOTO A");
}
+*/
-ChatModel::ChatModel (std::shared_ptr chatRoom){
+ChatRoomModel::ChatRoomModel (std::shared_ptr chatRoom){
CoreManager *coreManager = CoreManager::getInstance();
mCoreHandlers = coreManager->getHandlers();
@@ -394,8 +389,12 @@ ChatModel::ChatModel (std::shared_ptr chatRoom){
mChatRoom = chatRoom;
Q_ASSERT(mChatRoom);
+
+ setLastUpdateTime(QDateTime::fromMSecsSinceEpoch(chatRoom->getLastUpdateTime()));
+ setUnreadMessagesCount(chatRoom->getUnreadMessagesCount());
+ mMissedCallsCount = 0;
- handleIsComposingChanged(mChatRoom);
+ //handleIsComposingChanged(mChatRoom);
// Get messages.
mEntries.clear();
@@ -430,30 +429,35 @@ ChatModel::ChatModel (std::shared_ptr chatRoom){
}
{
CoreHandlers *coreHandlers = mCoreHandlers.get();
- QObject::connect(coreHandlers, &CoreHandlers::messageReceived, this, &ChatModel::handleMessageReceived);
- QObject::connect(coreHandlers, &CoreHandlers::callStateChanged, this, &ChatModel::handleCallStateChanged);
- QObject::connect(coreHandlers, &CoreHandlers::isComposingChanged, this, &ChatModel::handleIsComposingChanged);
+ //QObject::connect(coreHandlers, &CoreHandlers::messageReceived, this, &ChatRoomModel::handleMessageReceived);
+ QObject::connect(coreHandlers, &CoreHandlers::callCreated, this, &ChatRoomModel::handleCallCreated);
+ QObject::connect(coreHandlers, &CoreHandlers::callStateChanged, this, &ChatRoomModel::handleCallStateChanged);
+ //QObject::connect(coreHandlers, &CoreHandlers::isComposingChanged, this, &ChatRoomModel::handleIsComposingChanged);
+ }
+ if(mChatRoom){
+ std::list> participants = mChatRoom->getParticipants();
+ for(auto it = participants.begin() ; it != participants.end() ; ++it){
+ mParticipants << new ParticipantModel(*it, this);
+ }
}
- if(!mChatRoom)
- qWarning("TOTO B");
}
-ChatModel::~ChatModel () {
- mMessageHandlers->mChatModel = nullptr;
+ChatRoomModel::~ChatRoomModel () {
+ mMessageHandlers->mChatRoomModel = nullptr;
}
-QHash ChatModel::roleNames () const {
+QHash ChatRoomModel::roleNames () const {
QHash roles;
roles[Roles::ChatEntry] = "$chatEntry";
roles[Roles::SectionDate] = "$sectionDate";
return roles;
}
-int ChatModel::rowCount (const QModelIndex &) const {
+int ChatRoomModel::rowCount (const QModelIndex &) const {
return mEntries.count();
}
-QVariant ChatModel::data (const QModelIndex &index, int role) const {
+QVariant ChatRoomModel::data (const QModelIndex &index, int role) const {
int row = index.row();
if (!index.isValid() || row < 0 || row >= mEntries.count())
@@ -473,11 +477,11 @@ QVariant ChatModel::data (const QModelIndex &index, int role) const {
return QVariant();
}
-bool ChatModel::removeRow (int row, const QModelIndex &) {
+bool ChatRoomModel::removeRow (int row, const QModelIndex &) {
return removeRows(row, 1);
}
-bool ChatModel::removeRows (int row, int count, const QModelIndex &parent) {
+bool ChatRoomModel::removeRows (int row, int count, const QModelIndex &parent) {
int limit = row + count - 1;
if (row < 0 || count < 0 || limit >= mEntries.count())
@@ -500,46 +504,111 @@ bool ChatModel::removeRows (int row, int count, const QModelIndex &parent) {
return true;
}
-QString ChatModel::getPeerAddress () const {
+QString ChatRoomModel::getPeerAddress () const {
return Utils::coreStringToAppString(
mChatRoom->getPeerAddress()->asStringUriOnly()
);
}
-QString ChatModel::getLocalAddress () const {
+QString ChatRoomModel::getLocalAddress () const {
return Utils::coreStringToAppString(
mChatRoom->getLocalAddress()->asStringUriOnly()
);
}
-QString ChatModel::getFullPeerAddress () const {
+QString ChatRoomModel::getFullPeerAddress () const {
if(!mChatRoom)
qWarning("TOTO Z");
return QString::fromStdString(mChatRoom->getPeerAddress()->asString());
}
-QString ChatModel::getFullLocalAddress () const {
+QString ChatRoomModel::getFullLocalAddress () const {
return QString::fromStdString(mChatRoom->getLocalAddress()->asString());
}
-void ChatModel::setSipAddresses (const QString &peerAddress, const QString &localAddress, const bool& isSecure) {
+
+QString ChatRoomModel::getSubject () const {
+ return QString::fromStdString(mChatRoom->getSubject());
+}
+
+QString ChatRoomModel::getUsername () const {
+ std::string username = mChatRoom->getSubject();
+ if(username != ""){
+ return QString::fromStdString(username);
+ }
+ if( mChatRoom->getNbParticipants() == 1){
+ auto participants = mChatRoom->getParticipants();
+ auto contact = CoreManager::getInstance()->getContactsListModel()->findContactModelFromSipAddress(QString::fromStdString((*participants.begin())->getAddress()->asString()));
+ if(contact)
+ return contact->getVcardModel()->getUsername();
+ }
+ username = mChatRoom->getPeerAddress()->getDisplayName();
+ if(username != "")
+ return QString::fromStdString(username);
+ username = mChatRoom->getPeerAddress()->getUsername();
+ if(username != "")
+ return QString::fromStdString(username);
+ return QString::fromStdString(mChatRoom->getPeerAddress()->asStringUriOnly());
+}
+
+QString ChatRoomModel::getAvatar () const {
+ if( mChatRoom->getNbParticipants() == 1){
+ auto participants = mChatRoom->getParticipants();
+ auto contact = CoreManager::getInstance()->getContactsListModel()->findContactModelFromSipAddress(QString::fromStdString((*participants.begin())->getAddress()->asString()));
+ if(contact)
+ return contact->getVcardModel()->getAvatar();
+ }
+ return "";
+}
+
+int ChatRoomModel::getPresenceStatus() const {
+ if( mChatRoom->getNbParticipants() == 1){
+ auto participants = mChatRoom->getParticipants();
+ auto contact = CoreManager::getInstance()->getContactsListModel()->findContactModelFromSipAddress(QString::fromStdString((*participants.begin())->getAddress()->asString()));
+ if(contact)
+ return contact->getPresenceLevel();
+ else
+ return 0;
+ }else
+ return 0;
+ //return Presence::getPresenceLevel(1);
+ //return mChatRoom->getConsolidatedPresence();
+}
+
+void ChatRoomModel::setLastUpdateTime(const QDateTime& lastUpdateDate) {
+ if(mLastUpdateTime != lastUpdateDate ) {
+ mLastUpdateTime = lastUpdateDate;
+ emit lastUpdateTimeChanged();
+ }
+}
+
+void ChatRoomModel::setUnreadMessagesCount(const int& count){
+ if(count != mUnreadMessagesCount){
+ mUnreadMessagesCount = count;
+ emit unreadMessagesCountChanged();
+ }
+}
+
+void ChatRoomModel::setMissedCallsCount(const int& count){
+ if(count != mMissedCallsCount){
+ mMissedCallsCount = count;
+ emit missedCallsCountChanged();
+ }
+}
+
+
+void ChatRoomModel::leaveChatRoom (){
+ mChatRoom->leave();
+ mChatRoom->getCore()->deleteChatRoom(mChatRoom);
+}
+/*
+void ChatRoomModel::setSipAddresses (const QString &peerAddress, const QString &localAddress, const bool& isSecure) {
shared_ptr core = CoreManager::getInstance()->getCore();
shared_ptr factory(linphone::Factory::get());
std::shared_ptr params = core->createDefaultChatRoomParams();
std::list> participants;
-
- //params->enableEncryption(isSecure);
- //if(isSecure){
- // params->setBackend(linphone::ChatRoomBackend::FlexisipChat);
-// params->setEncryptionBackend(linphone::ChatRoomEncryptionBackend::Lime);
-// }
-
+
mChatRoom = core->searchChatRoom(params, factory->createAddress(localAddress.toStdString())
, factory->createAddress(peerAddress.toStdString())
, participants);
- /*
- mChatRoom = core->getChatRoom(
- factory->createAddress(peerAddress.toStdString()),
- factory->createAddress(localAddress.toStdString())
- );*/
Q_ASSERT(mChatRoom);
handleIsComposingChanged(mChatRoom);
@@ -564,26 +633,36 @@ void ChatModel::setSipAddresses (const QString &peerAddress, const QString &loca
for (auto &callLog : core->getCallHistory(mChatRoom->getPeerAddress(), mChatRoom->getLocalAddress()))
insertCall(callLog);
- qInfo() << QStringLiteral("ChatModel (%1, %2) loaded in %3 milliseconds.")
+ qInfo() << QStringLiteral("ChatRoomModel (%1, %2) loaded in %3 milliseconds.")
.arg(peerAddress).arg(localAddress).arg(timer.elapsed());
if(!mChatRoom)
qWarning("TOTO C");
}
+*/
-bool ChatModel::getIsSecure() const{
+bool ChatRoomModel::getIsSecure() const{
return mChatRoom->getSecurityLevel() == linphone::ChatRoomSecurityLevel::Encrypted
|| mChatRoom->getSecurityLevel() == linphone::ChatRoomSecurityLevel::Safe;
}
-bool ChatModel::getIsRemoteComposing () const {
+bool ChatRoomModel::getIsRemoteComposing () const {
return mIsRemoteComposing;
}
+//QList ChatRoomModel::getParticipants() const{
+QString ChatRoomModel::getParticipants() const{
+ QStringList participants;
+ for(auto it = mParticipants.begin() ; it != mParticipants.end() ; ++it)
+ participants << (*it)->getAddress();
+
+ return participants.join(",");
+}
+
// -----------------------------------------------------------------------------
-void ChatModel::removeEntry (int id) {
+void ChatRoomModel::removeEntry (int id) {
qInfo() << QStringLiteral("Removing chat entry: %1 of (%2, %3).")
.arg(id).arg(getPeerAddress()).arg(getLocalAddress());
@@ -591,7 +670,7 @@ void ChatModel::removeEntry (int id) {
qWarning() << QStringLiteral("Unable to remove chat entry: %1").arg(id);
}
-void ChatModel::removeAllEntries () {
+void ChatRoomModel::removeAllEntries () {
qInfo() << QStringLiteral("Removing all chat entries of: (%1, %2).")
.arg(getPeerAddress()).arg(getLocalAddress());
@@ -610,19 +689,18 @@ void ChatModel::removeAllEntries () {
// -----------------------------------------------------------------------------
-void ChatModel::sendMessage (const QString &message) {
- shared_ptr _message = mChatRoom->createMessage("");
- _message->getContents().begin()->get()->setStringBuffer(message.toUtf8().toStdString());
+void ChatRoomModel::sendMessage (const QString &message) {
+ shared_ptr _message = mChatRoom->createMessageFromUtf8("");
+ _message->getContents().begin()->get()->setUtf8Text(message.toUtf8().toStdString());
_message->removeListener(mMessageHandlers);// Remove old listener if already exists
_message->addListener(mMessageHandlers);
- insertMessageAtEnd(_message);
_message->send();
emit messageSent(_message);
}
-void ChatModel::resendMessage (int id) {
+void ChatRoomModel::resendMessage (int id) {
if (id < 0 || id > mEntries.count()) {
qWarning() << QStringLiteral("Entry %1 not exists.").arg(id);
return;
@@ -652,7 +730,7 @@ void ChatModel::resendMessage (int id) {
}
}
-void ChatModel::sendFileMessage (const QString &path) {
+void ChatRoomModel::sendFileMessage (const QString &path) {
QFile file(path);
if (!file.exists())
return;
@@ -682,7 +760,6 @@ void ChatModel::sendFileMessage (const QString &path) {
createThumbnail(message);
- insertMessageAtEnd(message);
message->send();
emit messageSent(message);
@@ -690,7 +767,7 @@ void ChatModel::sendFileMessage (const QString &path) {
// -----------------------------------------------------------------------------
-void ChatModel::downloadFile (int id) {
+void ChatRoomModel::downloadFile (int id) {
const ChatEntryData entry = getFileMessageEntry(id);
if (!entry.second)
return;
@@ -734,7 +811,7 @@ void ChatModel::downloadFile (int id) {
}
}
-void ChatModel::openFile (int id, bool showDirectory) {
+void ChatRoomModel::openFile (int id, bool showDirectory) {
const ChatEntryData entry = getFileMessageEntry(id);
if (!entry.second)
return;
@@ -750,27 +827,29 @@ void ChatModel::openFile (int id, bool showDirectory) {
}
}
-bool ChatModel::fileWasDownloaded (int id) {
+bool ChatRoomModel::fileWasDownloaded (int id) {
const ChatEntryData entry = getFileMessageEntry(id);
return entry.second && ::fileWasDownloaded(static_pointer_cast(entry.second));
}
-void ChatModel::compose () {
+void ChatRoomModel::compose () {
mChatRoom->compose();
}
-void ChatModel::resetMessageCount () {
+void ChatRoomModel::resetMessageCount () {
if (mChatRoom->getUnreadMessagesCount() > 0){
mChatRoom->markAsRead();// Marking as read is only for messages. Not for calls.
+ setUnreadMessagesCount(mChatRoom->getUnreadMessagesCount());
}
+ mMissedCallsCount = 0;
emit messageCountReset();
}
-std::shared_ptr ChatModel::getChatRoom(){
+std::shared_ptr ChatRoomModel::getChatRoom(){
return mChatRoom;
}
// -----------------------------------------------------------------------------
-const ChatModel::ChatEntryData ChatModel::getFileMessageEntry (int id) {
+const ChatRoomModel::ChatEntryData ChatRoomModel::getFileMessageEntry (int id) {
if (id < 0 || id > mEntries.count()) {
qWarning() << QStringLiteral("Entry %1 not exists.").arg(id);
return ChatEntryData();
@@ -793,18 +872,18 @@ const ChatModel::ChatEntryData ChatModel::getFileMessageEntry (int id) {
// -----------------------------------------------------------------------------
-void ChatModel::removeEntry (ChatEntryData &entry) {
+void ChatRoomModel::removeEntry (ChatEntryData &entry) {
int type = entry.first["type"].toInt();
switch (type) {
- case ChatModel::MessageEntry: {
+ case ChatRoomModel::MessageEntry: {
shared_ptr message = static_pointer_cast(entry.second);
removeFileMessageThumbnail(message);
mChatRoom->deleteMessage(message);
break;
}
- case ChatModel::CallEntry: {
+ case ChatRoomModel::CallEntry: {
if (entry.first["status"].toInt() == CallStatusSuccess) {
// WARNING: Unable to remove symmetric call here. (start/end)
// We are between `beginRemoveRows` and `endRemoveRows`.
@@ -829,7 +908,7 @@ void ChatModel::removeEntry (ChatEntryData &entry) {
}
}
-void ChatModel::insertCall (const shared_ptr &callLog) {
+void ChatRoomModel::insertCall (const shared_ptr &callLog) {
linphone::Call::Status status = callLog->getStatus();
auto insertEntry = [this](
@@ -862,7 +941,7 @@ void ChatModel::insertCall (const shared_ptr &callLog) {
}
}
-void ChatModel::insertMessageAtEnd (const shared_ptr &message) {
+void ChatRoomModel::insertMessageAtEnd (const shared_ptr &message) {
int row = mEntries.count();
beginInsertRows(QModelIndex(), row, row);
@@ -879,27 +958,95 @@ void ChatModel::insertMessageAtEnd (const shared_ptr &mes
// -----------------------------------------------------------------------------
-void ChatModel::handleCallStateChanged (const shared_ptr &call, linphone::Call::State state) {
- if (
- (state == linphone::Call::State::End || state == linphone::Call::State::Error) &&
- mChatRoom == CoreManager::getInstance()->getCore()->findChatRoom(call->getRemoteAddress(), mChatRoom->getLocalAddress())
- )
- insertCall(call->getCallLog());
+void ChatRoomModel::handleCallStateChanged (const shared_ptr &call, linphone::Call::State state) {
+ if (state == linphone::Call::State::End || state == linphone::Call::State::Error){
+ shared_ptr core = CoreManager::getInstance()->getCore();
+ std::shared_ptr params = core->createDefaultChatRoomParams();
+ std::list> participants;
+
+ auto chatRoom = core->searchChatRoom(params, mChatRoom->getLocalAddress()
+ , call->getRemoteAddress()
+ , participants);
+ if( mChatRoom == chatRoom){
+ insertCall(call->getCallLog());
+ setMissedCallsCount(mMissedCallsCount+1);
+ }
+ //mChatRoom == CoreManager::getInstance()->getCore()->findChatRoom(call->getRemoteAddress(), mChatRoom->getLocalAddress())
+ }
}
-void ChatModel::handleIsComposingChanged (const shared_ptr &chatRoom) {
- if (mChatRoom == chatRoom) {
- bool isRemoteComposing = mChatRoom->isRemoteComposing();
- if (isRemoteComposing != mIsRemoteComposing) {
- mIsRemoteComposing = isRemoteComposing;
+void ChatRoomModel::handleCallCreated(const shared_ptr &call){
+}
+//----------------------------------------------------------
+//------ CHAT ROOM HANDLERS
+//----------------------------------------------------------
+
+void ChatRoomModel::onIsComposingReceived(const std::shared_ptr & chatRoom, const std::shared_ptr & remoteAddress, bool isComposing){
+ if (isComposing != mIsRemoteComposing) {
+ mIsRemoteComposing = isComposing;
emit isRemoteComposingChanged(mIsRemoteComposing);
}
- }
}
-
-void ChatModel::handleMessageReceived (const shared_ptr &message) {
- if (mChatRoom == message->getChatRoom()) {
- insertMessageAtEnd(message);
- emit messageReceived(message);
- }
+void ChatRoomModel::onMessageReceived(const std::shared_ptr & chatRoom, const std::shared_ptr & message){
+ setUnreadMessagesCount(chatRoom->getUnreadMessagesCount());
+ /*
+ insertMessageAtEnd(message);
+ emit messageReceived(message);*/
}
+void ChatRoomModel::onNewEvent(const std::shared_ptr & chatRoom, const std::shared_ptr & eventLog){
+ qWarning() << "New Event" <<(int) eventLog->getType();
+ if( eventLog->getType() == linphone::EventLog::Type::ConferenceCallEnd ){
+ setMissedCallsCount(mMissedCallsCount+1);
+ }
+ /*auto message = eventLog->getChatMessage();
+ if(message){
+ insertMessageAtEnd(message);
+ emit messageReceived(message);
+ }*/
+}
+void ChatRoomModel::onChatMessageReceived(const std::shared_ptr & chatRoom, const std::shared_ptr & eventLog) {
+
+ auto message = eventLog->getChatMessage();
+ if(message){
+ insertMessageAtEnd(message);
+ emit messageReceived(message);
+ setLastUpdateTime(QDateTime::fromMSecsSinceEpoch(chatRoom->getLastUpdateTime()));
+ }
+}
+void ChatRoomModel::onChatMessageSending(const std::shared_ptr & chatRoom, const std::shared_ptr & eventLog){
+ auto message = eventLog->getChatMessage();
+ if(message){
+ insertMessageAtEnd(message);
+ emit messageReceived(message);
+ setLastUpdateTime(QDateTime::fromMSecsSinceEpoch(chatRoom->getLastUpdateTime()));
+ }
+}
+void ChatRoomModel::onChatMessageSent(const std::shared_ptr & chatRoom, const std::shared_ptr & eventLog){
+ /*auto message = eventLog->getChatMessage();
+ if(message){
+ insertMessageAtEnd(message);
+ emit messageReceived(message);
+ }*/
+}
+void ChatRoomModel::onParticipantAdded(const std::shared_ptr & chatRoom, const std::shared_ptr & eventLog){}
+void ChatRoomModel::onParticipantRemoved(const std::shared_ptr & chatRoom, const std::shared_ptr & eventLog){}
+void ChatRoomModel::onParticipantAdminStatusChanged(const std::shared_ptr & chatRoom, const std::shared_ptr & eventLog){}
+void ChatRoomModel::onStateChanged(const std::shared_ptr & chatRoom, linphone::ChatRoom::State newState){}
+void ChatRoomModel::onSecurityEvent(const std::shared_ptr & chatRoom, const std::shared_ptr & eventLog){}
+void ChatRoomModel::onSubjectChanged(const std::shared_ptr & chatRoom, const std::shared_ptr & eventLog) {
+ emit subjectChanged(getSubject());
+ emit usernameChanged(getUsername());
+}
+void ChatRoomModel::onUndecryptableMessageReceived(const std::shared_ptr & chatRoom, const std::shared_ptr & message){}
+void ChatRoomModel::onParticipantDeviceAdded(const std::shared_ptr & chatRoom, const std::shared_ptr & eventLog){}
+void ChatRoomModel::onParticipantDeviceRemoved(const std::shared_ptr & chatRoom, const std::shared_ptr & eventLog){}
+void ChatRoomModel::onConferenceJoined(const std::shared_ptr & chatRoom, const std::shared_ptr & eventLog){}
+void ChatRoomModel::onConferenceLeft(const std::shared_ptr & chatRoom, const std::shared_ptr & eventLog){}
+void ChatRoomModel::onEphemeralEvent(const std::shared_ptr & chatRoom, const std::shared_ptr & eventLog){}
+void ChatRoomModel::onEphemeralMessageTimerStarted(const std::shared_ptr & chatRoom, const std::shared_ptr & eventLog){}
+void ChatRoomModel::onEphemeralMessageDeleted(const std::shared_ptr & chatRoom, const std::shared_ptr & eventLog){}
+void ChatRoomModel::onConferenceAddressGeneration(const std::shared_ptr & chatRoom){}
+void ChatRoomModel::onParticipantRegistrationSubscriptionRequested(const std::shared_ptr & chatRoom, const std::shared_ptr & participantAddress){}
+void ChatRoomModel::onParticipantRegistrationUnsubscriptionRequested(const std::shared_ptr & chatRoom, const std::shared_ptr & participantAddress){}
+void ChatRoomModel::onChatMessageShouldBeStored(const std::shared_ptr & chatRoom, const std::shared_ptr & message){}
+void ChatRoomModel::onChatMessageParticipantImdnStateChanged(const std::shared_ptr & chatRoom, const std::shared_ptr & message, const std::shared_ptr & state){}
diff --git a/linphone-app/src/components/chat-room/ChatRoomModel.hpp b/linphone-app/src/components/chat-room/ChatRoomModel.hpp
new file mode 100644
index 000000000..565e142a5
--- /dev/null
+++ b/linphone-app/src/components/chat-room/ChatRoomModel.hpp
@@ -0,0 +1,242 @@
+/*
+ * Copyright (c) 2010-2020 Belledonne Communications SARL.
+ *
+ * This file is part of linphone-desktop
+ * (see https://www.linphone.org).
+ *
+ * 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * 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 .
+ */
+
+#ifndef CHAT_ROOM_MODEL_H_
+#define CHAT_ROOM_MODEL_H_
+
+#include
+#include
+#include
+
+// =============================================================================
+// Fetch all N messages of a ChatRoom.
+// =============================================================================
+
+class CoreHandlers;
+class ParticipantModel;
+
+class ChatRoomModel : public QAbstractListModel, public linphone::ChatRoomListener {
+ class MessageHandlers;
+
+ Q_OBJECT;
+
+public:
+ enum Roles {
+ ChatEntry = Qt::DisplayRole,
+ SectionDate
+ };
+
+ enum EntryType {
+ GenericEntry,
+ MessageEntry,
+ CallEntry
+ };
+ Q_ENUM(EntryType);
+
+ enum CallStatus {
+ CallStatusDeclined = int(linphone::Call::Status::Declined),
+ CallStatusMissed = int(linphone::Call::Status::Missed),
+ CallStatusSuccess = int(linphone::Call::Status::Success),
+ CallStatusAborted = int(linphone::Call::Status::Aborted),
+ CallStatusEarlyAborted = int(linphone::Call::Status::EarlyAborted),
+ CallStatusAcceptedElsewhere = int(linphone::Call::Status::AcceptedElsewhere),
+ CallStatusDeclinedElsewhere = int(linphone::Call::Status::DeclinedElsewhere)
+ };
+ Q_ENUM(CallStatus);
+
+ enum MessageStatus {
+ MessageStatusDelivered = int(linphone::ChatMessage::State::Delivered),
+ MessageStatusDeliveredToUser = int(linphone::ChatMessage::State::DeliveredToUser),
+ MessageStatusDisplayed = int(linphone::ChatMessage::State::Displayed),
+ MessageStatusFileTransferDone = int(linphone::ChatMessage::State::FileTransferDone),
+ MessageStatusFileTransferError = int(linphone::ChatMessage::State::FileTransferError),
+ MessageStatusFileTransferInProgress = int(linphone::ChatMessage::State::FileTransferInProgress),
+ MessageStatusIdle = int(linphone::ChatMessage::State::Idle),
+ MessageStatusInProgress = int(linphone::ChatMessage::State::InProgress),
+ MessageStatusNotDelivered = int(linphone::ChatMessage::State::NotDelivered)
+
+ };
+ Q_ENUM(MessageStatus);
+
+ Q_PROPERTY(QString participants READ getParticipants NOTIFY participantsChanged);
+ Q_PROPERTY(QString subject READ getSubject NOTIFY subjectChanged)
+ Q_PROPERTY(QDateTime lastUpdateTime MEMBER mLastUpdateTime WRITE setLastUpdateTime NOTIFY lastUpdateTimeChanged)
+ Q_PROPERTY(int unreadMessagesCount MEMBER mUnreadMessagesCount WRITE setUnreadMessagesCount NOTIFY unreadMessagesCountChanged)
+ Q_PROPERTY(int missedCallsCount MEMBER mMissedCallsCount WRITE setMissedCallsCount NOTIFY missedCallsCountChanged)
+
+ Q_PROPERTY(bool isComposing MEMBER mIsRemoteComposing NOTIFY isRemoteComposingChanged)
+
+
+
+ Q_PROPERTY(QString sipAddress READ getFullPeerAddress NOTIFY fullPeerAddressChanged)
+ Q_PROPERTY(QString username READ getUsername NOTIFY usernameChanged)
+ Q_PROPERTY(QString avatar READ getAvatar NOTIFY avatarChanged)
+ Q_PROPERTY(int presenceStatus READ getPresenceStatus NOTIFY presenceStatusChanged)
+
+
+
+ //ChatRoomModel (const QString &peerAddress, const QString &localAddress, const bool& isSecure);
+ ChatRoomModel (std::shared_ptr chatRoom);
+ ~ChatRoomModel ();
+
+ int rowCount (const QModelIndex &index = QModelIndex()) const override;
+
+ QHash roleNames () const override;
+ QVariant data (const QModelIndex &index, int role) const override;
+
+ bool removeRow (int row, const QModelIndex &parent = QModelIndex());
+ bool removeRows (int row, int count, const QModelIndex &parent = QModelIndex()) override;
+
+ Q_INVOKABLE QString getPeerAddress () const;
+ Q_INVOKABLE QString getLocalAddress () const;
+ Q_INVOKABLE QString getFullPeerAddress () const;
+ Q_INVOKABLE QString getFullLocalAddress () const;
+
+ QString getSubject () const;
+ QString getUsername () const;
+ QString getAvatar () const;
+ int getPresenceStatus() const;
+ void setLastUpdateTime(const QDateTime& lastUpdateDate);
+
+ void setUnreadMessagesCount(const int& count);
+ void setMissedCallsCount(const int& count);
+
+ Q_INVOKABLE void leaveChatRoom ();
+
+ bool getIsSecure() const;
+
+ bool getIsRemoteComposing () const;
+
+
+ //Q_INVOKABLE QList getParticipants()const
+ Q_INVOKABLE QString getParticipants()const;
+
+
+ void removeEntry (int id);
+ void removeAllEntries ();
+
+ void sendMessage (const QString &message);
+
+ void resendMessage (int id);
+
+ void sendFileMessage (const QString &path);
+
+ void downloadFile (int id);
+ void openFile (int id, bool showDirectory = false);
+ void openFileDirectory (int id) {
+ openFile(id, true);
+ }
+
+ bool fileWasDownloaded (int id);
+
+ void compose ();
+
+ void resetMessageCount ();
+
+ std::shared_ptr getChatRoom();
+ QDateTime mLastUpdateTime;
+ int mUnreadMessagesCount;
+ int mMissedCallsCount;
+
+
+//-------------------- CHAT ROOM HANDLER
+
+
+ virtual void onIsComposingReceived(const std::shared_ptr & chatRoom, const std::shared_ptr & remoteAddress, bool isComposing) override;
+ virtual void onMessageReceived(const std::shared_ptr & chatRoom, const std::shared_ptr & message) override;
+ virtual void onNewEvent(const std::shared_ptr & chatRoom, const std::shared_ptr & eventLog) override;
+ virtual void onChatMessageReceived(const std::shared_ptr & chatRoom, const std::shared_ptr & eventLog) override;
+ virtual void onChatMessageSending(const std::shared_ptr & chatRoom, const std::shared_ptr & eventLog) override;
+ virtual void onChatMessageSent(const std::shared_ptr & chatRoom, const std::shared_ptr & eventLog) override;
+ virtual void onParticipantAdded(const std::shared_ptr & chatRoom, const std::shared_ptr & eventLog) override;
+ virtual void onParticipantRemoved(const std::shared_ptr & chatRoom, const std::shared_ptr & eventLog) override;
+ virtual void onParticipantAdminStatusChanged(const std::shared_ptr & chatRoom, const std::shared_ptr & eventLog) override;
+ virtual void onStateChanged(const std::shared_ptr & chatRoom, linphone::ChatRoom::State newState) override;
+ virtual void onSecurityEvent(const std::shared_ptr & chatRoom, const std::shared_ptr & eventLog) override;
+ virtual void onSubjectChanged(const std::shared_ptr & chatRoom, const std::shared_ptr & eventLog) override;
+ virtual void onUndecryptableMessageReceived(const std::shared_ptr & chatRoom, const std::shared_ptr & message) override;
+ virtual void onParticipantDeviceAdded(const std::shared_ptr & chatRoom, const std::shared_ptr & eventLog) override;
+ virtual void onParticipantDeviceRemoved(const std::shared_ptr & chatRoom, const std::shared_ptr & eventLog) override;
+ virtual void onConferenceJoined(const std::shared_ptr & chatRoom, const std::shared_ptr & eventLog) override;
+ virtual void onConferenceLeft(const std::shared_ptr & chatRoom, const std::shared_ptr & eventLog) override;
+ virtual void onEphemeralEvent(const std::shared_ptr & chatRoom, const std::shared_ptr & eventLog) override;
+ virtual void onEphemeralMessageTimerStarted(const std::shared_ptr & chatRoom, const std::shared_ptr & eventLog) override;
+ virtual void onEphemeralMessageDeleted(const std::shared_ptr & chatRoom, const std::shared_ptr & eventLog) override;
+ virtual void onConferenceAddressGeneration(const std::shared_ptr & chatRoom) override;
+ virtual void onParticipantRegistrationSubscriptionRequested(const std::shared_ptr & chatRoom, const std::shared_ptr & participantAddress) override;
+ virtual void onParticipantRegistrationUnsubscriptionRequested(const std::shared_ptr & chatRoom, const std::shared_ptr & participantAddress) override;
+ virtual void onChatMessageShouldBeStored(const std::shared_ptr & chatRoom, const std::shared_ptr & message) override;
+ virtual void onChatMessageParticipantImdnStateChanged(const std::shared_ptr & chatRoom, const std::shared_ptr & message, const std::shared_ptr & state) override;
+
+
+signals:
+ bool isRemoteComposingChanged (bool status);
+
+ void allEntriesRemoved ();
+ void lastEntryRemoved ();
+
+ void messageSent (const std::shared_ptr &message);
+ void messageReceived (const std::shared_ptr &message);
+
+ void messageCountReset ();
+
+ void focused ();
+
+ void fullPeerAddressChanged();
+ void participantsChanged();
+ void subjectChanged(QString subject);
+ void usernameChanged(QString username);
+ void avatarChanged(QString avatar);
+ void presenceStatusChanged(int presenceStatus);
+ void lastUpdateTimeChanged();
+ void unreadMessagesCountChanged();
+ void missedCallsCountChanged();
+
+private:
+ typedef QPair> ChatEntryData;
+
+ //void setSipAddresses (const QString &peerAddress, const QString &localAddress, const bool& isSecure);
+
+ const ChatEntryData getFileMessageEntry (int id);
+
+ void removeEntry (ChatEntryData &entry);
+
+ void insertCall (const std::shared_ptr &callLog);
+ void insertMessageAtEnd (const std::shared_ptr &message);
+
+ void handleCallStateChanged (const std::shared_ptr &call, linphone::Call::State state);
+ void handleCallCreated(const std::shared_ptr &call);// Count an event call
+ //void handleIsComposingChanged (const std::shared_ptr &chatRoom);
+ //void handleMessageReceived (const std::shared_ptr &message);
+
+ bool mIsRemoteComposing = false;
+
+ mutable QList mEntries;
+ QList mParticipants;
+
+ std::shared_ptr mCoreHandlers;
+ std::shared_ptr mMessageHandlers;
+
+ std::shared_ptr mChatRoom;
+};
+
+Q_DECLARE_METATYPE(std::shared_ptr);
+
+#endif // CHAT_ROOM_MODEL_H_
diff --git a/linphone-app/src/components/chat/ChatProxyModel.cpp b/linphone-app/src/components/chat-room/ChatRoomProxyModel.cpp
similarity index 51%
rename from linphone-app/src/components/chat/ChatProxyModel.cpp
rename to linphone-app/src/components/chat-room/ChatRoomProxyModel.cpp
index 2093873e5..0eadff228 100644
--- a/linphone-app/src/components/chat/ChatProxyModel.cpp
+++ b/linphone-app/src/components/chat-room/ChatRoomProxyModel.cpp
@@ -23,31 +23,31 @@
#include "app/App.hpp"
#include "components/core/CoreManager.hpp"
-#include "ChatProxyModel.hpp"
+#include "ChatRoomProxyModel.hpp"
// =============================================================================
using namespace std;
-QString ChatProxyModel::gCachedText;
+QString ChatRoomProxyModel::gCachedText;
// Fetch the L last filtered chat entries.
-class ChatProxyModel::ChatModelFilter : public QSortFilterProxyModel {
+class ChatRoomProxyModel::ChatRoomModelFilter : public QSortFilterProxyModel {
public:
- ChatModelFilter (QObject *parent) : QSortFilterProxyModel(parent) {}
+ ChatRoomModelFilter (QObject *parent) : QSortFilterProxyModel(parent) {}
- ChatModel::EntryType getEntryTypeFilter () {
+ ChatRoomModel::EntryType getEntryTypeFilter () {
return mEntryTypeFilter;
}
- void setEntryTypeFilter (ChatModel::EntryType type) {
+ void setEntryTypeFilter (ChatRoomModel::EntryType type) {
mEntryTypeFilter = type;
invalidate();
}
protected:
bool filterAcceptsRow (int sourceRow, const QModelIndex &) const override {
- if (mEntryTypeFilter == ChatModel::EntryType::GenericEntry)
+ if (mEntryTypeFilter == ChatRoomModel::EntryType::GenericEntry)
return true;
QModelIndex index = sourceModel()->index(sourceRow, 0, QModelIndex());
@@ -57,13 +57,13 @@ protected:
}
private:
- ChatModel::EntryType mEntryTypeFilter = ChatModel::EntryType::GenericEntry;
+ ChatRoomModel::EntryType mEntryTypeFilter = ChatRoomModel::EntryType::GenericEntry;
};
// =============================================================================
-ChatProxyModel::ChatProxyModel (QObject *parent) : QSortFilterProxyModel(parent) {
- setSourceModel(new ChatModelFilter(this));
+ChatRoomProxyModel::ChatRoomProxyModel (QObject *parent) : QSortFilterProxyModel(parent) {
+ setSourceModel(new ChatRoomModelFilter(this));
mIsSecure = false;
App *app = App::getInstance();
@@ -81,25 +81,25 @@ ChatProxyModel::ChatProxyModel (QObject *parent) : QSortFilterProxyModel(parent)
// -----------------------------------------------------------------------------
#define GET_CHAT_MODEL() \
- if (!mChatModel) \
+ if (!mChatRoomModel) \
return; \
- mChatModel
+ mChatRoomModel
#define CREATE_PARENT_MODEL_FUNCTION(METHOD) \
- void ChatProxyModel::METHOD () { \
+ void ChatRoomProxyModel::METHOD () { \
GET_CHAT_MODEL()->METHOD(); \
}
#define CREATE_PARENT_MODEL_FUNCTION_WITH_PARAM(METHOD, ARG_TYPE) \
- void ChatProxyModel::METHOD (ARG_TYPE value) { \
+ void ChatRoomProxyModel::METHOD (ARG_TYPE value) { \
GET_CHAT_MODEL()->METHOD(value); \
}
#define CREATE_PARENT_MODEL_FUNCTION_WITH_ID(METHOD) \
- void ChatProxyModel::METHOD (int id) { \
+ void ChatRoomProxyModel::METHOD (int id) { \
QModelIndex sourceIndex = mapToSource(index(id, 0)); \
GET_CHAT_MODEL()->METHOD( \
- static_cast(sourceModel())->mapToSource(sourceIndex).row() \
+ static_cast(sourceModel())->mapToSource(sourceIndex).row() \
); \
}
@@ -120,15 +120,15 @@ CREATE_PARENT_MODEL_FUNCTION_WITH_ID(resendMessage);
#undef CREATE_PARENT_MODEL_FUNCTION_WITH_ID
-void ChatProxyModel::compose (const QString& text) {
- if (mChatModel)
- mChatModel->compose();
+void ChatRoomProxyModel::compose (const QString& text) {
+ if (mChatRoomModel)
+ mChatRoomModel->compose();
gCachedText = text;
}
// -----------------------------------------------------------------------------
-void ChatProxyModel::loadMoreEntries () {
+void ChatRoomProxyModel::loadMoreEntries () {
int count = rowCount();
int parentCount = sourceModel()->rowCount();
@@ -146,116 +146,116 @@ void ChatProxyModel::loadMoreEntries () {
}
}
-void ChatProxyModel::setEntryTypeFilter (ChatModel::EntryType type) {
- ChatModelFilter *chatModelFilter = static_cast(sourceModel());
+void ChatRoomProxyModel::setEntryTypeFilter (ChatRoomModel::EntryType type) {
+ ChatRoomModelFilter *ChatRoomModelFilter = static_cast(sourceModel());
- if (chatModelFilter->getEntryTypeFilter() != type) {
- chatModelFilter->setEntryTypeFilter(type);
+ if (ChatRoomModelFilter->getEntryTypeFilter() != type) {
+ ChatRoomModelFilter->setEntryTypeFilter(type);
emit entryTypeFilterChanged(type);
}
}
// -----------------------------------------------------------------------------
-bool ChatProxyModel::filterAcceptsRow (int sourceRow, const QModelIndex &) const {
+bool ChatRoomProxyModel::filterAcceptsRow (int sourceRow, const QModelIndex &) const {
return sourceModel()->rowCount() - sourceRow <= mMaxDisplayedEntries;
}
// -----------------------------------------------------------------------------
-QString ChatProxyModel::getPeerAddress () const {
- return mChatModel ? mChatModel->getPeerAddress() : QString("");
+QString ChatRoomProxyModel::getPeerAddress () const {
+ return mChatRoomModel ? mChatRoomModel->getPeerAddress() : QString("");
}
-void ChatProxyModel::setPeerAddress (const QString &peerAddress) {
+void ChatRoomProxyModel::setPeerAddress (const QString &peerAddress) {
mPeerAddress = peerAddress;
//reload();
}
-QString ChatProxyModel::getLocalAddress () const {
- return mChatModel ? mChatModel->getLocalAddress() : QString("");
+QString ChatRoomProxyModel::getLocalAddress () const {
+ return mChatRoomModel ? mChatRoomModel->getLocalAddress() : QString("");
}
-void ChatProxyModel::setLocalAddress (const QString &localAddress) {
+void ChatRoomProxyModel::setLocalAddress (const QString &localAddress) {
mLocalAddress = localAddress;
//reload();
}
-QString ChatProxyModel::getFullPeerAddress () const {
- return mChatModel ? mChatModel->getFullPeerAddress() : QString("");
+QString ChatRoomProxyModel::getFullPeerAddress () const {
+ return mChatRoomModel ? mChatRoomModel->getFullPeerAddress() : QString("");
}
-void ChatProxyModel::setFullPeerAddress (const QString &peerAddress) {
+void ChatRoomProxyModel::setFullPeerAddress (const QString &peerAddress) {
mFullPeerAddress = peerAddress;
//reload();
}
-QString ChatProxyModel::getFullLocalAddress () const {
- return mChatModel ? mChatModel->getFullLocalAddress() : QString("");
+QString ChatRoomProxyModel::getFullLocalAddress () const {
+ return mChatRoomModel ? mChatRoomModel->getFullLocalAddress() : QString("");
}
-void ChatProxyModel::setFullLocalAddress (const QString &localAddress) {
+void ChatRoomProxyModel::setFullLocalAddress (const QString &localAddress) {
mFullLocalAddress = localAddress;
//reload();
}
-int ChatProxyModel::getIsSecure () const {
- return mChatModel ? mChatModel->getIsSecure() : -1;
+int ChatRoomProxyModel::getIsSecure () const {
+ return mChatRoomModel ? mChatRoomModel->getIsSecure() : -1;
}
-void ChatProxyModel::setIsSecure (const int &secure) {
+void ChatRoomProxyModel::setIsSecure (const int &secure) {
mIsSecure = secure;
}
-bool ChatProxyModel::getIsRemoteComposing () const {
- return mChatModel ? mChatModel->getIsRemoteComposing() : false;
+bool ChatRoomProxyModel::getIsRemoteComposing () const {
+ return mChatRoomModel ? mChatRoomModel->getIsRemoteComposing() : false;
}
-QString ChatProxyModel::getCachedText() const{
+QString ChatRoomProxyModel::getCachedText() const{
return gCachedText;
}
// -----------------------------------------------------------------------------
-void ChatProxyModel::reload () {
+void ChatRoomProxyModel::reload () {
mMaxDisplayedEntries = EntriesChunkSize;
- if (mChatModel) {
- ChatModel *chatModel = mChatModel.get();
- QObject::disconnect(chatModel, &ChatModel::isRemoteComposingChanged, this, &ChatProxyModel::handleIsRemoteComposingChanged);
- QObject::disconnect(chatModel, &ChatModel::messageReceived, this, &ChatProxyModel::handleMessageReceived);
- QObject::disconnect(chatModel, &ChatModel::messageSent, this, &ChatProxyModel::handleMessageSent);
+ if (mChatRoomModel) {
+ ChatRoomModel *ChatRoomModel = mChatRoomModel.get();
+ QObject::disconnect(ChatRoomModel, &ChatRoomModel::isRemoteComposingChanged, this, &ChatRoomProxyModel::handleIsRemoteComposingChanged);
+ QObject::disconnect(ChatRoomModel, &ChatRoomModel::messageReceived, this, &ChatRoomProxyModel::handleMessageReceived);
+ QObject::disconnect(ChatRoomModel, &ChatRoomModel::messageSent, this, &ChatRoomProxyModel::handleMessageSent);
}
- //mChatModel = CoreManager::getInstance()->getChatModel(mPeerAddress, mLocalAddress, mIsSecure);
+ //mChatRoomModel = CoreManager::getInstance()->getChatRoomModel(mPeerAddress, mLocalAddress, mIsSecure);
//if(mChatRoom)
- mChatModel = CoreManager::getInstance()->getChatModel(mChatRoom);
+ mChatRoomModel = CoreManager::getInstance()->getChatRoomModel(mChatRoom);
- if (mChatModel) {
+ if (mChatRoomModel) {
- ChatModel *chatModel = mChatModel.get();
- QObject::connect(chatModel, &ChatModel::isRemoteComposingChanged, this, &ChatProxyModel::handleIsRemoteComposingChanged);
- QObject::connect(chatModel, &ChatModel::messageReceived, this, &ChatProxyModel::handleMessageReceived);
- QObject::connect(chatModel, &ChatModel::messageSent, this, &ChatProxyModel::handleMessageSent);
+ ChatRoomModel *ChatRoomModel = mChatRoomModel.get();
+ QObject::connect(ChatRoomModel, &ChatRoomModel::isRemoteComposingChanged, this, &ChatRoomProxyModel::handleIsRemoteComposingChanged);
+ QObject::connect(ChatRoomModel, &ChatRoomModel::messageReceived, this, &ChatRoomProxyModel::handleMessageReceived);
+ QObject::connect(ChatRoomModel, &ChatRoomModel::messageSent, this, &ChatRoomProxyModel::handleMessageSent);
}
- static_cast(sourceModel())->setSourceModel(mChatModel.get());
+ static_cast(sourceModel())->setSourceModel(mChatRoomModel.get());
}
-void ChatProxyModel::resetMessageCount(){
- if( mChatModel){
- mChatModel->resetMessageCount();
+void ChatRoomProxyModel::resetMessageCount(){
+ if( mChatRoomModel){
+ mChatRoomModel->resetMessageCount();
}
}
-std::shared_ptr ChatProxyModel::getChatModel () const{
- return mChatModel;
+ChatRoomModel *ChatRoomProxyModel::getChatRoomModel () const{
+ return mChatRoomModel.get();
}
-void ChatProxyModel::setChatModel (std::shared_ptr chatModel){
- mChatRoom = chatModel->getChatRoom();
+void ChatRoomProxyModel::setChatRoomModel (ChatRoomModel *ChatRoomModel){
+ mChatRoom = ChatRoomModel->getChatRoom();
reload();
- emit chatModelChanged();
+ emit chatRoomModelChanged();
}
// -----------------------------------------------------------------------------
@@ -269,25 +269,25 @@ static inline QWindow *getParentWindow (QObject *object) {
return nullptr;
}
-void ChatProxyModel::handleIsActiveChanged (QWindow *window) {
- if (mChatModel && window->isActive() && getParentWindow(this) == window) {
- mChatModel->resetMessageCount();
- mChatModel->focused();
+void ChatRoomProxyModel::handleIsActiveChanged (QWindow *window) {
+ if (mChatRoomModel && window->isActive() && getParentWindow(this) == window) {
+ mChatRoomModel->resetMessageCount();
+ mChatRoomModel->focused();
}
}
-void ChatProxyModel::handleIsRemoteComposingChanged (bool status) {
+void ChatRoomProxyModel::handleIsRemoteComposingChanged (bool status) {
emit isRemoteComposingChanged(status);
}
-void ChatProxyModel::handleMessageReceived (const shared_ptr &) {
+void ChatRoomProxyModel::handleMessageReceived (const shared_ptr &) {
mMaxDisplayedEntries++;
QWindow *window = getParentWindow(this);
if (window && window->isActive())
- mChatModel->resetMessageCount();
+ mChatRoomModel->resetMessageCount();
}
-void ChatProxyModel::handleMessageSent (const shared_ptr &) {
+void ChatRoomProxyModel::handleMessageSent (const shared_ptr &) {
mMaxDisplayedEntries++;
}
diff --git a/linphone-app/src/components/chat/ChatProxyModel.hpp b/linphone-app/src/components/chat-room/ChatRoomProxyModel.hpp
similarity index 84%
rename from linphone-app/src/components/chat/ChatProxyModel.hpp
rename to linphone-app/src/components/chat-room/ChatRoomProxyModel.hpp
index c3c50bd82..f0e604bb8 100644
--- a/linphone-app/src/components/chat/ChatProxyModel.hpp
+++ b/linphone-app/src/components/chat-room/ChatRoomProxyModel.hpp
@@ -18,19 +18,19 @@
* along with this program. If not, see .
*/
-#ifndef CHAT_PROXY_MODEL_H_
-#define CHAT_PROXY_MODEL_H_
+#ifndef CHAT_ROOM_PROXY_MODEL_H_
+#define CHAT_ROOM_PROXY_MODEL_H_
#include
-#include "ChatModel.hpp"
+#include "ChatRoomModel.hpp"
// =============================================================================
class QWindow;
-class ChatProxyModel : public QSortFilterProxyModel {
- class ChatModelFilter;
+class ChatRoomProxyModel : public QSortFilterProxyModel {
+ class ChatRoomModelFilter;
Q_OBJECT;
@@ -39,17 +39,17 @@ class ChatProxyModel : public QSortFilterProxyModel {
Q_PROPERTY(QString fullPeerAddress READ getFullPeerAddress WRITE setFullPeerAddress NOTIFY fullPeerAddressChanged);
Q_PROPERTY(QString fullLocalAddress READ getFullLocalAddress WRITE setFullLocalAddress NOTIFY fullLocalAddressChanged);
Q_PROPERTY(int isSecure READ getIsSecure WRITE setIsSecure NOTIFY isSecureChanged);
- Q_PROPERTY(std::shared_ptr chatModel READ getChatModel WRITE setChatModel NOTIFY chatModelChanged);
+ Q_PROPERTY(ChatRoomModel *chatRoomModel READ getChatRoomModel WRITE setChatRoomModel NOTIFY chatRoomModelChanged);
//Q_PROPERTY(bool isSecure MEMBER mIsSecure NOTIFY isSecureChanged);
Q_PROPERTY(bool isRemoteComposing READ getIsRemoteComposing NOTIFY isRemoteComposingChanged);
//Q_PROPERTY(bool isSecure READ getIsSecure NOTIFY isSecureChanged);
Q_PROPERTY(QString cachedText READ getCachedText);
public:
- ChatProxyModel (QObject *parent = Q_NULLPTR);
+ ChatRoomProxyModel (QObject *parent = Q_NULLPTR);
Q_INVOKABLE void loadMoreEntries ();
- Q_INVOKABLE void setEntryTypeFilter (ChatModel::EntryType type);
+ Q_INVOKABLE void setEntryTypeFilter (ChatRoomModel::EntryType type);
Q_INVOKABLE void removeEntry (int id);
Q_INVOKABLE void removeAllEntries ();
@@ -75,11 +75,11 @@ signals:
bool isRemoteComposingChanged (bool status);
bool isSecureChanged(bool secure);
- void chatModelChanged();
+ void chatRoomModelChanged();
void moreEntriesLoaded (int n);
- void entryTypeFilterChanged (ChatModel::EntryType type);
+ void entryTypeFilterChanged (ChatRoomModel::EntryType type);
protected:
bool filterAcceptsRow (int sourceRow, const QModelIndex &sourceParent) const override;
@@ -100,8 +100,8 @@ private:
int getIsSecure () const;
void setIsSecure (const int &secure);
- std::shared_ptr getChatModel() const;
- void setChatModel (std::shared_ptr chatModel);
+ ChatRoomModel *getChatRoomModel() const;
+ void setChatRoomModel (ChatRoomModel *chatRoomModel);
bool getIsRemoteComposing () const;
@@ -126,9 +126,9 @@ private:
std::shared_ptr mChatRoom;
- std::shared_ptr mChatModel;
+ std::shared_ptr mChatRoomModel;
static constexpr int EntriesChunkSize = 50;
};
-#endif // CHAT_PROXY_MODEL_H_
+#endif // CHAT_ROOM_PROXY_MODEL_H_
diff --git a/linphone-app/src/components/chat/ChatModel.hpp b/linphone-app/src/components/chat/ChatModel.hpp
deleted file mode 100644
index 4002ece96..000000000
--- a/linphone-app/src/components/chat/ChatModel.hpp
+++ /dev/null
@@ -1,161 +0,0 @@
-/*
- * Copyright (c) 2010-2020 Belledonne Communications SARL.
- *
- * This file is part of linphone-desktop
- * (see https://www.linphone.org).
- *
- * 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 3 of the License, or
- * (at your option) any later version.
- *
- * 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 .
- */
-
-#ifndef CHAT_MODEL_H_
-#define CHAT_MODEL_H_
-
-#include
-#include
-
-// =============================================================================
-// Fetch all N messages of a ChatRoom.
-// =============================================================================
-
-class CoreHandlers;
-
-class ChatModel : public QAbstractListModel {
- class MessageHandlers;
-
- Q_OBJECT;
-
-public:
- enum Roles {
- ChatEntry = Qt::DisplayRole,
- SectionDate
- };
-
- enum EntryType {
- GenericEntry,
- MessageEntry,
- CallEntry
- };
- Q_ENUM(EntryType);
-
- enum CallStatus {
- CallStatusDeclined = int(linphone::Call::Status::Declined),
- CallStatusMissed = int(linphone::Call::Status::Missed),
- CallStatusSuccess = int(linphone::Call::Status::Success),
- CallStatusAborted = int(linphone::Call::Status::Aborted),
- CallStatusEarlyAborted = int(linphone::Call::Status::EarlyAborted),
- CallStatusAcceptedElsewhere = int(linphone::Call::Status::AcceptedElsewhere),
- CallStatusDeclinedElsewhere = int(linphone::Call::Status::DeclinedElsewhere)
- };
- Q_ENUM(CallStatus);
-
- enum MessageStatus {
- MessageStatusDelivered = int(linphone::ChatMessage::State::Delivered),
- MessageStatusDeliveredToUser = int(linphone::ChatMessage::State::DeliveredToUser),
- MessageStatusDisplayed = int(linphone::ChatMessage::State::Displayed),
- MessageStatusFileTransferDone = int(linphone::ChatMessage::State::FileTransferDone),
- MessageStatusFileTransferError = int(linphone::ChatMessage::State::FileTransferError),
- MessageStatusFileTransferInProgress = int(linphone::ChatMessage::State::FileTransferInProgress),
- MessageStatusIdle = int(linphone::ChatMessage::State::Idle),
- MessageStatusInProgress = int(linphone::ChatMessage::State::InProgress),
- MessageStatusNotDelivered = int(linphone::ChatMessage::State::NotDelivered)
-
- };
- Q_ENUM(MessageStatus);
-
- ChatModel (const QString &peerAddress, const QString &localAddress, const bool& isSecure);
- ChatModel (std::shared_ptr chatRoom);
- ~ChatModel ();
-
- int rowCount (const QModelIndex &index = QModelIndex()) const override;
-
- QHash roleNames () const override;
- QVariant data (const QModelIndex &index, int role) const override;
-
- bool removeRow (int row, const QModelIndex &parent = QModelIndex());
- bool removeRows (int row, int count, const QModelIndex &parent = QModelIndex()) override;
-
- QString getPeerAddress () const;
- QString getLocalAddress () const;
- QString getFullPeerAddress () const;
- QString getFullLocalAddress () const;
-
- bool getIsSecure() const;
-
- bool getIsRemoteComposing () const;
-
- void removeEntry (int id);
- void removeAllEntries ();
-
- void sendMessage (const QString &message);
-
- void resendMessage (int id);
-
- void sendFileMessage (const QString &path);
-
- void downloadFile (int id);
- void openFile (int id, bool showDirectory = false);
- void openFileDirectory (int id) {
- openFile(id, true);
- }
-
- bool fileWasDownloaded (int id);
-
- void compose ();
-
- void resetMessageCount ();
-
- std::shared_ptr getChatRoom();
-
-signals:
- bool isRemoteComposingChanged (bool status);
-
- void allEntriesRemoved ();
- void lastEntryRemoved ();
-
- void messageSent (const std::shared_ptr &message);
- void messageReceived (const std::shared_ptr &message);
-
- void messageCountReset ();
-
- void focused ();
-
-private:
- typedef QPair> ChatEntryData;
-
- void setSipAddresses (const QString &peerAddress, const QString &localAddress, const bool& isSecure);
-
- const ChatEntryData getFileMessageEntry (int id);
-
- void removeEntry (ChatEntryData &entry);
-
- void insertCall (const std::shared_ptr &callLog);
- void insertMessageAtEnd (const std::shared_ptr &message);
-
- void handleCallStateChanged (const std::shared_ptr &call, linphone::Call::State state);
- void handleIsComposingChanged (const std::shared_ptr &chatRoom);
- void handleMessageReceived (const std::shared_ptr &message);
-
- bool mIsRemoteComposing = false;
-
- mutable QList mEntries;
-
- std::shared_ptr mCoreHandlers;
- std::shared_ptr mMessageHandlers;
-
- std::shared_ptr mChatRoom;
-};
-
-Q_DECLARE_METATYPE(std::shared_ptr