some cleaning up
This commit is contained in:
@@ -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,44 +235,44 @@ 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
|
||||||
|
//update convo in database to show that I left...if I am the last person, also close out the channel
|
||||||
|
|
||||||
self.firestoreService.updateUserStatus(userId: userId!, userStatus: .online) {[weak self] res in
|
// if I am the last one in the convo, then end the convo in the db
|
||||||
print(res)
|
if updatedConvo!.users.count == 1 && updatedConvo!.users[0] == userId {
|
||||||
|
updatedConvo!.state = .complete
|
||||||
|
updatedConvo!.endedTimestamp = Date()
|
||||||
|
}
|
||||||
|
|
||||||
|
let updatedUsers: [String] = updatedConvo!.users.filter{ arrUserId in
|
||||||
|
return arrUserId != userId
|
||||||
|
}
|
||||||
|
|
||||||
|
updatedConvo!.users = updatedUsers
|
||||||
|
|
||||||
|
self?.firestoreService.updateConvo(convo: updatedConvo!) {[weak self] res in
|
||||||
|
self?.selectedConvoId = nil
|
||||||
|
|
||||||
switch res {
|
print("left convo officially in our db as well")
|
||||||
case .success:
|
|
||||||
//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 updatedConvo!.users.count == 1 && updatedConvo!.users[0] == userId {
|
|
||||||
updatedConvo!.state = .complete
|
|
||||||
updatedConvo!.endedTimestamp = Date()
|
|
||||||
}
|
|
||||||
|
|
||||||
let updatedUsers: [String] = updatedConvo!.users.filter{ arrUserId in
|
|
||||||
return arrUserId != userId
|
|
||||||
}
|
|
||||||
|
|
||||||
updatedConvo!.users = updatedUsers
|
|
||||||
|
|
||||||
|
|
||||||
self?.firestoreService.updateConvo(convo: updatedConvo!) {[weak self] res in
|
|
||||||
self?.selectedConvoId = nil
|
|
||||||
|
|
||||||
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) {
|
||||||
|
|||||||
Reference in New Issue
Block a user