mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-01-17 11:08:06 +00:00
Refresh calllogs list when receive callback
This commit is contained in:
parent
0142a9146b
commit
d7da763dae
3 changed files with 68 additions and 15 deletions
|
|
@ -25,6 +25,11 @@ struct LinphoneApp: App {
|
|||
@ObservedObject private var coreContext = CoreContext.shared
|
||||
@ObservedObject private var sharedMainViewModel = SharedMainViewModel.shared
|
||||
|
||||
@State private var contactViewModel: ContactViewModel?
|
||||
@State private var editContactViewModel: EditContactViewModel?
|
||||
@State private var historyViewModel: HistoryViewModel?
|
||||
@State private var historyListViewModel: HistoryListViewModel?
|
||||
|
||||
@State private var isActive = false
|
||||
|
||||
var body: some Scene {
|
||||
|
|
@ -34,16 +39,26 @@ struct LinphoneApp: App {
|
|||
WelcomeView()
|
||||
} else if coreContext.defaultAccount == nil || sharedMainViewModel.displayProfileMode {
|
||||
AssistantView()
|
||||
} else if coreContext.defaultAccount != nil {
|
||||
} else if coreContext.defaultAccount != nil
|
||||
&& contactViewModel != nil
|
||||
&& editContactViewModel != nil
|
||||
&& historyViewModel != nil
|
||||
&& historyListViewModel != nil {
|
||||
ContentView(
|
||||
contactViewModel: ContactViewModel(),
|
||||
editContactViewModel: EditContactViewModel(),
|
||||
historyViewModel: HistoryViewModel(),
|
||||
historyListViewModel: HistoryListViewModel()
|
||||
contactViewModel: contactViewModel!,
|
||||
editContactViewModel: editContactViewModel!,
|
||||
historyViewModel: historyViewModel!,
|
||||
historyListViewModel: historyListViewModel!
|
||||
)
|
||||
}
|
||||
} else {
|
||||
SplashScreen(isActive: $isActive)
|
||||
.onDisappear {
|
||||
contactViewModel = ContactViewModel()
|
||||
editContactViewModel = EditContactViewModel()
|
||||
historyViewModel = HistoryViewModel()
|
||||
historyListViewModel = HistoryListViewModel()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,8 +73,6 @@ struct HistoryContactFragment: View {
|
|||
Button {
|
||||
isMenuOpen = false
|
||||
|
||||
indexPage = 0
|
||||
|
||||
if ContactsManager.shared.getFriendWithAddress(
|
||||
address: historyViewModel.displayedCall != nil && historyViewModel.displayedCall!.dir == .Outgoing
|
||||
? historyViewModel.displayedCall!.toAddress!
|
||||
|
|
@ -87,11 +85,13 @@ struct HistoryContactFragment: View {
|
|||
let friendIndex = MagicSearchSingleton.shared.lastSearch.firstIndex(
|
||||
where: {$0.friend!.addresses.contains(where: {$0.asStringUriOnly() == addressCall.asStringUriOnly()})})
|
||||
if friendIndex != nil {
|
||||
|
||||
withAnimation {
|
||||
|
||||
withAnimation {
|
||||
historyViewModel.displayedCall = nil
|
||||
contactViewModel.indexDisplayedFriend = friendIndex
|
||||
}
|
||||
indexPage = 0
|
||||
|
||||
contactViewModel.indexDisplayedFriend = friendIndex
|
||||
}
|
||||
}
|
||||
} else {
|
||||
let addressCall = historyViewModel.displayedCall != nil && historyViewModel.displayedCall!.dir == .Outgoing
|
||||
|
|
@ -100,10 +100,12 @@ struct HistoryContactFragment: View {
|
|||
|
||||
withAnimation {
|
||||
historyViewModel.displayedCall = nil
|
||||
isShowEditContactFragment.toggle()
|
||||
editContactViewModel.sipAddresses.removeAll()
|
||||
editContactViewModel.sipAddresses.append(String(addressCall.asStringUriOnly().dropFirst(4)))
|
||||
editContactViewModel.sipAddresses.append("")
|
||||
indexPage = 0
|
||||
|
||||
isShowEditContactFragment.toggle()
|
||||
editContactViewModel.sipAddresses.removeAll()
|
||||
editContactViewModel.sipAddresses.append(String(addressCall.asStringUriOnly().dropFirst(4)))
|
||||
editContactViewModel.sipAddresses.append("")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -26,9 +26,12 @@ class HistoryListViewModel: ObservableObject {
|
|||
@Published var callLogs: [CallLog] = []
|
||||
var callLogsTmp: [CallLog] = []
|
||||
|
||||
@Published private var coreDelegate: CoreDelegate?
|
||||
|
||||
var callLogsAddressToDelete = ""
|
||||
|
||||
init() {
|
||||
removeAllDelegate()
|
||||
computeCallLogsList()
|
||||
}
|
||||
|
||||
|
|
@ -46,6 +49,29 @@ class HistoryListViewModel: ObservableObject {
|
|||
self.callLogsTmp.append(log)
|
||||
}
|
||||
}
|
||||
|
||||
DispatchQueue.main.async {
|
||||
self.coreDelegate = CoreDelegateStub(
|
||||
onCallLogUpdated: { (_: Core, _: CallLog) -> Void in
|
||||
DispatchQueue.main.async {
|
||||
let account = core.defaultAccount
|
||||
let logs = account?.callLogs != nil ? account!.callLogs : core.callLogs
|
||||
|
||||
self.callLogs.removeAll()
|
||||
self.callLogsTmp.removeAll()
|
||||
|
||||
logs.forEach { log in
|
||||
self.callLogs.append(log)
|
||||
self.callLogsTmp.append(log)
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
if self.coreDelegate != nil {
|
||||
core.addDelegate(delegate: self.coreDelegate!)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -184,4 +210,14 @@ class HistoryListViewModel: ObservableObject {
|
|||
let indexTmp = self.callLogsTmp.firstIndex(where: {$0.callId == callLog.callId})
|
||||
self.callLogsTmp.remove(at: indexTmp!)
|
||||
}
|
||||
|
||||
func removeAllDelegate() {
|
||||
coreContext.doOnCoreQueue { core in
|
||||
if self.coreDelegate != nil {
|
||||
core.removeDelegate(delegate: self.coreDelegate!)
|
||||
self.coreDelegate = nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue