some cleaning up

This commit is contained in:
talksik
2021-12-31 02:36:14 -08:00
parent 9ef95b3445
commit ca586f8331
+16 -18
View File
@@ -86,7 +86,7 @@ class ConvoViewModel: NSObject, ObservableObject {
continue continue
} }
// TODO: if convo receiver is me and I'm not in a call, then join in // TODO: 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())! { if convo!.receiverUserId == userId && !(self?.isInCall())! {
self?.joinConvo(convo: convo!) self?.joinConvo(convo: convo!)
} }
@@ -235,22 +235,29 @@ class ConvoViewModel: NSObject, ObservableObject {
return return
} }
self.firestoreService.getConvo(channelName: self.selectedConvoId!) {convo in self.firestoreService.updateUserStatus(userId: userId!, userStatus: .online) {[weak self] res in
print(res)
switch res {
case .success:
print("updated user status")
case .error(let error):
print(error)
default:
return
}
}
self.firestoreService.getConvo(channelName: self.selectedConvoId!) {[weak self] convo in
if convo == nil { if convo == nil {
print("no such convo found") print("no such convo found")
return return
} }
var updatedConvo = convo var updatedConvo = convo
self.firestoreService.updateUserStatus(userId: userId!, userStatus: .online) {[weak self] res in
print(res)
switch res {
case .success:
//update convo in database to show that I left...if I am the last person, also close out the channel //update convo in database to show that I left...if I am the last person, also close out the channel
// if I am the last one in the convo, then end the convo // if I am the last one in the convo, then end the convo in the db
if updatedConvo!.users.count == 1 && updatedConvo!.users[0] == userId { if updatedConvo!.users.count == 1 && updatedConvo!.users[0] == userId {
updatedConvo!.state = .complete updatedConvo!.state = .complete
updatedConvo!.endedTimestamp = Date() updatedConvo!.endedTimestamp = Date()
@@ -262,18 +269,11 @@ class ConvoViewModel: NSObject, ObservableObject {
updatedConvo!.users = updatedUsers updatedConvo!.users = updatedUsers
self?.firestoreService.updateConvo(convo: updatedConvo!) {[weak self] res in self?.firestoreService.updateConvo(convo: updatedConvo!) {[weak self] res in
self?.selectedConvoId = nil self?.selectedConvoId = nil
print("left convo officially in our db as well") print("left convo officially in our db as well")
} }
case .error(let error):
print(error)
default:
return
}
}
} }
} }
@@ -389,8 +389,6 @@ extension ConvoViewModel: AgoraRtcEngineDelegate {
// sound effect upon leaving // sound effect upon leaving
self.playLeaveAudioEffect(engine: engine) self.playLeaveAudioEffect(engine: engine)
print("properties in leave channel: \(self)")
} }
func rtcEngine(_ engine: AgoraRtcEngineKit, didJoinedOfUid uid: UInt, elapsed: Int) { func rtcEngine(_ engine: AgoraRtcEngineKit, didJoinedOfUid uid: UInt, elapsed: Int) {