Commit 266854a9 authored by Kateryna Kostiuk's avatar Kateryna Kostiuk

fix: smartlist multi account

Update conversation only when receive file transfer for current
account.

Change-Id: I120def876f773056388698feda8c8e7d34983575
parent eb4a2d48
...@@ -137,7 +137,8 @@ class SmartlistViewModel: Stateable, ViewModel { ...@@ -137,7 +137,8 @@ class SmartlistViewModel: Stateable, ViewModel {
lazy var conversations: Observable<[ConversationSection]> = { [unowned self] in lazy var conversations: Observable<[ConversationSection]> = { [unowned self] in
//get initial value //get initial value
DispatchQueue.main.asyncAfter(deadline: .now() + 0.01, execute: { DispatchQueue.main.asyncAfter(deadline: .now() + 0.01, execute: {
self.conversationsService.conversationsForCurrentAccount self.conversationsService
.conversationsForCurrentAccount
.observeOn(MainScheduler.instance) .observeOn(MainScheduler.instance)
.subscribe(onNext: { (conversations) in .subscribe(onNext: { (conversations) in
self.conversationsForCurrentAccount.onNext(conversations) self.conversationsForCurrentAccount.onNext(conversations)
......
...@@ -54,7 +54,8 @@ class ConversationsManager: MessagesAdapterDelegate { ...@@ -54,7 +54,8 @@ class ConversationsManager: MessagesAdapterDelegate {
}) })
.subscribe(onNext: { [unowned self] event in .subscribe(onNext: { [unowned self] event in
guard let transferId: UInt64 = event.getEventInput(ServiceEventInput.transferId), guard let transferId: UInt64 = event.getEventInput(ServiceEventInput.transferId),
let transferInfo = self.dataTransferService.getTransferInfo(withId: transferId) else { let transferInfo = self.dataTransferService.getTransferInfo(withId: transferId),
let currentAccount = self.accountsService.currentAccount else {
self.log.error("ConversationsManager: can't find transferInfo") self.log.error("ConversationsManager: can't find transferInfo")
return return
} }
...@@ -65,7 +66,8 @@ class ConversationsManager: MessagesAdapterDelegate { ...@@ -65,7 +66,8 @@ class ConversationsManager: MessagesAdapterDelegate {
.generateDataTransferMessage(transferId: transferId, .generateDataTransferMessage(transferId: transferId,
transferInfo: transferInfo, transferInfo: transferInfo,
accountId: transferInfo.accountId, accountId: transferInfo.accountId,
photoIdentifier: photoIdentifier) photoIdentifier: photoIdentifier,
updateConversation: currentAccount.id == transferInfo.accountId )
.subscribe(onCompleted: { .subscribe(onCompleted: {
guard let transferInfo = self.dataTransferService guard let transferInfo = self.dataTransferService
.getTransferInfo(withId: transferId) else {return} .getTransferInfo(withId: transferId) else {return}
......
...@@ -243,7 +243,8 @@ class ConversationsService { ...@@ -243,7 +243,8 @@ class ConversationsService {
func generateDataTransferMessage(transferId: UInt64, func generateDataTransferMessage(transferId: UInt64,
transferInfo: NSDataTransferInfo, transferInfo: NSDataTransferInfo,
accountId: String, accountId: String,
photoIdentifier: String?) -> Completable { photoIdentifier: String?,
updateConversation: Bool) -> Completable {
return Completable.create(subscribe: { [unowned self] completable in return Completable.create(subscribe: { [unowned self] completable in
...@@ -278,12 +279,15 @@ class ConversationsService { ...@@ -278,12 +279,15 @@ class ConversationsService {
self.dbManager.getConversationsObservable(for: accountId) self.dbManager.getConversationsObservable(for: accountId)
.subscribeOn(ConcurrentDispatchQueueScheduler(qos: .background)) .subscribeOn(ConcurrentDispatchQueueScheduler(qos: .background))
.subscribe(onNext: { conversationsModels in .subscribe(onNext: { conversationsModels in
self.conversations.value = conversationsModels if updateConversation {
self.messagesSemaphore.signal() self.conversations.value = conversationsModels
}
let serviceEventType: ServiceEventType = .dataTransferMessageUpdated let serviceEventType: ServiceEventType = .dataTransferMessageUpdated
var serviceEvent = ServiceEvent(withEventType: serviceEventType) var serviceEvent = ServiceEvent(withEventType: serviceEventType)
serviceEvent.addEventInput(.transferId, value: transferId) serviceEvent.addEventInput(.transferId, value: transferId)
self.responseStream.onNext(serviceEvent) self.responseStream.onNext(serviceEvent)
self.messagesSemaphore.signal()
completable(.completed) completable(.completed)
}) })
.disposed(by: (self.disposeBag)) .disposed(by: (self.disposeBag))
...@@ -413,42 +417,23 @@ class ConversationsService { ...@@ -413,42 +417,23 @@ class ConversationsService {
for transferId: UInt64, for transferId: UInt64,
accountId: String, accountId: String,
to uri: String) { to uri: String) {
guard let contactUri = JamiURI.init(schema: URIType.ring, infoHach: uri).uriString else {return}
self.messagesSemaphore.wait() self.messagesSemaphore.wait()
//Get conversations for this sender self.dbManager
let conversation = self.conversations.value.filter({ conversation in .updateTransferStatus(daemonID: String(transferId),
return conversation.participantUri == contactUri && withStatus: transferStatus,
conversation.accountId == accountId accountId: accountId)
}).first .subscribeOn(ConcurrentDispatchQueueScheduler(qos: .background))
.subscribe(onCompleted: { [unowned self] in
//Find message
if let messages: [MessageModel] = conversation?.messages.filter({ (message) -> Bool in
return message.daemonId == String(transferId)
}) {
if let message = messages.first {
self.dbManager
.updateTransferStatus(daemonID: message.daemonId,
withStatus: transferStatus,
accountId: accountId)
.subscribeOn(ConcurrentDispatchQueueScheduler(qos: .background))
.subscribe(onCompleted: { [unowned self] in
self.messagesSemaphore.signal()
self.log.info("ConversationService: transferStatusChanged - transfer status updated")
let serviceEventType: ServiceEventType = .dataTransferMessageUpdated
var serviceEvent = ServiceEvent(withEventType: serviceEventType)
serviceEvent.addEventInput(.transferId, value: transferId)
serviceEvent.addEventInput(.state, value: transferStatus)
self.responseStream.onNext(serviceEvent)
}, onError: { _ in
self.messagesSemaphore.signal()
})
.disposed(by: self.disposeBag)
} else {
self.log.error("ConversationService: transferStatusChanged - transfer not found")
self.messagesSemaphore.signal() self.messagesSemaphore.signal()
} self.log.info("ConversationService: transferStatusChanged - transfer status updated")
} else { let serviceEventType: ServiceEventType = .dataTransferMessageUpdated
self.messagesSemaphore.signal() var serviceEvent = ServiceEvent(withEventType: serviceEventType)
} serviceEvent.addEventInput(.transferId, value: transferId)
serviceEvent.addEventInput(.state, value: transferStatus)
self.responseStream.onNext(serviceEvent)
}, onError: { _ in
self.messagesSemaphore.signal()
})
.disposed(by: self.disposeBag)
} }
} }
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