Commit 02dacd7b authored by Kateryna Kostiuk's avatar Kateryna Kostiuk Committed by Andreas Traczyk

conversation: remove when contact is discarded

Remove conversation that contain only generated messages when contact
request is discarded

Change-Id: Ib7c393c658013780f1a8bf8a20c40f87a40b563c
Reviewed-by: Andreas Traczyk's avatarAndreas Traczyk <andreas.traczyk@savoirfairelinux.com>
parent 6f9ee90f
......@@ -85,6 +85,12 @@ class ContactRequestManager {
type = GeneratedMessageType.sendContactRequest
case ServiceEventType.contactRequestReceived:
type = GeneratedMessageType.receivedContactRequest
case ServiceEventType.contactRequestDiscarded:
self.removeConversation(accountId: account.id,
accountRingId: ringId,
contactRingId: contactRingId,
shouldUpdateConversation: shouldUpdateConversations)
return
default:
return
}
......@@ -99,4 +105,20 @@ class ContactRequestManager {
})
.disposed(by: disposeBag)
}
private func removeConversation(accountId: String, accountRingId: String,
contactRingId: String,
shouldUpdateConversation: Bool) {
guard let conversation = self.conversationService.findConversation(withRingId: contactRingId, withAccountId: accountId) else {
return
}
// remove conversation if it contain only generated messages
let messagesNotGenerated = conversation.messages.filter({!$0.isGenerated})
if !messagesNotGenerated.isEmpty {
return
}
self.conversationService.deleteConversation(conversation: conversation)
}
}
......@@ -127,6 +127,10 @@ class ContactsService {
self.removeContactRequest(withRingId: contactRequest.ringId)
if success {
var event = ServiceEvent(withEventType: .contactRequestDiscarded)
event.addEventInput(.accountId, value: account.id)
event.addEventInput(.uri, value: contactRequest.ringId)
self.responseStream.onNext(event)
observable.on(.completed)
} else {
observable.on(.error(ContactServiceError.diacardTrusRequestFailed))
......
......@@ -35,6 +35,7 @@ enum ServiceEventType {
case contactAdded
case contactRequestSended
case contactRequestReceived
case contactRequestDiscarded
}
/**
......
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