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