Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
linphone-desktop
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
linphone-desktop
Commits
40236491
Commit
40236491
authored
Nov 25, 2016
by
Ronan Abhamon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(components/chat): supports deletion of messages
parent
0c7387f8
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
77 additions
and
20 deletions
+77
-20
ChatModel.cpp
tests/src/components/chat/ChatModel.cpp
+54
-7
ChatModel.hpp
tests/src/components/chat/ChatModel.hpp
+13
-1
ContactsListModel.cpp
tests/src/components/contacts/ContactsListModel.cpp
+2
-4
Chat.qml
tests/ui/modules/Linphone/Chat/Chat.qml
+5
-5
Event.qml
tests/ui/modules/Linphone/Chat/Event.qml
+1
-1
IncomingMessage.qml
tests/ui/modules/Linphone/Chat/IncomingMessage.qml
+1
-1
OutgoingMessage.qml
tests/ui/modules/Linphone/Chat/OutgoingMessage.qml
+1
-1
No files found.
tests/src/components/chat/ChatModel.cpp
View file @
40236491
#include <QDateTime>
#include <QDateTime>
#include <QtDebug>
#include "../../utils.hpp"
#include "../../utils.hpp"
#include "../core/CoreManager.hpp"
#include "../core/CoreManager.hpp"
#include "ChatModel.hpp"
#include "ChatModel.hpp"
using
namespace
std
;
// ===================================================================
// ===================================================================
QHash
<
int
,
QByteArray
>
ChatModel
::
roleNames
()
const
{
QHash
<
int
,
QByteArray
>
ChatModel
::
roleNames
()
const
{
...
@@ -22,14 +25,55 @@ QVariant ChatModel::data (const QModelIndex &index, int role) const {
...
@@ -22,14 +25,55 @@ QVariant ChatModel::data (const QModelIndex &index, int role) const {
switch
(
role
)
{
switch
(
role
)
{
case
Roles
:
:
ChatEntry
:
case
Roles
:
:
ChatEntry
:
return
QVariant
::
fromValue
(
m_entries
[
row
]);
return
QVariant
::
fromValue
(
m_entries
[
row
]
.
first
);
case
Roles
:
:
SectionDate
:
case
Roles
:
:
SectionDate
:
return
QVariant
::
fromValue
(
m_entries
[
row
][
"timestamp"
].
toDate
());
return
QVariant
::
fromValue
(
m_entries
[
row
]
.
first
[
"timestamp"
].
toDate
());
}
}
return
QVariant
();
return
QVariant
();
}
}
bool
ChatModel
::
removeRow
(
int
row
,
const
QModelIndex
&
)
{
return
removeRows
(
row
,
1
);
}
bool
ChatModel
::
removeRows
(
int
row
,
int
count
,
const
QModelIndex
&
parent
)
{
int
limit
=
row
+
count
-
1
;
if
(
row
<
0
||
count
<
0
||
limit
>=
m_entries
.
count
())
return
false
;
beginRemoveRows
(
parent
,
row
,
limit
);
for
(
int
i
=
0
;
i
<
count
;
++
i
)
{
QPair
<
QVariantMap
,
shared_ptr
<
void
>
>
pair
=
m_entries
.
takeAt
(
row
);
switch
(
pair
.
first
[
"type"
].
toInt
())
{
case
ChatModel
:
:
MessageEntry
:
m_chat_room
->
deleteMessage
(
static_pointer_cast
<
linphone
::
ChatMessage
>
(
pair
.
second
)
);
break
;
case
ChatModel
:
:
CallEntry
:
break
;
}
}
endRemoveRows
();
return
true
;
}
// -------------------------------------------------------------------
void
ChatModel
::
removeEntry
(
int
id
)
{
qInfo
()
<<
"Removing chat entry:"
<<
id
<<
"of:"
<<
getSipAddress
();
if
(
!
removeRow
(
id
))
qWarning
()
<<
"Unable to remove chat entry:"
<<
id
;
}
// -------------------------------------------------------------------
// -------------------------------------------------------------------
QString
ChatModel
::
getSipAddress
()
const
{
QString
ChatModel
::
getSipAddress
()
const
{
...
@@ -50,25 +94,28 @@ void ChatModel::setSipAddress (const QString &sip_address) {
...
@@ -50,25 +94,28 @@ void ChatModel::setSipAddress (const QString &sip_address) {
// Invalid old sip address entries.
// Invalid old sip address entries.
m_entries
.
clear
();
m_entries
.
clear
();
std
::
shared_ptr
<
linphone
::
ChatRoom
>
chat_room
=
m_
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
))
{
// Get messages.
for
(
auto
&
message
:
m_chat_room
->
getHistory
(
0
))
{
QVariantMap
map
;
QVariantMap
map
;
// UTC format.
map
[
"type"
]
=
EntryType
::
MessageEntry
;
map
[
"timestamp"
]
=
QDateTime
::
fromTime_t
(
message
->
getTime
());
map
[
"timestamp"
]
=
QDateTime
::
fromTime_t
(
message
->
getTime
());
map
[
"type"
]
=
"message"
;
map
[
"content"
]
=
Utils
::
linphoneStringToQString
(
map
[
"content"
]
=
Utils
::
linphoneStringToQString
(
message
->
getText
()
message
->
getText
()
);
);
map
[
"isOutgoing"
]
=
message
->
isOutgoing
();
map
[
"isOutgoing"
]
=
message
->
isOutgoing
();
m_entries
<<
map
;
m_entries
<<
qMakePair
(
map
,
static_pointer_cast
<
void
>
(
message
))
;
}
}
// Get calls.
// TODO.
endResetModel
();
endResetModel
();
emit
sipAddressChanged
(
sip_address
);
emit
sipAddressChanged
(
sip_address
);
...
...
tests/src/components/chat/ChatModel.hpp
View file @
40236491
...
@@ -22,6 +22,12 @@ public:
...
@@ -22,6 +22,12 @@ public:
SectionDate
SectionDate
};
};
enum
EntryType
{
MessageEntry
,
CallEntry
};
Q_ENUM
(
EntryType
);
ChatModel
(
QObject
*
parent
=
Q_NULLPTR
)
:
QAbstractListModel
(
parent
)
{}
ChatModel
(
QObject
*
parent
=
Q_NULLPTR
)
:
QAbstractListModel
(
parent
)
{}
int
rowCount
(
const
QModelIndex
&
index
=
QModelIndex
())
const
{
int
rowCount
(
const
QModelIndex
&
index
=
QModelIndex
())
const
{
...
@@ -31,6 +37,12 @@ public:
...
@@ -31,6 +37,12 @@ public:
QHash
<
int
,
QByteArray
>
roleNames
()
const
;
QHash
<
int
,
QByteArray
>
roleNames
()
const
;
QVariant
data
(
const
QModelIndex
&
index
,
int
role
)
const
;
QVariant
data
(
const
QModelIndex
&
index
,
int
role
)
const
;
bool
removeRow
(
int
row
,
const
QModelIndex
&
parent
=
QModelIndex
());
bool
removeRows
(
int
row
,
int
count
,
const
QModelIndex
&
parent
=
QModelIndex
());
public
slots
:
void
removeEntry
(
int
id
);
signals:
signals:
void
sipAddressChanged
(
const
QString
&
sipAddress
);
void
sipAddressChanged
(
const
QString
&
sipAddress
);
...
@@ -38,7 +50,7 @@ private:
...
@@ -38,7 +50,7 @@ private:
QString
getSipAddress
()
const
;
QString
getSipAddress
()
const
;
void
setSipAddress
(
const
QString
&
sip_address
);
void
setSipAddress
(
const
QString
&
sip_address
);
QList
<
Q
VariantMap
>
m_entries
;
QList
<
Q
Pair
<
QVariantMap
,
std
::
shared_ptr
<
void
>
>
>
m_entries
;
std
::
shared_ptr
<
linphone
::
ChatRoom
>
m_chat_room
;
std
::
shared_ptr
<
linphone
::
ChatRoom
>
m_chat_room
;
};
};
...
...
tests/src/components/contacts/ContactsListModel.cpp
View file @
40236491
...
@@ -57,11 +57,9 @@ bool ContactsListModel::removeRows (int row, int count, const QModelIndex &paren
...
@@ -57,11 +57,9 @@ bool ContactsListModel::removeRows (int row, int count, const QModelIndex &paren
beginRemoveRows
(
parent
,
row
,
limit
);
beginRemoveRows
(
parent
,
row
,
limit
);
for
(
int
i
=
0
;
i
<
count
;
++
i
)
{
for
(
int
i
=
0
;
i
<
count
;
++
i
)
{
ContactModel
*
contact
=
m_list
[
row
]
;
ContactModel
*
contact
=
m_list
.
takeAt
(
row
)
;
m_list
.
removeAt
(
row
);
m_linphone_friends
->
removeFriend
(
contact
->
m_linphone_friend
);
m_linphone_friends
->
removeFriend
(
contact
->
m_linphone_friend
);
contact
->
deleteLater
();
contact
->
deleteLater
();
}
}
...
@@ -94,5 +92,5 @@ void ContactsListModel::removeContact (ContactModel *contact) {
...
@@ -94,5 +92,5 @@ void ContactsListModel::removeContact (ContactModel *contact) {
int
index
=
m_list
.
indexOf
(
contact
);
int
index
=
m_list
.
indexOf
(
contact
);
if
(
index
==
-
1
||
!
removeRow
(
index
))
if
(
index
==
-
1
||
!
removeRow
(
index
))
qWarning
()
<<
"Unable to remove contact:"
<<
index
;
qWarning
()
<<
"Unable to remove contact:"
<<
contact
;
}
}
tests/ui/modules/Linphone/Chat/Chat.qml
View file @
40236491
...
@@ -11,14 +11,14 @@ import Linphone.Styles 1.0
...
@@ -11,14 +11,14 @@ import Linphone.Styles 1.0
ColumnLayout
{
ColumnLayout
{
property
var
contact
property
var
contact
property
alias
model
:
listView
.
model
property
alias
model
:
chat
.
model
// -----------------------------------------------------------------
// -----------------------------------------------------------------
spacing
:
0
spacing
:
0
ScrollableListView
{
ScrollableListView
{
id
:
listView
id
:
chat
Layout.fillHeight
:
true
Layout.fillHeight
:
true
Layout.fillWidth
:
true
Layout.fillWidth
:
true
...
@@ -84,8 +84,8 @@ ColumnLayout {
...
@@ -84,8 +84,8 @@ ColumnLayout {
return
mouseArea
.
containsMouse
return
mouseArea
.
containsMouse
}
}
function
delet
eEntry
()
{
function
remov
eEntry
()
{
c
onsole
.
log
(
'
delete entry
'
,
index
)
c
hat
.
model
.
removeEntry
(
index
)
}
}
anchors
{
anchors
{
...
@@ -157,7 +157,7 @@ ColumnLayout {
...
@@ -157,7 +157,7 @@ ColumnLayout {
// Display content.
// Display content.
Loader
{
Loader
{
Layout.fillWidth
:
true
Layout.fillWidth
:
true
sourceComponent
:
$chatEntry
.
type
===
'
message
'
sourceComponent
:
$chatEntry
.
type
===
ChatModel
.
MessageEntry
?
(
$chatEntry
.
isOutgoing
?
outgoingMessage
:
incomingMessage
)
?
(
$chatEntry
.
isOutgoing
?
outgoingMessage
:
incomingMessage
)
:
event
:
event
}
}
...
...
tests/ui/modules/Linphone/Chat/Event.qml
View file @
40236491
...
@@ -47,6 +47,6 @@ Row {
...
@@ -47,6 +47,6 @@ Row {
iconSize
:
ChatStyle
.
entry
.
deleteIconSize
iconSize
:
ChatStyle
.
entry
.
deleteIconSize
visible
:
isHoverEntry
()
visible
:
isHoverEntry
()
onClicked
:
delet
eEntry
()
onClicked
:
remov
eEntry
()
}
}
}
}
tests/ui/modules/Linphone/Chat/IncomingMessage.qml
View file @
40236491
...
@@ -43,7 +43,7 @@ RowLayout {
...
@@ -43,7 +43,7 @@ RowLayout {
iconSize
:
ChatStyle
.
entry
.
deleteIconSize
iconSize
:
ChatStyle
.
entry
.
deleteIconSize
visible
:
isHoverEntry
()
visible
:
isHoverEntry
()
onClicked
:
delet
eEntry
()
onClicked
:
remov
eEntry
()
}
}
}
}
}
}
tests/ui/modules/Linphone/Chat/OutgoingMessage.qml
View file @
40236491
...
@@ -39,7 +39,7 @@ Item {
...
@@ -39,7 +39,7 @@ Item {
iconSize
:
ChatStyle
.
entry
.
deleteIconSize
iconSize
:
ChatStyle
.
entry
.
deleteIconSize
visible
:
isHoverEntry
()
visible
:
isHoverEntry
()
onClicked
:
delet
eEntry
()
onClicked
:
remov
eEntry
()
}
}
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment