diff --git a/Ring/Ring/Services/ContactRequestManager.swift b/Ring/Ring/Services/ContactRequestManager.swift index d96a6d3544b906b9b2a3407df39c72354800beaa..795054a24736598ab31033a091c145234be5d409 100644 --- a/Ring/Ring/Services/ContactRequestManager.swift +++ b/Ring/Ring/Services/ContactRequestManager.swift @@ -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) + } } diff --git a/Ring/Ring/Services/ContactsService.swift b/Ring/Ring/Services/ContactsService.swift index 424bd2d7d66a1d907e32105bf5035fa955a7ae2f..3a0526124e6a55d2ca89200ec855fca8a2cd8a0e 100644 --- a/Ring/Ring/Services/ContactsService.swift +++ b/Ring/Ring/Services/ContactsService.swift @@ -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)) diff --git a/Ring/Ring/Services/ServiceEvent.swift b/Ring/Ring/Services/ServiceEvent.swift index 047a2e26d58eccb0b2b22609fafe8de66b78ef48..76decfa681bb63c789247a81fa101adf145850ad 100644 --- a/Ring/Ring/Services/ServiceEvent.swift +++ b/Ring/Ring/Services/ServiceEvent.swift @@ -35,6 +35,7 @@ enum ServiceEventType { case contactAdded case contactRequestSended case contactRequestReceived + case contactRequestDiscarded } /**