allowing third party to join seamless pretty sweet
This commit is contained in:
@@ -94,15 +94,20 @@ class ConvoViewModel: NSObject, ObservableObject {
|
||||
}
|
||||
|
||||
// if convo receiver is me and I'm not in a call or this call already, then join in
|
||||
// TODO: also if I am added after a receiver was added, then join the call
|
||||
if convo!.receiverUserId == userId && !(self?.isInCall())!
|
||||
&& convo!.receiverEndedTimestamp == 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
|
||||
if convo!.receiverEndedTimestamp != nil && (self?.isInCall())! && convo!.users.contains(userId!) {
|
||||
else if convo!.receiverEndedTimestamp != 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
|
||||
else if convo!.users.contains(userId!) && !(self?.isInCall())! {
|
||||
// should be free or online and not in another call unless it's a race condition
|
||||
print("I was added onto the call because I was free...joining automatically")
|
||||
self?.joinConvo(convo: convo!)
|
||||
}
|
||||
|
||||
self?.allConvos.append(convo!)
|
||||
@@ -229,6 +234,31 @@ class ConvoViewModel: NSObject, ObservableObject {
|
||||
self.agoraKit?.joinChannel(byToken: convoAgoraToken, channelId: channelName, info: nil, uid: 0, joinSuccess: nil)
|
||||
}
|
||||
|
||||
func addThirdPartyToConvo(friendId: String) {
|
||||
// recheck if this other friend that I am adding is online/free
|
||||
|
||||
if !self.isInCall() {
|
||||
print("not in a call, can't invite/force someone else...must have a selected convo")
|
||||
return
|
||||
}
|
||||
|
||||
// get the currconvo details
|
||||
var convo = self.relevantConvos.first {convo in
|
||||
convo.id == self.selectedConvoId
|
||||
}
|
||||
if convo == nil {
|
||||
print("convo not available")
|
||||
return
|
||||
}
|
||||
|
||||
// update convo users array with this other friend
|
||||
convo!.users.append(friendId)
|
||||
|
||||
self.firestoreService.updateConvo(convo: convo!) {[weak self] res in
|
||||
print("updated with new friend added in the convo")
|
||||
}
|
||||
}
|
||||
|
||||
// anyone can leave at any time
|
||||
func leaveConvo() {
|
||||
agoraKit?.leaveChannel(nil)
|
||||
|
||||
@@ -156,7 +156,7 @@ struct CircleGridView: View {
|
||||
.cornerRadius(100)
|
||||
|
||||
// user status
|
||||
UserStatusView(status: self.authSessionStore.relevantUsersDict[friendId]?.userStatus, size: 20, padding: 5)
|
||||
UserStatusView(status: self.authSessionStore.relevantUsersDict[friendId]?.userStatus, size: 20, padding: 5)
|
||||
|
||||
// inside avatar
|
||||
Image(self.authSessionStore.relevantUsersDict[friendId]?.avatar ?? Avatars.avatarSystemNames[0])
|
||||
@@ -182,6 +182,12 @@ struct CircleGridView: View {
|
||||
.gesture(
|
||||
LongPressGesture(minimumDuration: longPressMinDuration)
|
||||
.onEnded {_ in // on activation of long press
|
||||
// if in a call, I cannot record or select someone...strict rules on user if in a call
|
||||
if self.convoVM.isInCall() {
|
||||
print("can't select another friend because I am in a call...leave call first")
|
||||
return
|
||||
}
|
||||
|
||||
// stop any player still playing of a message
|
||||
self.queuePlayer.removeAllItems()
|
||||
|
||||
@@ -458,15 +464,27 @@ extension CircleGridView {
|
||||
private func handleTap(gridItemIndex: Int, friendId: String) {
|
||||
print("tap gesture activated")
|
||||
|
||||
// if friend and I are online, start convo immediately with them
|
||||
// if friend and I are online, and I am not in a convo, start convo immediately with them
|
||||
if self.authSessionStore.relevantUsersDict[friendId]?.userStatus == .online
|
||||
&& self.authSessionStore.user?.userStatus == .online {
|
||||
&& self.authSessionStore.user?.userStatus == .online && !self.convoVM.isInCall() {
|
||||
print("starting a direct convo...getting it going")
|
||||
self.convoVM.startConvo(friendId: friendId)
|
||||
|
||||
return
|
||||
} // if I am in a convo and I am adding someone else online, then make them join my convo
|
||||
else if self.convoVM.isInCall() && self.authSessionStore.relevantUsersDict[friendId]?.userStatus == .online {
|
||||
print("chaining the convo with more people...forcing someone else in")
|
||||
|
||||
self.convoVM.addThirdPartyToConvo(friendId: friendId)
|
||||
|
||||
return
|
||||
} // if I am in a convo, don't allow listening to a message or expanding details of a friend in my circle
|
||||
else if self.convoVM.isInCall() {
|
||||
print("can't select this friend as you are in a convo")
|
||||
return
|
||||
}
|
||||
|
||||
// TODO: if I am in a call and I am adding someone else online, then make them join my convo
|
||||
|
||||
|
||||
// clearing the player to make room for this friend's convo or to deselect this user
|
||||
self.queuePlayer.removeAllItems()
|
||||
|
||||
Reference in New Issue
Block a user