Commit d53bb79b authored by Andreas Traczyk's avatar Andreas Traczyk Committed by Kateryna Kostiuk

conversations: prevents received messages from reverting status

- Message engine will cause erroneous status updates
  to SENDING or FAILURE for messages already SENT or READ. This
  patch treats these cases client side.

Change-Id: Icd5df2728bb83f8a4ba193f653e12f68935aa4bd
Reviewed-by: Kateryna Kostiuk's avatarKateryna Kostiuk <kateryna.kostiuk@savoirfairelinux.com>
parent 719b1b80
...@@ -68,9 +68,10 @@ class ConversationsService: MessagesAdapterDelegate { ...@@ -68,9 +68,10 @@ class ConversationsService: MessagesAdapterDelegate {
*/ */
for conversation in results.toArray() { for conversation in results.toArray() {
for message in (conversation.messages) { for message in (conversation.messages) {
if message.id != "" && (message.status == .unknown || message.status == .sending ) { if !message.id.isEmpty && (message.status == .unknown || message.status == .sending ) {
let updatedMessageStatus = self.status(forMessageId: message.id) let updatedMessageStatus = self.status(forMessageId: message.id)
if updatedMessageStatus != message.status { if (updatedMessageStatus.rawValue > message.status.rawValue && updatedMessageStatus != .failure) ||
(updatedMessageStatus == .failure && message.status == .sending) {
self.setMessageStatus(withMessage: message, withStatus: updatedMessageStatus) self.setMessageStatus(withMessage: message, withStatus: updatedMessageStatus)
.subscribe(onCompleted: { [] in .subscribe(onCompleted: { [] in
print("Message status updated - load") print("Message status updated - load")
...@@ -268,7 +269,9 @@ class ConversationsService: MessagesAdapterDelegate { ...@@ -268,7 +269,9 @@ class ConversationsService: MessagesAdapterDelegate {
//Find message //Find message
if let message = conversation?.messages.filter({ messages in if let message = conversation?.messages.filter({ messages in
return !messages.id.isEmpty && messages.id == String(messageId) && messages.status != status return !messages.id.isEmpty && messages.id == String(messageId) &&
((status.rawValue > messages.status.rawValue && status != .failure) ||
(status == .failure && messages.status == .sending))
}).first { }).first {
self.setMessageStatus(withMessage: message, self.setMessageStatus(withMessage: message,
withStatus: status) withStatus: status)
......
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