swarm: fix duplicate participants in swarminfo
This patch removes duplicate participants in
swarminfo when we create swarm for the first time
Change-Id: I74fb12586b7c5adfd157053ce7497da882a1bf2f
diff --git a/Ring/Ring/SwarmInfo.swift b/Ring/Ring/SwarmInfo.swift
index c3ad39d..df2c2c5 100644
--- a/Ring/Ring/SwarmInfo.swift
+++ b/Ring/Ring/SwarmInfo.swift
@@ -184,34 +184,6 @@
self.insertAndSortContacts(contacts: contactsInfo)
}
- func addContactToParticipantsList(jamiId: String, role: ParticipantRole) {
- // remove from contacts list
- var contactsValue = contacts.value
- if let index = contactsValue.firstIndex(where: { contactInfo in
- contactInfo.jamiId == jamiId
- }) {
- contactsValue.remove(at: index)
- contacts.accept(contactsValue)
- }
- // add to participants list
- guard let participantInfo = createParticipant(jamiId: jamiId, role: role) else { return }
- insertAndSortParticipants(participants: [participantInfo])
- }
-
- func addContactToParticipantsList(participantInfo: ParticipantInfo, role: ParticipantRole) {
- // remove from contacts list
- var contactsValue = contacts.value
- if let index = contactsValue.firstIndex(where: { contactInfo in
- contactInfo.jamiId == participantInfo.jamiId
- }) {
- contactsValue.remove(at: index)
- contacts.accept(contactsValue.sorted(by: { $0.name.value > $1.name.value }))
- }
- // add to participants list
- participantInfo.role = role
- insertAndSortParticipants(participants: [participantInfo])
- }
-
private func subscribeParticipantsInfo() {
tempBag = DisposeBag()
let namesObservable = participants.value
@@ -366,7 +338,7 @@
}
private func insertAndSortParticipants(participants: [ParticipantInfo]) {
- var currentValue = self.participants.value
+ var currentValue = [ParticipantInfo]()
currentValue.append(contentsOf: participants)
currentValue = currentValue.filter({ [.invited, .member, .admin].contains($0.role) })
currentValue.sort { participant1, participant2 in