forked from mirrors/linphone-iphone
Replace publisher with delegate in AccountModel
This commit is contained in:
parent
70267b6d3b
commit
3261cebd5f
2 changed files with 29 additions and 19 deletions
|
|
@ -166,7 +166,7 @@ final class CoreContext: ObservableObject {
|
|||
|
||||
var accountModels: [AccountModel] = []
|
||||
for account in self.mCore.accountList {
|
||||
accountModels.append(AccountModel(account: account, corePublisher: self.mCore.publisher))
|
||||
accountModels.append(AccountModel(account: account, core: self.mCore))
|
||||
}
|
||||
DispatchQueue.main.async {
|
||||
self.coreIsStarted = true
|
||||
|
|
@ -203,7 +203,7 @@ final class CoreContext: ObservableObject {
|
|||
Log.info("New configuration state is \(status) = \(message)\n")
|
||||
var accountModels: [AccountModel] = []
|
||||
for account in self.mCore.accountList {
|
||||
accountModels.append(AccountModel(account: account, corePublisher: self.mCore.publisher))
|
||||
accountModels.append(AccountModel(account: account, core: self.mCore))
|
||||
}
|
||||
DispatchQueue.main.async {
|
||||
if status == ConfiguringState.Successful {
|
||||
|
|
@ -281,7 +281,7 @@ final class CoreContext: ObservableObject {
|
|||
}, onAccountAdded: { (_: Core, _: Account) in
|
||||
var accountModels: [AccountModel] = []
|
||||
for account in self.mCore.accountList {
|
||||
accountModels.append(AccountModel(account: account, corePublisher: self.mCore.publisher))
|
||||
accountModels.append(AccountModel(account: account, core: self.mCore))
|
||||
}
|
||||
DispatchQueue.main.async {
|
||||
self.accounts = accountModels
|
||||
|
|
@ -289,7 +289,7 @@ final class CoreContext: ObservableObject {
|
|||
}, onAccountRemoved: { (_: Core, _: Account) in
|
||||
var accountModels: [AccountModel] = []
|
||||
for account in self.mCore.accountList {
|
||||
accountModels.append(AccountModel(account: account, corePublisher: self.mCore.publisher))
|
||||
accountModels.append(AccountModel(account: account, core: self.mCore))
|
||||
}
|
||||
DispatchQueue.main.async {
|
||||
self.accounts = accountModels
|
||||
|
|
|
|||
|
|
@ -31,32 +31,42 @@ class AccountModel: ObservableObject {
|
|||
@Published var displayName: String = ""
|
||||
@Published var address: String = ""
|
||||
|
||||
private var mSuscriptions = Set<AnyCancellable?>()
|
||||
private var accountDelegate: AccountDelegate?
|
||||
private var coreDelegate: CoreDelegate?
|
||||
|
||||
init(account: Account, corePublisher: CoreDelegatePublisher?) {
|
||||
init(account: Account, core: Core) {
|
||||
self.account = account
|
||||
|
||||
mSuscriptions.insert(account.publisher?.onRegistrationStateChanged?.postOnCoreQueue { _ in
|
||||
accountDelegate = AccountDelegateStub(onRegistrationStateChanged: { (_: Account, _: RegistrationState, _: String) in
|
||||
self.update()
|
||||
})
|
||||
mSuscriptions.insert(corePublisher?.onChatRoomRead?.postOnCoreQueue(
|
||||
receiveValue: { _ in
|
||||
self.computeNotificationsCount()
|
||||
}))
|
||||
mSuscriptions.insert(corePublisher?.onMessagesReceived?.postOnCoreQueue(
|
||||
receiveValue: { _ in
|
||||
self.computeNotificationsCount()
|
||||
}))
|
||||
mSuscriptions.insert(corePublisher?.onCallStateChanged?.postOnCoreQueue(
|
||||
receiveValue: { _ in
|
||||
self.computeNotificationsCount()
|
||||
}))
|
||||
account.addDelegate(delegate: accountDelegate!)
|
||||
|
||||
coreDelegate = CoreDelegateStub(onCallStateChanged: { (_: Core, _: Call, _: Call.State, _: String) in
|
||||
self.computeNotificationsCount()
|
||||
}, onMessagesReceived: { (_: Core, _: ChatRoom, _:[ChatMessage]) in
|
||||
self.computeNotificationsCount()
|
||||
}, onChatRoomRead: { (_: Core, _: ChatRoom) in
|
||||
self.computeNotificationsCount()
|
||||
})
|
||||
core.addDelegate(delegate: coreDelegate!)
|
||||
|
||||
CoreContext.shared.doOnCoreQueue { _ in
|
||||
self.update()
|
||||
}
|
||||
}
|
||||
|
||||
deinit {
|
||||
if let delegate = accountDelegate {
|
||||
account.removeDelegate(delegate: delegate)
|
||||
}
|
||||
if let delegate = coreDelegate {
|
||||
CoreContext.shared.doOnCoreQueue { core in
|
||||
core.removeDelegate(delegate: delegate)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func update() {
|
||||
let state = account.state
|
||||
var isDefault: Bool = false
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue