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
f9901b5e
Commit
f9901b5e
authored
Mar 29, 2017
by
Ronan Abhamon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(app): deal correctly with unread messages count
parent
ce2a71ce
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
100 additions
and
50 deletions
+100
-50
AsyncObjectBuilder.cpp
...ne-desktop/src/app/object-builders/AsyncObjectBuilder.cpp
+5
-1
SipAddressObserver.cpp
...sktop/src/components/sip-addresses/SipAddressObserver.cpp
+8
-0
SipAddressObserver.hpp
...sktop/src/components/sip-addresses/SipAddressObserver.hpp
+15
-0
SipAddressesModel.cpp
...esktop/src/components/sip-addresses/SipAddressesModel.cpp
+67
-49
SipAddressesModel.hpp
...esktop/src/components/sip-addresses/SipAddressesModel.hpp
+5
-0
No files found.
linphone-desktop/src/app/object-builders/AsyncObjectBuilder.cpp
View file @
f9901b5e
...
...
@@ -102,7 +102,11 @@ void AsyncObjectBuilder::createObject (QQmlEngine *engine, const char *path, Dec
qInfo
()
<<
QStringLiteral
(
"Start async creation of: `%1`. Component:"
).
arg
(
path
)
<<
m_component
;
QObject
::
connect
(
m_component
,
&
QQmlComponent
::
statusChanged
,
this
,
&
AsyncObjectBuilder
::
handleComponentCreation
);
QObject
::
connect
(
m_component
,
&
QQmlComponent
::
statusChanged
,
this
,
&
AsyncObjectBuilder
::
handleComponentCreation
,
Qt
::
DirectConnection
);
}
QObject
*
AsyncObjectBuilder
::
getObject
()
const
{
...
...
linphone-desktop/src/components/sip-addresses/SipAddressObserver.cpp
View file @
f9901b5e
...
...
@@ -43,3 +43,11 @@ void SipAddressObserver::setPresenceStatus (const Presence::PresenceStatus &pres
m_presence_status
=
presence_status
;
emit
presenceStatusChanged
(
presence_status
);
}
void
SipAddressObserver
::
setUnreadMessagesCount
(
int
unread_messages_count
)
{
if
(
unread_messages_count
==
m_unread_messages_count
)
return
;
m_unread_messages_count
=
unread_messages_count
;
emit
unreadMessagesCountChanged
(
unread_messages_count
);
}
linphone-desktop/src/components/sip-addresses/SipAddressObserver.hpp
View file @
f9901b5e
...
...
@@ -36,6 +36,7 @@ class SipAddressObserver : public QObject {
Q_PROPERTY
(
ContactModel
*
contact
READ
getContact
NOTIFY
contactChanged
);
Q_PROPERTY
(
Presence
::
PresenceStatus
presenceStatus
READ
getPresenceStatus
NOTIFY
presenceStatusChanged
);
Q_PROPERTY
(
int
unreadMessagesCount
READ
getUnreadMessagesCount
NOTIFY
unreadMessagesCountChanged
);
public:
SipAddressObserver
(
const
QString
&
sip_address
);
...
...
@@ -44,28 +45,42 @@ public:
signals:
void
contactChanged
(
ContactModel
*
contact
);
void
presenceStatusChanged
(
const
Presence
::
PresenceStatus
&
presenceStatus
);
void
unreadMessagesCountChanged
(
int
unreadMessagesCount
);
private:
QString
getSipAddress
()
const
{
return
m_sip_address
;
}
// ---------------------------------------------------------------------------
ContactModel
*
getContact
()
const
{
return
m_contact
;
}
void
setContact
(
ContactModel
*
contact
);
// ---------------------------------------------------------------------------
Presence
::
PresenceStatus
getPresenceStatus
()
const
{
return
m_presence_status
;
}
void
setPresenceStatus
(
const
Presence
::
PresenceStatus
&
presence_status
);
// ---------------------------------------------------------------------------
int
getUnreadMessagesCount
()
const
{
return
m_unread_messages_count
;
}
void
setUnreadMessagesCount
(
int
unread_messages_count
);
QString
m_sip_address
;
ContactModel
*
m_contact
=
nullptr
;
Presence
::
PresenceStatus
m_presence_status
=
Presence
::
PresenceStatus
::
Offline
;
int
m_unread_messages_count
=
0
;
};
Q_DECLARE_METATYPE
(
SipAddressObserver
*
);
...
...
linphone-desktop/src/components/sip-addresses/SipAddressesModel.cpp
View file @
f9901b5e
...
...
@@ -76,57 +76,18 @@ QVariant SipAddressesModel::data (const QModelIndex &index, int role) const {
return
QVariant
();
}
void
SipAddressesModel
::
connectToChatModel
(
ChatModel
*
chat_model
)
{
QObject
::
connect
(
chat_model
,
&
ChatModel
::
allEntriesRemoved
,
this
,
[
this
,
chat_model
]()
{
const
QString
sip_address
=
chat_model
->
getSipAddress
();
auto
it
=
m_sip_addresses
.
find
(
sip_address
);
if
(
it
==
m_sip_addresses
.
end
())
{
qWarning
()
<<
QStringLiteral
(
"Unable to found sip address: `%1`."
).
arg
(
sip_address
);
return
;
}
int
row
=
m_refs
.
indexOf
(
&
(
*
it
));
Q_ASSERT
(
row
!=
-
1
);
// No history, no contact => Remove sip address from list.
if
(
!
it
->
contains
(
"contact"
))
{
removeRow
(
row
);
return
;
}
// Signal changes.
it
->
remove
(
"timestamp"
);
emit
dataChanged
(
index
(
row
,
0
),
index
(
row
,
0
));
}
);
QObject
::
connect
(
chat_model
,
&
ChatModel
::
messageSent
,
this
,
[
this
](
const
shared_ptr
<
linphone
::
ChatMessage
>
&
message
)
{
addOrUpdateSipAddress
(
::
Utils
::
linphoneStringToQString
(
message
->
getToAddress
()
->
asStringUriOnly
()),
message
);
}
);
QObject
::
connect
(
chat_model
,
&
ChatModel
::
messagesCountReset
,
this
,
[
this
,
chat_model
]()
{
const
QString
&
sip_address
=
chat_model
->
getSipAddress
();
// -----------------------------------------------------------------------------
auto
it
=
m_sip_addresses
.
find
(
sip_address
);
if
(
it
!=
m_sip_addresses
.
end
())
{
(
*
it
)[
"unreadMessagesCount"
]
=
0
;
void
SipAddressesModel
::
connectToChatModel
(
ChatModel
*
chat_model
)
{
QObject
::
connect
(
chat_model
,
&
ChatModel
::
allEntriesRemoved
,
this
,
[
this
,
chat_model
]
{
handleAllEntriesRemoved
(
chat_model
->
getSipAddress
());
});
int
row
=
m_refs
.
indexOf
(
&
(
*
it
));
Q_ASSERT
(
row
!=
-
1
);
emit
dataChanged
(
index
(
row
,
0
),
index
(
row
,
0
));
QObject
::
connect
(
chat_model
,
&
ChatModel
::
messageSent
,
this
,
&
SipAddressesModel
::
handleMessageSent
);
return
;
}
}
);
QObject
::
connect
(
chat_model
,
&
ChatModel
::
messagesCountReset
,
this
,
[
this
,
chat_model
]
{
handleMessagesCountReset
(
chat_model
->
getSipAddress
());
});
}
// -----------------------------------------------------------------------------
...
...
@@ -151,6 +112,9 @@ SipAddressObserver *SipAddressesModel::getSipAddressObserver (const QString &sip
model
->
setPresenceStatus
(
it
->
value
(
"presenceStatus"
,
Presence
::
PresenceStatus
::
Offline
).
value
<
Presence
::
PresenceStatus
>
()
);
model
->
setUnreadMessagesCount
(
it
->
value
(
"unreadMessagesCount"
,
0
).
toInt
()
);
}
}
...
...
@@ -288,6 +252,47 @@ void SipAddressesModel::handlePresenceReceived (
updateObservers
(
sip_address
,
status
);
}
void
SipAddressesModel
::
handleAllEntriesRemoved
(
const
QString
&
sip_address
)
{
auto
it
=
m_sip_addresses
.
find
(
sip_address
);
if
(
it
==
m_sip_addresses
.
end
())
{
qWarning
()
<<
QStringLiteral
(
"Unable to found sip address: `%1`."
).
arg
(
sip_address
);
return
;
}
int
row
=
m_refs
.
indexOf
(
&
(
*
it
));
Q_ASSERT
(
row
!=
-
1
);
// No history, no contact => Remove sip address from list.
if
(
!
it
->
contains
(
"contact"
))
{
removeRow
(
row
);
return
;
}
// Signal changes.
it
->
remove
(
"timestamp"
);
emit
dataChanged
(
index
(
row
,
0
),
index
(
row
,
0
));
}
void
SipAddressesModel
::
handleMessageSent
(
const
shared_ptr
<
linphone
::
ChatMessage
>
&
message
)
{
addOrUpdateSipAddress
(
::
Utils
::
linphoneStringToQString
(
message
->
getToAddress
()
->
asStringUriOnly
()),
message
);
}
void
SipAddressesModel
::
handleMessagesCountReset
(
const
QString
&
sip_address
)
{
auto
it
=
m_sip_addresses
.
find
(
sip_address
);
if
(
it
!=
m_sip_addresses
.
end
())
{
(
*
it
)[
"unreadMessagesCount"
]
=
0
;
int
row
=
m_refs
.
indexOf
(
&
(
*
it
));
Q_ASSERT
(
row
!=
-
1
);
emit
dataChanged
(
index
(
row
,
0
),
index
(
row
,
0
));
}
updateObservers
(
sip_address
,
0
);
}
// -----------------------------------------------------------------------------
void
SipAddressesModel
::
addOrUpdateSipAddress
(
QVariantMap
&
map
,
ContactModel
*
contact
)
{
...
...
@@ -304,8 +309,14 @@ void SipAddressesModel::addOrUpdateSipAddress (QVariantMap &map, const shared_pt
}
void
SipAddressesModel
::
addOrUpdateSipAddress
(
QVariantMap
&
map
,
const
shared_ptr
<
linphone
::
ChatMessage
>
&
message
)
{
// FIXME: Bug in the core, count is incremented after this function call.
// So... +1!
int
count
=
message
->
getChatRoom
()
->
getUnreadMessagesCount
()
+
1
;
map
[
"timestamp"
]
=
QDateTime
::
fromMSecsSinceEpoch
(
message
->
getTime
()
*
1000
);
map
[
"unreadMessagesCount"
]
=
message
->
getChatRoom
()
->
getUnreadMessagesCount
();
map
[
"unreadMessagesCount"
]
=
count
;
updateObservers
(
map
[
"sipAddress"
].
toString
(),
count
);
}
template
<
typename
T
>
...
...
@@ -418,6 +429,8 @@ void SipAddressesModel::initSipAddresses () {
handleContactAdded
(
contact
);
}
// -----------------------------------------------------------------------------
void
SipAddressesModel
::
updateObservers
(
const
QString
&
sip_address
,
ContactModel
*
contact
)
{
for
(
auto
&
observer
:
m_observers
.
values
(
sip_address
))
observer
->
setContact
(
contact
);
...
...
@@ -427,3 +440,8 @@ void SipAddressesModel::updateObservers (const QString &sip_address, const Prese
for
(
auto
&
observer
:
m_observers
.
values
(
sip_address
))
observer
->
setPresenceStatus
(
presence_status
);
}
void
SipAddressesModel
::
updateObservers
(
const
QString
&
sip_address
,
int
messages_count
)
{
for
(
auto
&
observer
:
m_observers
.
values
(
sip_address
))
observer
->
setUnreadMessagesCount
(
messages_count
);
}
linphone-desktop/src/components/sip-addresses/SipAddressesModel.hpp
View file @
f9901b5e
...
...
@@ -68,6 +68,10 @@ private:
void
handleCallStateChanged
(
const
std
::
shared_ptr
<
linphone
::
Call
>
&
call
,
linphone
::
CallState
state
);
void
handlePresenceReceived
(
const
QString
&
sip_address
,
const
shared_ptr
<
const
linphone
::
PresenceModel
>
&
presence_model
);
void
handleAllEntriesRemoved
(
const
QString
&
sip_address
);
void
handleMessageSent
(
const
std
::
shared_ptr
<
linphone
::
ChatMessage
>
&
message
);
void
handleMessagesCountReset
(
const
QString
&
sip_address
);
// ---------------------------------------------------------------------------
// A sip address exists in this list if a contact is linked to it, or a call, or a message.
...
...
@@ -87,6 +91,7 @@ private:
void
updateObservers
(
const
QString
&
sip_address
,
ContactModel
*
contact
);
void
updateObservers
(
const
QString
&
sip_address
,
const
Presence
::
PresenceStatus
&
presence_status
);
void
updateObservers
(
const
QString
&
sip_address
,
int
messages_count
);
QHash
<
QString
,
QVariantMap
>
m_sip_addresses
;
QList
<
const
QVariantMap
*>
m_refs
;
...
...
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