Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
BC
public
liblinphone
Commits
f319f5cf
Commit
f319f5cf
authored
Sep 19, 2018
by
Simon Morlat
Browse files
Revert "fix(ChatMessage): chat message state must be independent of imdn"
This reverts commit
2f1d4b13
.
parent
2f1d4b13
Pipeline
#344
failed with stage
in 0 seconds
Changes
12
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/chat/chat-message/chat-message-p.h
View file @
f319f5cf
...
...
@@ -62,11 +62,7 @@ public:
void
setDirection
(
ChatMessage
::
Direction
dir
);
void
setParticipantState
(
const
IdentityAddress
&
participantAddress
,
ChatMessage
::
State
newState
,
time_t
stateChangeTime
);
virtual
void
setState
(
ChatMessage
::
State
newState
);
void
forceState
(
ChatMessage
::
State
newState
)
{
state
=
newState
;
}
virtual
void
setState
(
ChatMessage
::
State
newState
,
bool
force
=
false
);
void
setTime
(
time_t
time
);
...
...
@@ -101,6 +97,9 @@ public:
belle_http_request_t
*
getHttpRequest
()
const
;
void
setHttpRequest
(
belle_http_request_t
*
request
);
SalOp
*
getSalOp
()
const
;
void
setSalOp
(
SalOp
*
op
);
bool
getDisplayNotificationRequired
()
const
{
return
displayNotificationRequired
;
}
bool
getNegativeDeliveryNotificationRequired
()
const
{
return
negativeDeliveryNotificationRequired
;
}
bool
getPositiveDeliveryNotificationRequired
()
const
{
return
positiveDeliveryNotificationRequired
;
}
...
...
@@ -108,12 +107,6 @@ public:
virtual
void
setNegativeDeliveryNotificationRequired
(
bool
value
)
{
negativeDeliveryNotificationRequired
=
value
;
}
virtual
void
setPositiveDeliveryNotificationRequired
(
bool
value
)
{
positiveDeliveryNotificationRequired
=
value
;
}
SalOp
*
getSalOp
()
const
;
void
setSalOp
(
SalOp
*
op
);
void
disableDeliveryNotificationRequiredInDatabase
();
void
disableDisplayNotificationRequiredInDatabase
();
SalCustomHeader
*
getSalCustomHeaders
()
const
;
void
setSalCustomHeaders
(
SalCustomHeader
*
headers
);
...
...
src/chat/chat-message/chat-message.cpp
View file @
f319f5cf
...
...
@@ -133,14 +133,15 @@ void ChatMessagePrivate::setParticipantState (const IdentityAddress &participant
setState
(
ChatMessage
::
State
::
DeliveredToUser
);
}
void
ChatMessagePrivate
::
setState
(
ChatMessage
::
State
newState
)
{
void
ChatMessagePrivate
::
setState
(
ChatMessage
::
State
newState
,
bool
force
)
{
L_Q
();
// 1. Check valid transition.
if
(
force
)
state
=
newState
;
if
(
!
isValidStateTransition
(
state
,
newState
))
return
;
// 2. Update state and notify changes.
lInfo
()
<<
"Chat message "
<<
this
<<
": moving from "
<<
Utils
::
toString
(
state
)
<<
" to "
<<
Utils
::
toString
(
newState
);
state
=
newState
;
...
...
@@ -149,7 +150,7 @@ void ChatMessagePrivate::setState (ChatMessage::State newState) {
if
(
linphone_chat_message_get_message_state_changed_cb
(
msg
))
linphone_chat_message_get_message_state_changed_cb
(
msg
)(
msg
,
LinphoneChatMessageState
(
state
)
,
(
LinphoneChatMessageState
)
state
,
linphone_chat_message_get_message_state_changed_cb_user_data
(
msg
)
);
...
...
@@ -157,22 +158,17 @@ void ChatMessagePrivate::setState (ChatMessage::State newState) {
if
(
cbs
&&
linphone_chat_message_cbs_get_msg_state_changed
(
cbs
))
linphone_chat_message_cbs_get_msg_state_changed
(
cbs
)(
msg
,
(
LinphoneChatMessageState
)
state
);
// 3. Specific case, change to displayed after transfer.
if
(
state
==
ChatMessage
::
State
::
FileTransferDone
)
{
setState
(
ChatMessage
::
State
::
Displayed
);
return
;
}
// 4. Send notification and update in database if necessary.
if
(
state
!=
ChatMessage
::
State
::
FileTransferError
&&
state
!=
ChatMessage
::
State
::
InProgress
)
{
if
(
state
==
ChatMessage
::
State
::
Displayed
)
static_cast
<
ChatRoomPrivate
*>
(
q
->
getChatRoom
()
->
getPrivate
())
->
sendDisplayNotification
(
q
->
getSharedFromThis
());
if
(
!
hasFileTransferContent
())
{
// We wait until the file has been downloaded to send the displayed IMDN
bool
doNotStoreInDb
=
static_cast
<
ChatRoomPrivate
*>
(
q
->
getChatRoom
()
->
getPrivate
())
->
sendDisplayNotification
(
q
->
getSharedFromThis
());
// Force the state so it is stored directly in DB, but when the IMDN has successfully been delivered
setState
(
ChatMessage
::
State
::
Displayed
,
doNotStoreInDb
);
}
}
else
if
(
state
!=
ChatMessage
::
State
::
FileTransferError
&&
state
!=
ChatMessage
::
State
::
InProgress
)
updateInDb
();
}
}
// -----------------------------------------------------------------------------
belle_http_request_t
*
ChatMessagePrivate
::
getHttpRequest
()
const
{
return
fileTransferChatMessageModifier
.
getHttpRequest
();
}
...
...
@@ -181,24 +177,6 @@ void ChatMessagePrivate::setHttpRequest (belle_http_request_t *request) {
fileTransferChatMessageModifier
.
setHttpRequest
(
request
);
}
// -----------------------------------------------------------------------------
void
ChatMessagePrivate
::
disableDeliveryNotificationRequiredInDatabase
()
{
L_Q
();
unique_ptr
<
MainDb
>
&
mainDb
=
q
->
getChatRoom
()
->
getCore
()
->
getPrivate
()
->
mainDb
;
if
(
dbKey
.
isValid
())
mainDb
->
disableDeliveryNotificationRequired
(
mainDb
->
getEventFromKey
(
dbKey
));
}
void
ChatMessagePrivate
::
disableDisplayNotificationRequiredInDatabase
()
{
L_Q
();
unique_ptr
<
MainDb
>
&
mainDb
=
q
->
getChatRoom
()
->
getCore
()
->
getPrivate
()
->
mainDb
;
if
(
dbKey
.
isValid
())
mainDb
->
disableDisplayNotificationRequired
(
mainDb
->
getEventFromKey
(
dbKey
));
}
// -----------------------------------------------------------------------------
SalOp
*
ChatMessagePrivate
::
getSalOp
()
const
{
return
salOp
;
}
...
...
@@ -491,11 +469,11 @@ void ChatMessagePrivate::notifyReceiving () {
::
time
(
nullptr
),
q
->
getSharedFromThis
()
);
_linphone_chat_room_notify_chat_message_received
(
chatRoom
,
L_GET_C_BACK_PTR
(
event
));
// Legacy
q
->
getChatRoom
()
->
getPrivate
()
->
notifyChatMessageReceived
(
q
->
getSharedFromThis
());
// Legacy.
AbstractChatRoomPrivate
*
dChatRoom
=
q
->
getChatRoom
()
->
getPrivate
();
dChatRoom
->
notifyChatMessageReceived
(
q
->
getSharedFromThis
());
static_cast
<
ChatRoomPrivate
*>
(
dChatRoom
)
->
sendDeliveryNotification
(
q
->
getSharedFromThis
());
if
(
getPositiveDeliveryNotificationRequired
())
static_cast
<
ChatRoomPrivate
*>
(
q
->
getChatRoom
()
->
getPrivate
())
->
sendDeliveryNotification
(
q
->
getSharedFromThis
());
}
LinphoneReason
ChatMessagePrivate
::
receive
()
{
...
...
@@ -519,14 +497,14 @@ LinphoneReason ChatMessagePrivate::receive () {
/* Unable to decrypt message */
chatRoom
->
getPrivate
()
->
notifyUndecryptableChatMessageReceived
(
q
->
getSharedFromThis
());
reason
=
linphone_error_code_to_reason
(
errorCode
);
static_cast
<
ChatRoomPrivate
*>
(
q
->
getChatRoom
()
->
getPrivate
())
->
sendDeliveryErrorNotification
(
q
->
getSharedFromThis
(),
reason
);
if
(
getNegativeDeliveryNotificationRequired
())
{
static_cast
<
ChatRoomPrivate
*>
(
q
->
getChatRoom
()
->
getPrivate
())
->
sendDeliveryErrorNotification
(
q
->
getSharedFromThis
(),
reason
);
}
return
reason
;
}
if
(
result
==
ChatMessageModifier
::
Result
::
Suspended
)
{
}
else
if
(
result
==
ChatMessageModifier
::
Result
::
Suspended
)
{
currentRecvStep
|=
ChatMessagePrivate
::
Step
::
Encryption
;
return
LinphoneReasonNone
;
}
...
...
@@ -598,10 +576,7 @@ LinphoneReason ChatMessagePrivate::receive () {
}
// Check if this is in fact an outgoing message (case where this is a message sent by us from an other device).
if
(
(
chatRoom
->
getCapabilities
()
&
ChatRoom
::
Capabilities
::
Conference
)
&&
Address
(
chatRoom
->
getLocalAddress
()).
weakEqual
(
fromAddress
)
)
if
(
Address
(
chatRoom
->
getLocalAddress
()).
weakEqual
(
fromAddress
))
setDirection
(
ChatMessage
::
Direction
::
Outgoing
);
// Check if this is a duplicate message.
...
...
@@ -610,10 +585,12 @@ LinphoneReason ChatMessagePrivate::receive () {
if
(
errorCode
>
0
)
{
reason
=
linphone_error_code_to_reason
(
errorCode
);
static_cast
<
ChatRoomPrivate
*>
(
q
->
getChatRoom
()
->
getPrivate
())
->
sendDeliveryErrorNotification
(
q
->
getSharedFromThis
(),
reason
);
if
(
getNegativeDeliveryNotificationRequired
())
{
static_cast
<
ChatRoomPrivate
*>
(
q
->
getChatRoom
()
->
getPrivate
())
->
sendDeliveryErrorNotification
(
q
->
getSharedFromThis
(),
reason
);
}
return
reason
;
}
...
...
@@ -643,8 +620,7 @@ void ChatMessagePrivate::send () {
if
(
result
==
ChatMessageModifier
::
Result
::
Error
)
{
setState
(
ChatMessage
::
State
::
NotDelivered
);
return
;
}
if
(
result
==
ChatMessageModifier
::
Result
::
Suspended
)
{
}
else
if
(
result
==
ChatMessageModifier
::
Result
::
Suspended
)
{
setState
(
ChatMessage
::
State
::
InProgress
);
return
;
}
...
...
src/chat/chat-message/imdn-message-p.h
View file @
f319f5cf
...
...
@@ -35,7 +35,7 @@ private:
ImdnMessagePrivate
(
const
ImdnMessage
::
Context
&
context
)
:
NotificationMessagePrivate
(
context
.
chatRoom
,
ChatMessage
::
Direction
::
Outgoing
),
context
(
context
)
{}
void
setState
(
ChatMessage
::
State
newState
)
override
;
void
setState
(
ChatMessage
::
State
newState
,
bool
force
=
false
)
override
;
ImdnMessage
::
Context
context
;
...
...
src/chat/chat-message/imdn-message.cpp
View file @
f319f5cf
...
...
@@ -31,7 +31,7 @@ LINPHONE_BEGIN_NAMESPACE
// -----------------------------------------------------------------------------
void
ImdnMessagePrivate
::
setState
(
ChatMessage
::
State
newState
)
{
void
ImdnMessagePrivate
::
setState
(
ChatMessage
::
State
newState
,
bool
force
)
{
L_Q
();
if
(
newState
==
ChatMessage
::
State
::
Delivered
)
{
...
...
src/chat/chat-message/notification-message-p.h
View file @
f319f5cf
...
...
@@ -35,7 +35,7 @@ protected:
NotificationMessagePrivate
(
const
std
::
shared_ptr
<
AbstractChatRoom
>
&
cr
,
ChatMessage
::
Direction
dir
)
:
ChatMessagePrivate
(
cr
,
dir
)
{}
void
setState
(
ChatMessage
::
State
newState
)
override
{};
void
setState
(
ChatMessage
::
State
newState
,
bool
force
=
false
)
override
{};
private:
void
setDisplayNotificationRequired
(
bool
value
)
override
{}
...
...
src/chat/chat-room/abstract-chat-room-p.h
View file @
f319f5cf
...
...
@@ -38,7 +38,7 @@ public:
virtual
void
setCreationTime
(
time_t
creationTime
)
=
0
;
virtual
void
setLastUpdateTime
(
time_t
lastUpdateTime
)
=
0
;
virtual
void
setState
(
AbstractChatRoom
::
State
newS
tate
)
=
0
;
virtual
void
setState
(
AbstractChatRoom
::
State
s
tate
)
=
0
;
virtual
void
sendChatMessage
(
const
std
::
shared_ptr
<
ChatMessage
>
&
chatMessage
)
=
0
;
...
...
src/chat/chat-room/chat-room-p.h
View file @
f319f5cf
...
...
@@ -47,7 +47,7 @@ public:
this
->
lastUpdateTime
=
lastUpdateTime
;
}
void
setState
(
ChatRoom
::
State
newS
tate
)
override
;
void
setState
(
ChatRoom
::
State
s
tate
)
override
;
void
sendChatMessage
(
const
std
::
shared_ptr
<
ChatMessage
>
&
chatMessage
)
override
;
void
sendIsComposingNotification
();
...
...
@@ -67,10 +67,10 @@ public:
std
::
shared_ptr
<
IsComposingMessage
>
createIsComposingMessage
();
std
::
list
<
std
::
shared_ptr
<
ChatMessage
>>
findChatMessages
(
const
std
::
string
&
messageId
)
const
;
void
sendDeliveryErrorNotification
(
const
std
::
shared_ptr
<
ChatMessage
>
&
chatM
essage
,
LinphoneReason
reason
);
void
sendDeliveryNotification
(
const
std
::
shared_ptr
<
ChatMessage
>
&
chatM
essage
);
void
sendDeliveryErrorNotification
(
const
std
::
shared_ptr
<
ChatMessage
>
&
m
essage
,
LinphoneReason
reason
);
void
sendDeliveryNotification
(
const
std
::
shared_ptr
<
ChatMessage
>
&
m
essage
);
void
sendDeliveryNotifications
()
override
;
void
sendDisplayNotification
(
const
std
::
shared_ptr
<
ChatMessage
>
&
chatM
essage
);
bool
sendDisplayNotification
(
const
std
::
shared_ptr
<
ChatMessage
>
&
m
essage
);
void
notifyChatMessageReceived
(
const
std
::
shared_ptr
<
ChatMessage
>
&
chatMessage
)
override
;
void
notifyIsComposingReceived
(
const
Address
&
remoteAddress
,
bool
isComposing
);
...
...
src/chat/chat-room/chat-room.cpp
View file @
f319f5cf
...
...
@@ -38,9 +38,9 @@ LINPHONE_BEGIN_NAMESPACE
// -----------------------------------------------------------------------------
void
ChatRoomPrivate
::
setState
(
ChatRoom
::
State
newS
tate
)
{
if
(
state
!=
newS
tate
)
{
state
=
newS
tate
;
void
ChatRoomPrivate
::
setState
(
ChatRoom
::
State
s
tate
)
{
if
(
this
->
state
!=
s
tate
)
{
this
->
state
=
s
tate
;
notifyStateChanged
();
}
}
...
...
@@ -139,57 +139,38 @@ list<shared_ptr<ChatMessage>> ChatRoomPrivate::findChatMessages (const string &m
// -----------------------------------------------------------------------------
void
ChatRoomPrivate
::
sendDeliveryErrorNotification
(
const
shared_ptr
<
ChatMessage
>
&
chatMessage
,
LinphoneReason
reason
)
{
LinphoneImNotifPolicy
*
policy
=
linphone_core_get_im_notif_policy
(
chatMessage
->
getCore
()
->
getCCore
());
ChatMessagePrivate
*
dChatMessage
=
chatMessage
->
getPrivate
();
if
(
linphone_im_notif_policy_get_send_imdn_delivered
(
policy
)
&&
chatMessage
->
getPrivate
()
->
getNegativeDeliveryNotificationRequired
()
)
{
dChatMessage
->
setNegativeDeliveryNotificationRequired
(
false
);
imdnHandler
->
notifyDeliveryError
(
chatMessage
,
reason
);
}
void
ChatRoomPrivate
::
sendDeliveryErrorNotification
(
const
shared_ptr
<
ChatMessage
>
&
message
,
LinphoneReason
reason
)
{
L_Q
();
LinphoneImNotifPolicy
*
policy
=
linphone_core_get_im_notif_policy
(
q
->
getCore
()
->
getCCore
());
if
(
linphone_im_notif_policy_get_send_imdn_delivered
(
policy
))
imdnHandler
->
notifyDeliveryError
(
message
,
reason
);
}
void
ChatRoomPrivate
::
sendDeliveryNotification
(
const
shared_ptr
<
ChatMessage
>
&
chatMessage
)
{
LinphoneImNotifPolicy
*
policy
=
linphone_core_get_im_notif_policy
(
chatMessage
->
getCore
()
->
getCCore
());
ChatMessagePrivate
*
dChatMessage
=
chatMessage
->
getPrivate
();
if
(
linphone_im_notif_policy_get_send_imdn_delivered
(
policy
)
&&
dChatMessage
->
getPositiveDeliveryNotificationRequired
()
)
{
dChatMessage
->
setPositiveDeliveryNotificationRequired
(
false
);
imdnHandler
->
notifyDelivery
(
chatMessage
);
}
void
ChatRoomPrivate
::
sendDeliveryNotification
(
const
shared_ptr
<
ChatMessage
>
&
message
)
{
L_Q
();
LinphoneImNotifPolicy
*
policy
=
linphone_core_get_im_notif_policy
(
q
->
getCore
()
->
getCCore
());
if
(
linphone_im_notif_policy_get_send_imdn_delivered
(
policy
))
imdnHandler
->
notifyDelivery
(
message
);
}
void
ChatRoomPrivate
::
sendDeliveryNotifications
()
{
L_Q
();
LinphoneImNotifPolicy
*
policy
=
linphone_core_get_im_notif_policy
(
q
->
getCore
()
->
getCCore
());
if
(
linphone_im_notif_policy_get_send_imdn_delivered
(
policy
))
{
auto
chatMessages
=
q
->
getCore
()
->
getPrivate
()
->
mainDb
->
findChatMessagesToBeNotifiedAsDelivered
(
q
->
getChatRoomId
());
for
(
const
auto
&
chatMessage
:
chatMessages
)
{
ChatMessagePrivate
*
dChatMessage
=
chatMessage
->
getPrivate
();
if
(
dChatMessage
->
getPositiveDeliveryNotificationRequired
())
{
dChatMessage
->
setPositiveDeliveryNotificationRequired
(
false
);
imdnHandler
->
notifyDelivery
(
chatMessage
);
}
}
auto
messages
=
q
->
getCore
()
->
getPrivate
()
->
mainDb
->
findChatMessagesToBeNotifiedAsDelivered
(
q
->
getChatRoomId
());
for
(
const
auto
message
:
messages
)
imdnHandler
->
notifyDelivery
(
message
);
}
}
void
ChatRoomPrivate
::
sendDisplayNotification
(
const
shared_ptr
<
ChatMessage
>
&
chatM
essage
)
{
bool
ChatRoomPrivate
::
sendDisplayNotification
(
const
shared_ptr
<
ChatMessage
>
&
m
essage
)
{
L_Q
();
LinphoneImNotifPolicy
*
policy
=
linphone_core_get_im_notif_policy
(
q
->
getCore
()
->
getCCore
());
ChatMessagePrivate
*
dChatMessage
=
chatMessage
->
getPrivate
();
if
(
linphone_im_notif_policy_get_send_imdn_displayed
(
policy
)
&&
chatMessage
->
getPrivate
()
->
getDisplayNotificationRequired
()
)
{
dChatMessage
->
setPositiveDeliveryNotificationRequired
(
false
);
dChatMessage
->
setDisplayNotificationRequired
(
false
);
imdnHandler
->
notifyDisplay
(
chatMessage
);
if
(
linphone_im_notif_policy_get_send_imdn_displayed
(
policy
))
{
imdnHandler
->
notifyDisplay
(
message
);
return
imdnHandler
->
aggregationEnabled
();
}
return
false
;
}
// -----------------------------------------------------------------------------
...
...
@@ -448,7 +429,11 @@ int ChatRoom::getChatMessageCount () const {
}
int
ChatRoom
::
getUnreadChatMessageCount
()
const
{
return
getCore
()
->
getPrivate
()
->
mainDb
->
getUnreadChatMessageCount
(
getChatRoomId
());
L_D
();
int
dbUnreadCount
=
getCore
()
->
getPrivate
()
->
mainDb
->
getUnreadChatMessageCount
(
getChatRoomId
());
int
notifiedCount
=
d
->
imdnHandler
->
getDisplayNotificationCount
();
L_ASSERT
(
dbUnreadCount
>=
notifiedCount
);
return
dbUnreadCount
-
notifiedCount
;
}
// -----------------------------------------------------------------------------
...
...
@@ -514,11 +499,21 @@ shared_ptr<ChatMessage> ChatRoom::findChatMessage (const string &messageId, Chat
void
ChatRoom
::
markAsRead
()
{
L_D
();
bool
globallyMarkAsReadInDb
=
true
;
CorePrivate
*
dCore
=
getCore
()
->
getPrivate
();
for
(
auto
&
chatMessage
:
dCore
->
mainDb
->
getUnreadChatMessages
(
d
->
chatRoomId
))
chatMessage
->
getPrivate
()
->
setState
(
ChatMessage
::
State
::
Displayed
);
for
(
auto
&
chatMessage
:
dCore
->
mainDb
->
getUnreadChatMessages
(
d
->
chatRoomId
))
{
// Do not send display notification for file transfer until it has been downloaded (it won't have a file transfer content anymore)
if
(
!
chatMessage
->
getPrivate
()
->
hasFileTransferContent
())
{
bool
doNotStoreInDb
=
d
->
sendDisplayNotification
(
chatMessage
);
// Force the state so it is stored directly in DB, but when the IMDN has successfully been delivered
chatMessage
->
getPrivate
()
->
setState
(
ChatMessage
::
State
::
Displayed
,
doNotStoreInDb
);
if
(
doNotStoreInDb
)
globallyMarkAsReadInDb
=
false
;
}
}
dCore
->
mainDb
->
markChatMessagesAsRead
(
d
->
chatRoomId
);
if
(
globallyMarkAsReadInDb
)
dCore
->
mainDb
->
markChatMessagesAsRead
(
d
->
chatRoomId
);
}
LINPHONE_END_NAMESPACE
src/chat/notification/imdn.cpp
View file @
f319f5cf
...
...
@@ -17,7 +17,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include
"linphone/utils/
algorithm
.h"
#include
<
algorithm
>
#include "chat/chat-message/imdn-message-p.h"
#include "chat/chat-room/chat-room-p.h"
...
...
@@ -47,19 +47,24 @@ Imdn::~Imdn () {
// -----------------------------------------------------------------------------
int
Imdn
::
getDisplayNotificationCount
()
const
{
return
static_cast
<
int
>
(
displayedMessages
.
size
());
}
// -----------------------------------------------------------------------------
void
Imdn
::
notifyDelivery
(
const
shared_ptr
<
ChatMessage
>
&
message
)
{
if
(
find
(
deliveredMessages
,
message
)
==
deliveredMessages
.
end
())
{
if
(
find
(
deliveredMessages
.
begin
(),
deliveredMessages
.
end
()
,
message
)
==
deliveredMessages
.
end
())
{
deliveredMessages
.
push_back
(
message
);
startTimer
();
}
}
void
Imdn
::
notifyDeliveryError
(
const
shared_ptr
<
ChatMessage
>
&
message
,
LinphoneReason
reason
)
{
if
(
findIf
(
nonDeliveredMessages
,
[
message
](
const
MessageReason
&
mr
)
{
return
message
==
mr
.
message
;
})
==
nonDeliveredMessages
.
end
()
)
{
auto
it
=
find_if
(
nonDeliveredMessages
.
begin
(),
nonDeliveredMessages
.
end
(),
[
message
](
const
MessageReason
mr
)
{
return
message
==
mr
.
message
;
});
if
(
it
==
nonDeliveredMessages
.
end
())
{
nonDeliveredMessages
.
emplace_back
(
message
,
reason
);
startTimer
();
}
...
...
@@ -82,18 +87,14 @@ void Imdn::onImdnMessageDelivered (const std::shared_ptr<ImdnMessage> &message)
// If an IMDN has been successfully delivered, remove it from the list so that
// it does not get sent again
auto
context
=
message
->
getPrivate
()
->
getContext
();
for
(
const
auto
&
chatMessage
:
context
.
deliveredMessages
)
{
chatMessage
->
getPrivate
()
->
disableDeliveryNotificationRequiredInDatabase
();
deliveredMessages
.
remove
(
chatMessage
);
}
for
(
const
auto
&
deliveredMsg
:
context
.
deliveredMessages
)
deliveredMessages
.
remove
(
deliveredMsg
);
for
(
const
auto
&
chatMessage
:
context
.
displayedMessages
)
{
chatMessage
->
getPrivate
()
->
disableDisplayNotificationRequiredInDatabase
();
displayedMessages
.
remove
(
chatMessage
);
}
for
(
const
auto
&
displayedMsg
:
context
.
displayedMessages
)
displayedMessages
.
remove
(
displayedMsg
);
for
(
const
auto
&
chatMessage
:
context
.
nonDeliveredMessages
)
nonDeliveredMessages
.
remove
(
chatMessage
);
for
(
const
auto
&
nonDeliveredMsg
:
context
.
nonDeliveredMessages
)
nonDeliveredMessages
.
remove
(
nonDeliveredMsg
);
sentImdnMessages
.
remove
(
message
);
}
...
...
src/chat/notification/imdn.h
View file @
f319f5cf
...
...
@@ -57,6 +57,8 @@ public:
Imdn
(
ChatRoom
*
chatRoom
);
~
Imdn
();
int
getDisplayNotificationCount
()
const
;
void
notifyDelivery
(
const
std
::
shared_ptr
<
ChatMessage
>
&
message
);
void
notifyDeliveryError
(
const
std
::
shared_ptr
<
ChatMessage
>
&
message
,
LinphoneReason
reason
);
void
notifyDisplay
(
const
std
::
shared_ptr
<
ChatMessage
>
&
message
);
...
...
src/db/main-db.cpp
View file @
f319f5cf
...
...
@@ -618,7 +618,7 @@ shared_ptr<EventLog> MainDbPrivate::selectConferenceChatMessageEvent (
// This is necessary if linphone has crashed while sending a message. It will set the correct state so the user can resend it.
if
(
messageState
==
ChatMessage
::
State
::
Idle
||
messageState
==
ChatMessage
::
State
::
InProgress
)
messageState
=
ChatMessage
::
State
::
NotDelivered
;
dChatMessage
->
force
State
(
messageState
);
dChatMessage
->
set
State
(
messageState
,
true
);
dChatMessage
->
forceFromAddress
(
IdentityAddress
(
row
.
get
<
string
>
(
3
)));
dChatMessage
->
forceToAddress
(
IdentityAddress
(
row
.
get
<
string
>
(
4
)));
...
...
@@ -2179,7 +2179,7 @@ list<shared_ptr<ChatMessage>> MainDb::findChatMessagesToBeNotifiedAsDelivered (
const
ChatRoomId
&
chatRoomId
)
const
{
static
const
string
query
=
Statements
::
get
(
Statements
::
SelectConferenceEvents
)
+
string
(
" AND direction = :direction AND delivery_notification_required <> 0"
);
string
(
" AND direction = :direction AND
state = :state AND
delivery_notification_required <> 0"
);
DurationLogger
durationLogger
(
"Find chat messages to be notified as delivered: (peer="
+
chatRoomId
.
getPeerAddress
().
asString
()
+
...
...
@@ -2195,9 +2195,10 @@ list<shared_ptr<ChatMessage>> MainDb::findChatMessagesToBeNotifiedAsDelivered (
return
chatMessages
;
const
long
long
&
dbChatRoomId
=
d
->
selectChatRoomId
(
chatRoomId
);
const
int
&
state
=
int
(
ChatMessage
::
State
::
Delivered
);
const
int
&
direction
=
int
(
ChatMessage
::
Direction
::
Incoming
);
soci
::
rowset
<
soci
::
row
>
rows
=
(
d
->
dbSession
.
getBackendSession
()
->
prepare
<<
query
,
soci
::
use
(
dbChatRoomId
),
soci
::
use
(
direction
)
d
->
dbSession
.
getBackendSession
()
->
prepare
<<
query
,
soci
::
use
(
dbChatRoomId
),
soci
::
use
(
direction
)
,
soci
::
use
(
state
)
);
for
(
const
auto
&
row
:
rows
)
{
shared_ptr
<
EventLog
>
event
=
d
->
selectGenericConferenceEvent
(
chatRoom
,
row
);
...
...
@@ -2288,36 +2289,6 @@ int MainDb::getHistorySize (const ChatRoomId &chatRoomId, FilterMask mask) const
};
}
void
MainDb
::
cleanHistory
(
const
ChatRoomId
&
chatRoomId
,
FilterMask
mask
)
{
const
string
query
=
"SELECT event_id FROM conference_event WHERE chat_room_id = :chatRoomId"
+
buildSqlEventFilter
({
ConferenceCallFilter
,
ConferenceChatMessageFilter
,
ConferenceInfoFilter
,
ConferenceInfoNoDeviceFilter
},
mask
);
DurationLogger
durationLogger
(
"Clean history of: (peer="
+
chatRoomId
.
getPeerAddress
().
asString
()
+
", local="
+
chatRoomId
.
getLocalAddress
().
asString
()
+
", mask="
+
Utils
::
toString
(
mask
)
+
")."
);
L_DB_TRANSACTION
{
L_D
();
const
long
long
&
dbChatRoomId
=
d
->
selectChatRoomId
(
chatRoomId
);
d
->
invalidConferenceEventsFromQuery
(
query
,
dbChatRoomId
);
*
d
->
dbSession
.
getBackendSession
()
<<
"DELETE FROM event WHERE id IN ("
+
query
+
")"
,
soci
::
use
(
dbChatRoomId
);
tr
.
commit
();
if
(
!
mask
||
(
mask
&
ConferenceChatMessageFilter
))
d
->
unreadChatMessageCountCache
.
insert
(
chatRoomId
,
0
);
};
}
// -----------------------------------------------------------------------------
template
<
typename
T
>
static
void
fetchContentAppData
(
soci
::
session
*
session
,
Content
&
content
,
long
long
contentId
,
T
&
data
)
{
static
const
string
query
=
"SELECT name, data FROM chat_message_content_app_data"
...
...
@@ -2394,30 +2365,30 @@ void MainDb::loadChatMessageContents (const shared_ptr<ChatMessage> &chatMessage
};
}
// -----------------------------------------------------------------------------
void
MainDb
::
cleanHistory
(
const
ChatRoomId
&
chatRoomId
,
FilterMask
mask
)
{
const
string
query
=
"SELECT event_id FROM conference_event WHERE chat_room_id = :chatRoomId"
+
buildSqlEventFilter
({
ConferenceCallFilter
,
ConferenceChatMessageFilter
,
ConferenceInfoFilter
,
ConferenceInfoNoDeviceFilter
},
mask
);
void
MainDb
::
disableDeliveryNotificationRequired
(
const
std
::
shared_ptr
<
const
EventLog
>
&
eventLog
)
{
shared_ptr
<
ChatMessage
>
chatMessage
(
static_pointer_cast
<
const
ConferenceChatMessageEvent
>
(
eventLog
)
->
getChatMessage
());
const
long
long
&
eventId
=
static_cast
<
MainDbKey
&>
(
eventLog
->
getPrivate
()
->
dbKey
).
getPrivate
()
->
storageId
;
DurationLogger
durationLogger
(
"Clean history of: (peer="
+
chatRoomId
.
getPeerAddress
().
asString
()
+
", local="
+
chatRoomId
.
getLocalAddress
().
asString
()
+
", mask="
+
Utils
::
toString
(
mask
)
+
")."
);
L_DB_TRANSACTION
{
L_D
();
*
d
->
dbSession
.
getBackendSession
()
<<
"UPDATE conference_chat_message_event SET delivery_notification_required = 0"
" WHERE event_id = :eventId"
,
soci
::
use
(
eventId
);
tr
.
commit
();
};
}
void
MainDb
::
disableDisplayNotificationRequired
(
const
std
::
shared_ptr
<
const
EventLog
>
&
eventLog
)
{
shared_ptr
<
ChatMessage
>
chatMessage
(
static_pointer_cast
<
const
ConferenceChatMessageEvent
>
(
eventLog
)
->
getChatMessage
());
const
long
long
&
eventId
=
static_cast
<
MainDbKey
&>
(
eventLog
->
getPrivate
()
->
dbKey
).
getPrivate
()
->
storageId
;
const
long
long
&
dbChatRoomId
=
d
->
selectChatRoomId
(
chatRoomId
);
d
->
invalidConferenceEventsFromQuery
(
query
,
dbChatRoomId
);
*
d
->
dbSession
.
getBackendSession
()
<<
"DELETE FROM event WHERE id IN ("
+
query
+
")"
,
soci
::
use
(
dbChatRoomId
);
L_DB_TRANSACTION
{
L_D
();
*
d
->
dbSession
.
getBackendSession
()
<<
"UPDATE conference_chat_message_event"
" SET delivery_notification_required = 0, display_notification_required = 0"
" WHERE event_id = :eventId"
,
soci
::
use
(
eventId
);
tr
.
commit
();
if
(
!
mask
||
(
mask
&
ConferenceChatMessageFilter
))
d
->
unreadChatMessageCountCache
.
insert
(
chatRoomId
,
0
);
};
}
...
...
src/db/main-db.h
View file @
f319f5cf
...
...
@@ -156,9 +156,6 @@ public:
void
loadChatMessageContents
(
const
std
::
shared_ptr
<
ChatMessage
>
&
chatMessage
);
void
disableDeliveryNotificationRequired
(
const
std
::
shared_ptr
<
const
EventLog
>
&
eventLog
);
void
disableDisplayNotificationRequired
(
const
std
::
shared_ptr
<
const
EventLog
>
&
eventLog
);
// ---------------------------------------------------------------------------
// Chat rooms.
// ---------------------------------------------------------------------------
...
...
Ronan
@Abhamon
mentioned in commit
498b28ee
·
Sep 20, 2018
mentioned in commit
498b28ee
mentioned in commit 498b28ee70152f3844a30cea5c4f7a0a8cfdebec
Toggle commit list
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