From 13e677b4b217b1bd6f615f8030320a5a6448625e Mon Sep 17 00:00:00 2001 From: Julien Wadel Date: Tue, 17 Aug 2021 16:18:06 +0200 Subject: [PATCH] Upgrade data synchronization on chat room managment Fix synchro between smartsearchbar and participant list Fix showing avatar on first message burst Fix SDK missusing on addresses Fix Popup Menu location --- .../components/chat-room/ChatRoomModel.cpp | 12 ++------ .../participant/ParticipantListModel.cpp | 5 +++- .../participant/ParticipantListModel.hpp | 3 ++ .../participant/ParticipantProxyModel.cpp | 29 +++++++++++-------- .../participant/ParticipantProxyModel.hpp | 2 ++ linphone-app/ui/modules/Common/Menus/Menu.qml | 2 +- .../ui/modules/Linphone/Chat/Chat.qml | 9 +++--- .../modules/Linphone/Chat/IncomingMessage.qml | 19 +++++------- .../ui/modules/Linphone/Contact/Contact.qml | 3 +- .../Linphone/Contact/ContactDescription.qml | 4 ++- .../ui/views/App/Main/Conversation.qml | 13 +++++++-- .../views/App/Main/Dialogs/InfoChatRoom.qml | 5 ++-- .../ui/views/App/Main/MainWindowMenuBar.qml | 10 ++++--- 13 files changed, 66 insertions(+), 50 deletions(-) diff --git a/linphone-app/src/components/chat-room/ChatRoomModel.cpp b/linphone-app/src/components/chat-room/ChatRoomModel.cpp index 952b8ccb9..966b5d53c 100644 --- a/linphone-app/src/components/chat-room/ChatRoomModel.cpp +++ b/linphone-app/src/components/chat-room/ChatRoomModel.cpp @@ -347,10 +347,7 @@ void ChatRoomModel::removeEntry(ChatEvent* entry){ //-------------------------------------------------------------------------------------------- QString ChatRoomModel::getPeerAddress () const { - if(haveEncryption() || isGroupEnabled()){ - return getParticipants()->addressesToString(); - }else - return mChatRoom ? Utils::coreStringToAppString(mChatRoom->getPeerAddress()->asStringUriOnly()) : ""; + return mChatRoom ? Utils::coreStringToAppString(mChatRoom->getPeerAddress()->asStringUriOnly()) : ""; } QString ChatRoomModel::getLocalAddress () const { @@ -367,10 +364,7 @@ QString ChatRoomModel::getLocalAddress () const { } QString ChatRoomModel::getFullPeerAddress () const { - if(haveEncryption() || isGroupEnabled()){ - return getParticipants()->addressesToString(); - }else - return mChatRoom ? Utils::coreStringToAppString(mChatRoom->getPeerAddress()->asString()) : ""; + return mChatRoom ? Utils::coreStringToAppString(mChatRoom->getPeerAddress()->asString()) : ""; } QString ChatRoomModel::getFullLocalAddress () const { @@ -674,7 +668,7 @@ public: QList::iterator itEntries = entries.begin(); int spotted = 0; auto lastEntry = itEntries; - while(itEntries != entries.end() && (spotted != 7 || (entries.end()-itEntries > minEntries)) ) { + while(itEntries != entries.end() && (spotted != 7 && (entries.end()-itEntries > minEntries)) ) { if( itEntries->mType == ChatRoomModel::EntryType::MessageEntry) { if( (spotted & 1) == 0) { lastEntry = itEntries; diff --git a/linphone-app/src/components/participant/ParticipantListModel.cpp b/linphone-app/src/components/participant/ParticipantListModel.cpp index 55af6e42c..7e6aa8aa1 100644 --- a/linphone-app/src/components/participant/ParticipantListModel.cpp +++ b/linphone-app/src/components/participant/ParticipantListModel.cpp @@ -218,6 +218,7 @@ void ParticipantListModel::updateParticipants () { changed = true; }else if(!(*itParticipant)->getParticipant()){ (*itParticipant)->setParticipant(dbParticipant); + changed = true; } } if( changed){ @@ -229,10 +230,12 @@ void ParticipantListModel::updateParticipants () { void ParticipantListModel::add (std::shared_ptr participant){ int row = mParticipants.count(); + connect(this, &ParticipantListModel::deviceSecurityLevelChanged, participant.get(), &ParticipantModel::onDeviceSecurityLevelChanged); + connect(this, &ParticipantListModel::securityLevelChanged, participant.get(), &ParticipantModel::onSecurityLevelChanged); + connect(participant.get(),&ParticipantModel::updateAdminStatus, this, &ParticipantListModel::setAdminStatus); beginInsertRows(QModelIndex(), row, row); mParticipants << participant; endInsertRows(); - resetInternalData(); emit participantsChanged(); emit countChanged(); } diff --git a/linphone-app/src/components/participant/ParticipantListModel.hpp b/linphone-app/src/components/participant/ParticipantListModel.hpp index cf1b68770..ce438d42e 100644 --- a/linphone-app/src/components/participant/ParticipantListModel.hpp +++ b/linphone-app/src/components/participant/ParticipantListModel.hpp @@ -35,6 +35,9 @@ public: Q_PROPERTY(ChatRoomModel* chatRoomModel READ getChatRoomModel CONSTANT) Q_PROPERTY(int count READ getCount NOTIFY countChanged) + Q_PROPERTY(QString addressesToString READ addressesToString NOTIFY participantsChanged) + Q_PROPERTY(QString displayNamesToString READ displayNamesToString NOTIFY participantsChanged) + Q_PROPERTY(QString usernamesToString READ usernamesToString NOTIFY participantsChanged) void reset(); void update(); diff --git a/linphone-app/src/components/participant/ParticipantProxyModel.cpp b/linphone-app/src/components/participant/ParticipantProxyModel.cpp index 898b11983..e75d1b3e4 100644 --- a/linphone-app/src/components/participant/ParticipantProxyModel.cpp +++ b/linphone-app/src/components/participant/ParticipantProxyModel.cpp @@ -49,7 +49,7 @@ QStringList ParticipantProxyModel::getSipAddresses() const{ QStringList participants; ParticipantListModel * list = dynamic_cast(sourceModel()); for(int i = 0 ; i < list->rowCount() ; ++i) - participants << list->getAt(i)->getSipAddress(); + participants << list->getAt(i)->getSipAddress(); return participants; } @@ -57,7 +57,7 @@ QVariantList ParticipantProxyModel::getParticipants() const{ QVariantList participants; ParticipantListModel * list = dynamic_cast(sourceModel()); for(int i = 0 ; i < list->rowCount() ; ++i) - participants << QVariant::fromValue(list->getAt(i)); + participants << QVariant::fromValue(list->getAt(i)); return participants; } @@ -70,9 +70,12 @@ int ParticipantProxyModel::getCount() const{ void ParticipantProxyModel::setChatRoomModel(ChatRoomModel * chatRoomModel){ if(!mChatRoomModel || mChatRoomModel != chatRoomModel){ mChatRoomModel = chatRoomModel; - if(mChatRoomModel) - setSourceModel(mChatRoomModel->getParticipants()); - else { + if(mChatRoomModel) { + auto participants = mChatRoomModel->getParticipants(); + setSourceModel(participants); + for(int i = 0 ; i < participants->getCount() ; ++i) + emit addressAdded(participants->getAt(i)->getSipAddress()); + }else { setSourceModel(new ParticipantListModel(nullptr, this)); } sort(0); @@ -83,12 +86,13 @@ void ParticipantProxyModel::setChatRoomModel(ChatRoomModel * chatRoomModel){ void ParticipantProxyModel::add(const QString& address){ ParticipantListModel * participantsModel = dynamic_cast(sourceModel()); if(!participantsModel->contains(address)){ - std::shared_ptr participant = std::make_shared(nullptr); + std::shared_ptr participant = std::make_shared(nullptr); participant->setSipAddress(address); participantsModel->add(participant); if(mChatRoomModel && mChatRoomModel->getChatRoom())// Invite and wait for its creation mChatRoomModel->getChatRoom()->addParticipant(Utils::interpretUrl(address)); emit countChanged(); + emit addressAdded(address); } } @@ -101,19 +105,20 @@ void ParticipantProxyModel::remove(ParticipantModel * participant){ mChatRoomModel->getChatRoom()->removeParticipant(participant->getParticipant()); //dynamic_cast(sourceModel())->remove(participant); emit countChanged(); + emit addressRemoved(participant->getSipAddress()); } } // ----------------------------------------------------------------------------- bool ParticipantProxyModel::filterAcceptsRow (int sourceRow, const QModelIndex &sourceParent) const { - //const QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent); - return true; + //const QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent); + return true; } bool ParticipantProxyModel::lessThan (const QModelIndex &left, const QModelIndex &right) const { - const ParticipantModel* a = sourceModel()->data(left).value(); - const ParticipantModel* b = sourceModel()->data(right).value(); - - return a->getCreationTime() >= b->getCreationTime(); + const ParticipantModel* a = sourceModel()->data(left).value(); + const ParticipantModel* b = sourceModel()->data(right).value(); + + return a->getCreationTime() >= b->getCreationTime(); } diff --git a/linphone-app/src/components/participant/ParticipantProxyModel.hpp b/linphone-app/src/components/participant/ParticipantProxyModel.hpp index 53cfa15f4..37da1017e 100644 --- a/linphone-app/src/components/participant/ParticipantProxyModel.hpp +++ b/linphone-app/src/components/participant/ParticipantProxyModel.hpp @@ -60,6 +60,8 @@ public: signals: void chatRoomModelChanged(); void countChanged(); + void addressAdded(QString sipAddress); + void addressRemoved(QString sipAddress); private: /* diff --git a/linphone-app/ui/modules/Common/Menus/Menu.qml b/linphone-app/ui/modules/Common/Menus/Menu.qml index dae3d5379..b06ea282f 100644 --- a/linphone-app/ui/modules/Common/Menus/Menu.qml +++ b/linphone-app/ui/modules/Common/Menus/Menu.qml @@ -1,5 +1,5 @@ import QtQuick 2.7 -import QtQuick.Controls 2.2 as Controls +import QtQuick.Controls 2.3 as Controls import Common 1.0 import Common.Styles 1.0 diff --git a/linphone-app/ui/modules/Linphone/Chat/Chat.qml b/linphone-app/ui/modules/Linphone/Chat/Chat.qml index 8fccbda96..0819e75e1 100644 --- a/linphone-app/ui/modules/Linphone/Chat/Chat.qml +++ b/linphone-app/ui/modules/Linphone/Chat/Chat.qml @@ -177,10 +177,11 @@ Rectangle { font.pointSize: ChatStyle.entry.time.pointSize visible: isMessage && $chatEntry != undefined - && !$chatEntry.isOutgoing - && (!previousItem - || previousItem.fromSipAddress != $chatEntry.fromSipAddress - || (new Date(previousItem.timestamp)).setHours(0, 0, 0, 0) != (new Date($chatEntry.timestamp)).setHours(0, 0, 0, 0) + && !$chatEntry.isOutgoing // Only outgoing + && (!previousItem //No previous entry + || previousItem.type != ChatRoomModel.MessageEntry // Previous entry is a message + || previousItem.fromSipAddress != $chatEntry.fromSipAddress // Different user + || (new Date(previousItem.timestamp)).setHours(0, 0, 0, 0) != (new Date($chatEntry.timestamp)).setHours(0, 0, 0, 0) // Same day == section ) } RowLayout { diff --git a/linphone-app/ui/modules/Linphone/Chat/IncomingMessage.qml b/linphone-app/ui/modules/Linphone/Chat/IncomingMessage.qml index cdbbd56e2..055d658aa 100644 --- a/linphone-app/ui/modules/Linphone/Chat/IncomingMessage.qml +++ b/linphone-app/ui/modules/Linphone/Chat/IncomingMessage.qml @@ -32,18 +32,13 @@ RowLayout { if (index <= 0) { return true // 1. First message, so visible. } - - var previousEntry = proxyModel.data(proxyModel.index(index - 1, 0)) - if (!previousEntry) { - return true - } - - // 2. Previous entry is a call event. => Visible. - // 3. I have sent a message before my contact. => Visible. - // 4. One hour between two incoming messages. => Visible. - return previousEntry.type !== ChatRoomModel.MessageEntry || - previousEntry.isOutgoing || - $chatEntry.timestamp.getTime() - previousEntry.timestamp.getTime() > 3600 + var previousEntry = proxyModel.getAt(index - 1) + return !$chatEntry.isOutgoing && (// Only outgoing + !previousEntry //No previous entry + || previousEntry.type != ChatRoomModel.MessageEntry // Previous entry is a message + || previousEntry.fromSipAddress != $chatEntry.fromSipAddress // Different user + || (new Date(previousEntry.timestamp)).setHours(0, 0, 0, 0) != (new Date($chatEntry.timestamp)).setHours(0, 0, 0, 0) // Same day == section + ) } TooltipArea{ delay:0 diff --git a/linphone-app/ui/modules/Linphone/Contact/Contact.qml b/linphone-app/ui/modules/Linphone/Contact/Contact.qml index 04c3e2fee..acd818be2 100644 --- a/linphone-app/ui/modules/Linphone/Contact/Contact.qml +++ b/linphone-app/ui/modules/Linphone/Contact/Contact.qml @@ -109,9 +109,10 @@ Rectangle { ? (entry.groupEnabled != undefined && entry.groupEnabled ? '' : (entry.haveEncryption != undefined && entry.haveEncryption - ? entry.participants.addressesToString() + ? '' : entry.sipAddress || entry.fullPeerAddress || entry.peerAddress || '')) : '') + participants: entry && showContactAddress && entry.groupEnabled != undefined && !entry.groupEnabled && entry.haveEncryption != undefined && entry.haveEncryption ? entry.participants.addressesToString : '' /* sipAddress: (entry && showContactAddress? diff --git a/linphone-app/ui/modules/Linphone/Contact/ContactDescription.qml b/linphone-app/ui/modules/Linphone/Contact/ContactDescription.qml index ba9882fe8..a2127070a 100644 --- a/linphone-app/ui/modules/Linphone/Contact/ContactDescription.qml +++ b/linphone-app/ui/modules/Linphone/Contact/ContactDescription.qml @@ -10,6 +10,8 @@ Column { id:mainItem property alias username: username.text property string sipAddress + property string participants + property alias statusText : status.text property var contactDescriptionStyle : ContactDescriptionStyle @@ -67,7 +69,7 @@ Column { Text { id:address anchors.horizontalCenter: (horizontalTextAlignment == Text.AlignHCenter ? parent.horizontalCenter : undefined) - text: SipAddressesModel.cleanSipAddress(sipAddress) + text: sipAddress?SipAddressesModel.cleanSipAddress(sipAddress):participants color: sipAddressColor elide: Text.ElideRight font.weight: contactDescriptionStyle.sipAddress.weight diff --git a/linphone-app/ui/views/App/Main/Conversation.qml b/linphone-app/ui/views/App/Main/Conversation.qml index 8162330dd..35d760c58 100644 --- a/linphone-app/ui/views/App/Main/Conversation.qml +++ b/linphone-app/ui/views/App/Main/Conversation.qml @@ -132,12 +132,21 @@ ColumnLayout { contactDescriptionStyle: ConversationStyle.bar.contactDescription username: avatar.username usernameClickable: chatRoomModel.isMeAdmin + participants: if(chatRoomModel) { + if(chatRoomModel.groupEnabled) { + return chatRoomModel.participants.displayNamesToString; + }else if(chatRoomModel.isSecure()) { + return chatRoomModel.participants.addressesToString; + }else + return '' + }else + return '' sipAddress: { if(chatRoomModel) { if(chatRoomModel.groupEnabled) { - return chatRoomModel.participants.displayNamesToString(); + return ''; }else if(chatRoomModel.isSecure()) { - return chatRoomModel.participants.addressesToString(); + return ''; }else { return chatRoomModel.sipAddress; } diff --git a/linphone-app/ui/views/App/Main/Dialogs/InfoChatRoom.qml b/linphone-app/ui/views/App/Main/Dialogs/InfoChatRoom.qml index 4e1e4f396..73e6be17d 100644 --- a/linphone-app/ui/views/App/Main/Dialogs/InfoChatRoom.qml +++ b/linphone-app/ui/views/App/Main/Dialogs/InfoChatRoom.qml @@ -88,13 +88,11 @@ DialogPlus { secure:0, handler: function (entry) { selectedParticipants.add(entry.sipAddress) - smartSearchBar.addAddressToIgnore(entry.sipAddress); }, }] onEntryClicked: { selectedParticipants.add(entry) - smartSearchBar.addAddressToIgnore(entry); } } @@ -153,7 +151,6 @@ DialogPlus { icon: 'remove_participant', tooltipText: 'Remove this participant from the selection', handler: function (entry) { - smartSearchBar.removeAddressToIgnore(entry.sipAddress) selectedParticipants.remove(entry) // ++lastContacts.reloadCount } @@ -165,6 +162,8 @@ DialogPlus { model: ParticipantProxyModel { id:selectedParticipants chatRoomModel:dialog.chatRoomModel + onAddressAdded: smartSearchBar.addAddressToIgnore(sipAddress) + onAddressRemoved: smartSearchBar.removeAddressToIgnore(sipAddress) } diff --git a/linphone-app/ui/views/App/Main/MainWindowMenuBar.qml b/linphone-app/ui/views/App/Main/MainWindowMenuBar.qml index 2ee2476bf..a485aace5 100644 --- a/linphone-app/ui/views/App/Main/MainWindowMenuBar.qml +++ b/linphone-app/ui/views/App/Main/MainWindowMenuBar.qml @@ -1,14 +1,16 @@ import QtQuick 2.7 -import QtQuick.Controls 2.3 -import Qt.labs.platform 1.0 +//import QtQuick.Controls 2.3 +//import Qt.labs.platform 1.0 import Linphone 1.0 - +import Common 1.0 +import Utils 1.0 // ============================================================================= Item { + id:menuParent function open () { - menu.open() + menu.popup() } // ---------------------------------------------------------------------------