From abaa151930d3ef3ba47a65dc7cb2f2fbab21ed1c Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Thu, 24 Nov 2016 16:03:01 +0100 Subject: [PATCH] feat(Linphone/Chat): use the right model from core --- tests/src/components/chat/ChatModel.cpp | 23 ++++++++++++++++ tests/ui/modules/Linphone/Chat/Chat.qml | 25 +++++++----------- tests/ui/modules/Linphone/Chat/Message.qml | 2 +- tests/ui/modules/Linphone/Timeline.qml | 2 +- tests/ui/views/App/MainWindow/Contacts.qml | 2 +- .../ui/views/App/MainWindow/Conversation.qml | 26 ++++++++++++++----- tests/ui/views/App/MainWindow/MainWindow.qml | 2 +- 7 files changed, 56 insertions(+), 26 deletions(-) diff --git a/tests/src/components/chat/ChatModel.cpp b/tests/src/components/chat/ChatModel.cpp index c8954fedc..470f9bd33 100644 --- a/tests/src/components/chat/ChatModel.cpp +++ b/tests/src/components/chat/ChatModel.cpp @@ -1,3 +1,5 @@ +#include + #include "../../utils.hpp" #include "../core/CoreManager.hpp" @@ -38,10 +40,31 @@ void ChatModel::setSipAddress (const QString &sip_address) { if (sip_address == getSipAddress()) return; + beginResetModel(); + + // Invalid old sip address entries. + m_entries.clear(); + std::shared_ptr chat_room = CoreManager::getInstance()->getCore()->getChatRoomFromUri( Utils::qStringToLinphoneString(sip_address) ); + for (auto &message : chat_room->getHistory(0)) { + QVariantMap map; + + map["sectionDate"] = 1465389121; + map["timestamp"] = QDateTime::fromTime_t(message->getTime()); + map["type"] = "message"; + map["content"] = Utils::linphoneStringToQString( + message->getText() + ); + map["isOutgoing"] = message->isOutgoing(); + + m_entries << map; + } + + endResetModel(); + emit sipAddressChanged(sip_address); } diff --git a/tests/ui/modules/Linphone/Chat/Chat.qml b/tests/ui/modules/Linphone/Chat/Chat.qml index 974f420ca..ac1c6235b 100644 --- a/tests/ui/modules/Linphone/Chat/Chat.qml +++ b/tests/ui/modules/Linphone/Chat/Chat.qml @@ -11,18 +11,22 @@ import Linphone.Styles 1.0 ColumnLayout { property var contact + property alias model: listView.model + // ----------------------------------------------------------------- spacing: 0 ScrollableListView { + id: listView + Layout.fillHeight: true Layout.fillWidth: true section { criteria: ViewSection.FullString delegate: sectionHeading - property: '$dateSection' + property: '$chatEntry.sectionDate' } // --------------------------------------------------------------- @@ -60,7 +64,7 @@ ColumnLayout { verticalAlignment: Text.AlignVCenter // Cast section to integer because Qt converts the - // $dateSection in string!!! + // sectionDate in string!!! text: new Date(+section).toLocaleDateString( Qt.locale(App.locale()) ) @@ -143,7 +147,7 @@ ColumnLayout { Layout.preferredWidth: ChatStyle.entry.time.width color: ChatStyle.entry.time.color font.pointSize: ChatStyle.entry.time.fontSize - text: new Date($timestamp).toLocaleString( + text: $chatEntry.timestamp.toLocaleString( Qt.locale(App.locale()), 'hh:mm' ) @@ -153,24 +157,13 @@ ColumnLayout { // Display content. Loader { Layout.fillWidth: true - sourceComponent: $type === 'message' - ? ($outgoing ? outgoingMessage : incomingMessage) + sourceComponent: $chatEntry.type === 'message' + ? ($chatEntry.isOutgoing ? outgoingMessage : incomingMessage) : event } } } } - - // TMP - model: ListModel { - ListElement { $dateSection: 1465389121000; $outgoing: true; $timestamp: 1465389121000; $type: 'message'; $content: "https://cdn.pixabay.com/photo/2014/03/29/09/17/cat-300572_960_720.jpg www.google.fr" } - ListElement { $dateSection: 1465389121000; $outgoing: true; $timestamp: 1465389121000; $type: 'message'; $content: "Contact mail" } - ListElement { $dateSection: 1465389121000; $timestamp: 1465389133000; $type: 'event'; $content: 'incoming_call' } - ListElement { $dateSection: 1465389121000; $timestamp: 1465389439000; $type: 'message'; $content: 'www.test.frPerfect! bg g vg gv v g v hgv gv gv jhb jh b jb jh hg vg cfcy f v u uyg f tf tf ft f tf t t fy ft f tu ty f rd rd d d uu gu y gg y f r dr ' } - ListElement { $dateSection: 1465389121000; $timestamp: 1465389500000; $type: 'event'; $content: 'end_call' } - ListElement { $dateSection: 1465994221000; $outgoing: true; $timestamp: 1465924321000; $type: 'message'; $content: 'http://mithril94.free.fr/sigbarfactory/fonts/show/tribal.gif https://cdn.pixabay.com/photo/2014/03/29/09/17/cat-300572_960_720.jpg You\'ve heard the expression, "Just believe it and http://writm.com/wp-content/uploads/2016/08/Cat-hd-wallpapers.jpg it will https://cdn.pixabay.com/photo/2014/03/29/09/17/cat-300572_960_720.jpg come." http://html.com/wp-content/uploads/html-com-1.png Well, technically, that is true, https://cdn.pixabay.com/photo/2014/03/29/09/17/cat-300572_960_720.jpg however, \'believing\' is not just thinking that you can have it...' } - ListElement { $dateSection: 1465994221000; $timestamp: 1465924391000; $type: 'event'; $content: 'lost_incoming_call' } - } } // ----------------------------------------------------------------- diff --git a/tests/ui/modules/Linphone/Chat/Message.qml b/tests/ui/modules/Linphone/Chat/Message.qml index 342486ec8..6219c8043 100644 --- a/tests/ui/modules/Linphone/Chat/Message.qml +++ b/tests/ui/modules/Linphone/Chat/Message.qml @@ -60,7 +60,7 @@ Item { padding: ChatStyle.entry.message.padding readOnly: true selectByMouse: true - text: Utils.encodeUrisToQmlFormat($content, { + text: Utils.encodeUrisToQmlFormat($chatEntry.content, { imagesHeight: ChatStyle.entry.message.images.height, imagesWidth: ChatStyle.entry.message.images.width }) diff --git a/tests/ui/modules/Linphone/Timeline.qml b/tests/ui/modules/Linphone/Timeline.qml index de2ae67dd..8a98f050e 100644 --- a/tests/ui/modules/Linphone/Timeline.qml +++ b/tests/ui/modules/Linphone/Timeline.qml @@ -110,7 +110,7 @@ ColumnLayout { anchors.fill: parent onClicked: { view.currentIndex = index - timeline.entrySelected(parent.contact) + timeline.entrySelected($timelineEntry.sipAddresses) } } } diff --git a/tests/ui/views/App/MainWindow/Contacts.qml b/tests/ui/views/App/MainWindow/Contacts.qml index 4591627eb..5629d5f5c 100644 --- a/tests/ui/views/App/MainWindow/Contacts.qml +++ b/tests/ui/views/App/MainWindow/Contacts.qml @@ -157,7 +157,7 @@ ColumnLayout { ActionButton { icon: 'chat' onClicked: window.setView('Conversation', { - contact: $contact + sipAddress: $contact.sipAddress }) } } diff --git a/tests/ui/views/App/MainWindow/Conversation.qml b/tests/ui/views/App/MainWindow/Conversation.qml index f3d419ca6..ffa92c946 100644 --- a/tests/ui/views/App/MainWindow/Conversation.qml +++ b/tests/ui/views/App/MainWindow/Conversation.qml @@ -3,13 +3,20 @@ import QtQuick.Layouts 1.3 import Common 1.0 import Linphone 1.0 +import Utils 1.0 import App.Styles 1.0 // =================================================================== ColumnLayout { - property var contact + id: conversation + + property string sipAddress + + property var _contact: ContactsListModel.mapSipAddressToContact( + sipAddress + ) || sipAddress spacing: 0 @@ -31,18 +38,22 @@ ColumnLayout { spacing: ConversationStyle.bar.spacing Avatar { + id: avatar + Layout.preferredHeight: ConversationStyle.bar.avatarSize Layout.preferredWidth: ConversationStyle.bar.avatarSize - presenceLevel: contact.presenceLevel - username: contact.username + presenceLevel: _contact.presenceLevel || Presence.White + username: Utils.isString(_contact) + ? _contact.substring(4, _contact.indexOf('@')) // 4 = length("sip:") + : _contact.username } ContactDescription { Layout.fillHeight: true Layout.fillWidth: true - sipAddress: contact.sipAddress + sipAddress: conversation.sipAddress sipAddressColor: ConversationStyle.bar.description.sipAddressColor - username: contact.username + username: avatar.username usernameColor: ConversationStyle.bar.description.usernameColor } @@ -119,6 +130,9 @@ ColumnLayout { Chat { Layout.fillHeight: true Layout.fillWidth: true - contact: parent.contact + contact: parent._contact + model: ChatModel { + sipAddress: conversation.sipAddress + } } } diff --git a/tests/ui/views/App/MainWindow/MainWindow.qml b/tests/ui/views/App/MainWindow/MainWindow.qml index 6cb793ce9..1fe771d39 100644 --- a/tests/ui/views/App/MainWindow/MainWindow.qml +++ b/tests/ui/views/App/MainWindow/MainWindow.qml @@ -144,7 +144,7 @@ ApplicationWindow { onEntrySelected: { menu.resetSelectedEntry() - setView('Conversation', { contact: entry }) + setView('Conversation', { sipAddress: entry }) } } }