mirror of
https://gitlab.linphone.org/BC/public/linphone-desktop.git
synced 2026-05-07 14:44:01 +00:00
feat(Linphone/Chat): use the right model from core
This commit is contained in:
parent
fc88ff95d3
commit
abaa151930
7 changed files with 56 additions and 26 deletions
|
|
@ -1,3 +1,5 @@
|
|||
#include <QDateTime>
|
||||
|
||||
#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<linphone::ChatRoom> 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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 <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 {
|
|||
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
|
||||
})
|
||||
|
|
|
|||
|
|
@ -110,7 +110,7 @@ ColumnLayout {
|
|||
anchors.fill: parent
|
||||
onClicked: {
|
||||
view.currentIndex = index
|
||||
timeline.entrySelected(parent.contact)
|
||||
timeline.entrySelected($timelineEntry.sipAddresses)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -157,7 +157,7 @@ ColumnLayout {
|
|||
ActionButton {
|
||||
icon: 'chat'
|
||||
onClicked: window.setView('Conversation', {
|
||||
contact: $contact
|
||||
sipAddress: $contact.sipAddress
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -144,7 +144,7 @@ ApplicationWindow {
|
|||
|
||||
onEntrySelected: {
|
||||
menu.resetSelectedEntry()
|
||||
setView('Conversation', { contact: entry })
|
||||
setView('Conversation', { sipAddress: entry })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue