From 454601a13c16b610fa72865328c2e702dd8ffc7f Mon Sep 17 00:00:00 2001 From: talksik Date: Sat, 1 Jan 2022 22:06:00 -0800 Subject: [PATCH] cleaning up things --- nirvana-ios/Models/Convo.swift | 2 +- nirvana-ios/Views/Convos/ConvoViewModel.swift | 17 ++++++++--------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/nirvana-ios/Models/Convo.swift b/nirvana-ios/Models/Convo.swift index cd75d6e..5b8cd99 100644 --- a/nirvana-ios/Models/Convo.swift +++ b/nirvana-ios/Models/Convo.swift @@ -30,7 +30,7 @@ struct Convo: Identifiable, Codable { @ServerTimestamp var startedTimestamp: Date? var endedTimestamp: Date? - var receiverEndedTimestamp: Date? + var secondToLastUserEndedTimestamp: Date? } //struct DetailConvo: Convo { diff --git a/nirvana-ios/Views/Convos/ConvoViewModel.swift b/nirvana-ios/Views/Convos/ConvoViewModel.swift index d50de7b..96d0375 100644 --- a/nirvana-ios/Views/Convos/ConvoViewModel.swift +++ b/nirvana-ios/Views/Convos/ConvoViewModel.swift @@ -95,12 +95,12 @@ class ConvoViewModel: NSObject, ObservableObject { // if convo receiver is me and I'm not in a call or this call already, then join in if convo!.receiverUserId == userId && !(self?.isInCall())! - && convo!.receiverEndedTimestamp == nil { + && convo!.secondToLastUserEndedTimestamp == nil { print("I am the direct receiver...joining convo") self?.joinConvo(convo: convo!) } // if I am in a convo in which the last/loner has left, I need to leave the convo - else if convo!.receiverEndedTimestamp != nil && (self?.isInCall())! && convo!.users.contains(userId!) { + else if convo!.secondToLastUserEndedTimestamp != nil && (self?.isInCall())! && convo!.users.contains(userId!) { print("I am the last one now... ending the convo") self?.leaveConvo() } //also if I am added after a receiver was added and I am not already in a convo, then join the call @@ -305,7 +305,7 @@ class ConvoViewModel: NSObject, ObservableObject { updatedConvo!.endedTimestamp = Date() } // if I am second to last, the last guy is a loner else if updatedConvo!.users.count == 2 && updatedConvo!.users.contains(userId!) { - updatedConvo!.receiverEndedTimestamp = Date() + updatedConvo!.secondToLastUserEndedTimestamp = Date() } let updatedUsers: [String] = updatedConvo!.users.filter{ arrUserId in @@ -324,11 +324,7 @@ class ConvoViewModel: NSObject, ObservableObject { func destroyInstance() { AgoraRtcEngineKit.destroy() - } - - func joinedConvoCallback() { - - } + } } extension ConvoViewModel { @@ -417,7 +413,10 @@ extension ConvoViewModel: AgoraRtcEngineDelegate { case .success: // update convo in database users array to let them know I am in now - updatedConvo!.users.append(userId!) + // only add if I am not already in the users arr...if I was a third party, I should be in there already + if !updatedConvo!.users.contains(userId!) { + updatedConvo!.users.append(userId!) + } updatedConvo!.state = .active self?.firestoreService.updateConvo(convo: updatedConvo!) {[weak self] res in