logic for joining and leaving room
This commit is contained in:
@@ -55,6 +55,8 @@ import {
|
|||||||
createOneOnOneConversation,
|
createOneOnOneConversation,
|
||||||
getConversationsQueryLIVE,
|
getConversationsQueryLIVE,
|
||||||
getUserById,
|
getUserById,
|
||||||
|
joinConversation,
|
||||||
|
leaveConversation,
|
||||||
searchUsers,
|
searchUsers,
|
||||||
sendAudioClipToConversation,
|
sendAudioClipToConversation,
|
||||||
} from '../firebase/firestore';
|
} from '../firebase/firestore';
|
||||||
@@ -826,6 +828,8 @@ function MainPanel() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const maxPriorityConvos = 5;
|
||||||
|
|
||||||
function ConversationDetails() {
|
function ConversationDetails() {
|
||||||
const { user } = useAuth();
|
const { user } = useAuth();
|
||||||
const { getUser, selectedConversation, selectConversation, isCloudDoingMagic } = useTerminal();
|
const { getUser, selectedConversation, selectConversation, isCloudDoingMagic } = useTerminal();
|
||||||
@@ -834,13 +838,36 @@ function ConversationDetails() {
|
|||||||
// TODO: at the terminal level, make sure we are listening for audio clips
|
// TODO: at the terminal level, make sure we are listening for audio clips
|
||||||
// and here it's just an access of that map of content for each conversation's blocks
|
// and here it's just an access of that map of content for each conversation's blocks
|
||||||
|
|
||||||
|
// the reference last active date based on current session of viewing this conversation
|
||||||
|
const [lastActiveDate, setLastActiveDate] = useState<Date>(null);
|
||||||
|
|
||||||
// join the room
|
// join the room
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (selectedConversation.membersInRoom?.length > 0) {
|
if (selectedConversation.membersInRoom?.length > 1) {
|
||||||
// join the audio room
|
// join the audio room with hms
|
||||||
}
|
}
|
||||||
}, [selectedConversation.membersInRoom]);
|
}, [selectedConversation.membersInRoom]);
|
||||||
|
|
||||||
|
// update my last active date in this conversation
|
||||||
|
// put me in the membersInRoom
|
||||||
|
useEffect(() => {
|
||||||
|
setLastActiveDate((prevLastActiveForCurrentSession) => {
|
||||||
|
if (prevLastActiveForCurrentSession) return prevLastActiveForCurrentSession;
|
||||||
|
|
||||||
|
return selectedConversation.members[user.uid].lastActiveDate?.toDate();
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!selectedConversation.memberIdsList.includes(user.uid))
|
||||||
|
joinConversation(selectedConversation.id, user.uid);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
leaveConversation(selectedConversation.id, user.uid);
|
||||||
|
};
|
||||||
|
}, [selectedConversation.members, user.uid, setLastActiveDate, selectedConversation.id]);
|
||||||
|
|
||||||
|
// TODO: uncheck priority or not
|
||||||
|
// soft max of 10...not going to enforce by counting all in database, but relying on client side list of convos
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
(async () => {
|
(async () => {
|
||||||
const userPromises = selectedConversation.memberIdsList
|
const userPromises = selectedConversation.memberIdsList
|
||||||
|
|||||||
@@ -17,6 +17,9 @@ import {
|
|||||||
startAt,
|
startAt,
|
||||||
endAt,
|
endAt,
|
||||||
addDoc,
|
addDoc,
|
||||||
|
arrayUnion,
|
||||||
|
updateDoc,
|
||||||
|
arrayRemove,
|
||||||
} from 'firebase/firestore';
|
} from 'firebase/firestore';
|
||||||
|
|
||||||
import { User as FirebaseUser } from 'firebase/auth';
|
import { User as FirebaseUser } from 'firebase/auth';
|
||||||
@@ -60,7 +63,8 @@ const db = {
|
|||||||
users: collectionPoint<User>(`users`),
|
users: collectionPoint<User>(`users`),
|
||||||
user: (userId: string) => docPoint<User>(`users/${userId}`),
|
user: (userId: string) => docPoint<User>(`users/${userId}`),
|
||||||
conversations: collectionPoint<Conversation>(`conversations`),
|
conversations: collectionPoint<Conversation>(`conversations`),
|
||||||
conversation: (conversationId: string) => docPoint<User>(`conversations/${conversationId}`),
|
conversation: (conversationId: string) =>
|
||||||
|
docPoint<Conversation>(`conversations/${conversationId}`),
|
||||||
|
|
||||||
conversationAudioClips: (conversationId: string) =>
|
conversationAudioClips: (conversationId: string) =>
|
||||||
collectionPoint<AudioClip>(`conversations/${conversationId}/audioClips`),
|
collectionPoint<AudioClip>(`conversations/${conversationId}/audioClips`),
|
||||||
@@ -163,9 +167,9 @@ export const createOneOnOneConversation = async (
|
|||||||
const newDoc = await addDoc(db.conversations, newConversation);
|
const newDoc = await addDoc(db.conversations, newConversation);
|
||||||
return newDoc.id;
|
return newDoc.id;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Error creating user: ', e);
|
console.error('Error: ', e);
|
||||||
|
|
||||||
throw new Error('Error creating user');
|
throw new Error('Error');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -193,9 +197,9 @@ export const createGroupConversation = async (
|
|||||||
try {
|
try {
|
||||||
await addDoc(db.conversations, newConversation);
|
await addDoc(db.conversations, newConversation);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Error creating user: ', e);
|
console.error('Error : ', e);
|
||||||
|
|
||||||
throw new Error('Error creating user');
|
throw new Error('Error ');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -203,8 +207,30 @@ export const sendAudioClipToConversation = async (audioClip: AudioClip, conversa
|
|||||||
try {
|
try {
|
||||||
await addDoc(db.conversationAudioClips(conversationId), audioClip);
|
await addDoc(db.conversationAudioClips(conversationId), audioClip);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Error creating user: ', e);
|
console.error('Error ', e);
|
||||||
|
|
||||||
throw new Error('Error creating user');
|
throw new Error('Error ');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// put the user in membersInroom
|
||||||
|
export const joinConversation = async (conversationId: string, userId: string) => {
|
||||||
|
try {
|
||||||
|
await updateDoc(db.conversation(conversationId), { membersInRoom: arrayUnion(userId) });
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Error ', e);
|
||||||
|
|
||||||
|
throw new Error('Error');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// leave membersInroom
|
||||||
|
export const leaveConversation = async (conversationId: string, userId: string) => {
|
||||||
|
try {
|
||||||
|
await updateDoc(db.conversation(conversationId), { membersInRoom: arrayRemove(userId) });
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Error ', e);
|
||||||
|
|
||||||
|
throw new Error('Error');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user