conversation: update info after accepting a request
Change-Id: I43f7aa79c15f515878627d3d194f48a9b3bff241
diff --git a/Ring/Ring/Features/Conversations/Conversation/ConversationViewModel.swift b/Ring/Ring/Features/Conversations/Conversation/ConversationViewModel.swift
index dc0c4e4..b629b3b 100644
--- a/Ring/Ring/Features/Conversations/Conversation/ConversationViewModel.swift
+++ b/Ring/Ring/Features/Conversations/Conversation/ConversationViewModel.swift
@@ -173,22 +173,8 @@
}
self.subscribePresenceServiceContactPresence()
- if conversation.value.isSwarm() && self.swarmInfo == nil && !self.conversation.value.id.isEmpty {
- self.swarmInfo = SwarmInfo(injectionBag: self.injectionBag, conversation: self.conversation.value)
- self.swarmInfo!.finalAvatar.share()
- .observe(on: MainScheduler.instance)
- .subscribe { [weak self] image in
- self?.profileImageData.accept(image.pngData())
- } onError: { _ in
- }
- .disposed(by: self.disposeBag)
- self.swarmInfo!.finalTitle.share()
- .observe(on: MainScheduler.instance)
- .subscribe { [weak self] name in
- self?.userName.accept(name)
- } onError: { _ in
- }
- .disposed(by: self.disposeBag)
+ if self.shouldCreateSwarmInfo() {
+ self.createSwarmInfo()
} else {
let filterParicipants = conversation.value.getParticipants()
if let participantId = filterParicipants.first?.jamiId,
@@ -207,6 +193,11 @@
self.subscribeUserServiceLookupStatus()
self.nameService.lookupAddress(withAccount: self.conversation.value.accountId, nameserver: "", address: filterParicipants.first?.jamiId ?? "")
}
+ /*
+ By default, a conversation is created as non-swarm. Upon receiving the conversationReady
+ notification, we need to verify whether it is a swarm or not
+ */
+ subscribeConversationReady()
}
subscribeLastMessagesUpdate()
subscribeConversationSynchronization()
@@ -230,6 +221,46 @@
.disposed(by: self.disposeBag)
}
+ private func subscribeConversationReady() {
+ self.conversationsService.conversationReady
+ .subscribe { [weak self] conversationId in
+ guard let self = self else { return }
+ /*
+ Check if the conversation, originally created as non-swarm,
+ becomes a swarm after an update. If so, update the relevant information.
+ */
+ if conversationId == self.conversation.value.id {
+ if self.shouldCreateSwarmInfo() {
+ self.createSwarmInfo()
+ }
+ }
+ } onError: { _ in
+ }
+ .disposed(by: self.disposeBag)
+ }
+
+ func shouldCreateSwarmInfo() -> Bool {
+ return self.conversation.value.isSwarm() && self.swarmInfo == nil && !self.conversation.value.id.isEmpty
+ }
+
+ func createSwarmInfo() {
+ self.swarmInfo = SwarmInfo(injectionBag: self.injectionBag, conversation: self.conversation.value)
+ self.swarmInfo!.finalAvatar.share()
+ .observe(on: MainScheduler.instance)
+ .subscribe { [weak self] image in
+ self?.profileImageData.accept(image.pngData())
+ } onError: { _ in
+ }
+ .disposed(by: self.disposeBag)
+ self.swarmInfo!.finalTitle.share()
+ .observe(on: MainScheduler.instance)
+ .subscribe { [weak self] name in
+ self?.displayName.accept(name)
+ } onError: { _ in
+ }
+ .disposed(by: self.disposeBag)
+ }
+
private func subscribeNonSwarmProfiles(uri: String, accountId: String) {
self.profileService
.getProfile(uri: uri, createIfNotexists: false, accountId: accountId)
diff --git a/Ring/Ring/Models/ConversationModel.swift b/Ring/Ring/Models/ConversationModel.swift
index bbc91fc..69b583d 100644
--- a/Ring/Ring/Models/ConversationModel.swift
+++ b/Ring/Ring/Models/ConversationModel.swift
@@ -225,6 +225,7 @@
if let hash = info[ConversationAttributes.title.rawValue], !hash.isEmpty {
self.hash = hash
}
+ updateProfile(profile: info)
if let type = info[ConversationAttributes.mode.rawValue],
let typeInt = Int(type),
let conversationType = ConversationType(rawValue: typeInt) {
diff --git a/Ring/Ring/Services/ConversationsService.swift b/Ring/Ring/Services/ConversationsService.swift
index b466948..e904e8f 100644
--- a/Ring/Ring/Services/ConversationsService.swift
+++ b/Ring/Ring/Services/ConversationsService.swift
@@ -382,7 +382,6 @@
if let info = conversationsAdapter.getConversationInfo(forAccount: accountId, conversationId: conversationId) as? [String: String],
let participantsInfo = conversationsAdapter.getConversationMembers(accountId, conversationId: conversationId) {
conversation.updateInfo(info: info)
- // let conversation = ConversationModel(withId: conversationId, accountId: accountId, info: info)
if let prefsInfo = getConversationPreferences(accountId: accountId, conversationId: conversationId) {
conversation.updatePreferences(preferences: prefsInfo)
}