Commit abaa1519 authored by Ronan Abhamon's avatar Ronan Abhamon

feat(Linphone/Chat): use the right model from core

parent fc88ff95
#include <QDateTime>
#include "../../utils.hpp" #include "../../utils.hpp"
#include "../core/CoreManager.hpp" #include "../core/CoreManager.hpp"
...@@ -38,10 +40,31 @@ void ChatModel::setSipAddress (const QString &sip_address) { ...@@ -38,10 +40,31 @@ void ChatModel::setSipAddress (const QString &sip_address) {
if (sip_address == getSipAddress()) if (sip_address == getSipAddress())
return; return;
beginResetModel();
// Invalid old sip address entries.
m_entries.clear();
std::shared_ptr<linphone::ChatRoom> chat_room = std::shared_ptr<linphone::ChatRoom> chat_room =
CoreManager::getInstance()->getCore()->getChatRoomFromUri( CoreManager::getInstance()->getCore()->getChatRoomFromUri(
Utils::qStringToLinphoneString(sip_address) 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); emit sipAddressChanged(sip_address);
} }
...@@ -11,18 +11,22 @@ import Linphone.Styles 1.0 ...@@ -11,18 +11,22 @@ import Linphone.Styles 1.0
ColumnLayout { ColumnLayout {
property var contact property var contact
property alias model: listView.model
// ----------------------------------------------------------------- // -----------------------------------------------------------------
spacing: 0 spacing: 0
ScrollableListView { ScrollableListView {
id: listView
Layout.fillHeight: true Layout.fillHeight: true
Layout.fillWidth: true Layout.fillWidth: true
section { section {
criteria: ViewSection.FullString criteria: ViewSection.FullString
delegate: sectionHeading delegate: sectionHeading
property: '$dateSection' property: '$chatEntry.sectionDate'
} }
// --------------------------------------------------------------- // ---------------------------------------------------------------
...@@ -60,7 +64,7 @@ ColumnLayout { ...@@ -60,7 +64,7 @@ ColumnLayout {
verticalAlignment: Text.AlignVCenter verticalAlignment: Text.AlignVCenter
// Cast section to integer because Qt converts the // Cast section to integer because Qt converts the
// $dateSection in string!!! // sectionDate in string!!!
text: new Date(+section).toLocaleDateString( text: new Date(+section).toLocaleDateString(
Qt.locale(App.locale()) Qt.locale(App.locale())
) )
...@@ -143,7 +147,7 @@ ColumnLayout { ...@@ -143,7 +147,7 @@ ColumnLayout {
Layout.preferredWidth: ChatStyle.entry.time.width Layout.preferredWidth: ChatStyle.entry.time.width
color: ChatStyle.entry.time.color color: ChatStyle.entry.time.color
font.pointSize: ChatStyle.entry.time.fontSize font.pointSize: ChatStyle.entry.time.fontSize
text: new Date($timestamp).toLocaleString( text: $chatEntry.timestamp.toLocaleString(
Qt.locale(App.locale()), Qt.locale(App.locale()),
'hh:mm' 'hh:mm'
) )
...@@ -153,24 +157,13 @@ ColumnLayout { ...@@ -153,24 +157,13 @@ ColumnLayout {
// Display content. // Display content.
Loader { Loader {
Layout.fillWidth: true Layout.fillWidth: true
sourceComponent: $type === 'message' sourceComponent: $chatEntry.type === 'message'
? ($outgoing ? outgoingMessage : incomingMessage) ? ($chatEntry.isOutgoing ? outgoingMessage : incomingMessage)
: event : 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 <img src='http://html.com/wp-content/uploads/html-com-1.png' width='50%' height='50%' />www.google.fr" }
ListElement { $dateSection: 1465389121000; $outgoing: true; $timestamp: 1465389121000; $type: 'message'; $content: "<a href='mailto:qq1@qqpart.com'>Contact mail</a>" }
ListElement { $dateSection: 1465389121000; $timestamp: 1465389133000; $type: 'event'; $content: 'incoming_call' }
ListElement { $dateSection: 1465389121000; $timestamp: 1465389439000; $type: 'message'; $content: 'www.test.fr<blink>Perfect!</blink> 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' }
}
} }
// ----------------------------------------------------------------- // -----------------------------------------------------------------
......
...@@ -60,7 +60,7 @@ Item { ...@@ -60,7 +60,7 @@ Item {
padding: ChatStyle.entry.message.padding padding: ChatStyle.entry.message.padding
readOnly: true readOnly: true
selectByMouse: true selectByMouse: true
text: Utils.encodeUrisToQmlFormat($content, { text: Utils.encodeUrisToQmlFormat($chatEntry.content, {
imagesHeight: ChatStyle.entry.message.images.height, imagesHeight: ChatStyle.entry.message.images.height,
imagesWidth: ChatStyle.entry.message.images.width imagesWidth: ChatStyle.entry.message.images.width
}) })
......
...@@ -110,7 +110,7 @@ ColumnLayout { ...@@ -110,7 +110,7 @@ ColumnLayout {
anchors.fill: parent anchors.fill: parent
onClicked: { onClicked: {
view.currentIndex = index view.currentIndex = index
timeline.entrySelected(parent.contact) timeline.entrySelected($timelineEntry.sipAddresses)
} }
} }
} }
......
...@@ -157,7 +157,7 @@ ColumnLayout { ...@@ -157,7 +157,7 @@ ColumnLayout {
ActionButton { ActionButton {
icon: 'chat' icon: 'chat'
onClicked: window.setView('Conversation', { onClicked: window.setView('Conversation', {
contact: $contact sipAddress: $contact.sipAddress
}) })
} }
} }
......
...@@ -3,13 +3,20 @@ import QtQuick.Layouts 1.3 ...@@ -3,13 +3,20 @@ import QtQuick.Layouts 1.3
import Common 1.0 import Common 1.0
import Linphone 1.0 import Linphone 1.0
import Utils 1.0
import App.Styles 1.0 import App.Styles 1.0
// =================================================================== // ===================================================================
ColumnLayout { ColumnLayout {
property var contact id: conversation
property string sipAddress
property var _contact: ContactsListModel.mapSipAddressToContact(
sipAddress
) || sipAddress
spacing: 0 spacing: 0
...@@ -31,18 +38,22 @@ ColumnLayout { ...@@ -31,18 +38,22 @@ ColumnLayout {
spacing: ConversationStyle.bar.spacing spacing: ConversationStyle.bar.spacing
Avatar { Avatar {
id: avatar
Layout.preferredHeight: ConversationStyle.bar.avatarSize Layout.preferredHeight: ConversationStyle.bar.avatarSize
Layout.preferredWidth: ConversationStyle.bar.avatarSize Layout.preferredWidth: ConversationStyle.bar.avatarSize
presenceLevel: contact.presenceLevel presenceLevel: _contact.presenceLevel || Presence.White
username: contact.username username: Utils.isString(_contact)
? _contact.substring(4, _contact.indexOf('@')) // 4 = length("sip:")
: _contact.username
} }
ContactDescription { ContactDescription {
Layout.fillHeight: true Layout.fillHeight: true
Layout.fillWidth: true Layout.fillWidth: true
sipAddress: contact.sipAddress sipAddress: conversation.sipAddress
sipAddressColor: ConversationStyle.bar.description.sipAddressColor sipAddressColor: ConversationStyle.bar.description.sipAddressColor
username: contact.username username: avatar.username
usernameColor: ConversationStyle.bar.description.usernameColor usernameColor: ConversationStyle.bar.description.usernameColor
} }
...@@ -119,6 +130,9 @@ ColumnLayout { ...@@ -119,6 +130,9 @@ ColumnLayout {
Chat { Chat {
Layout.fillHeight: true Layout.fillHeight: true
Layout.fillWidth: true Layout.fillWidth: true
contact: parent.contact contact: parent._contact
model: ChatModel {
sipAddress: conversation.sipAddress
}
} }
} }
...@@ -144,7 +144,7 @@ ApplicationWindow { ...@@ -144,7 +144,7 @@ ApplicationWindow {
onEntrySelected: { onEntrySelected: {
menu.resetSelectedEntry() menu.resetSelectedEntry()
setView('Conversation', { contact: entry }) setView('Conversation', { sipAddress: entry })
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment