fix convo query
This commit is contained in:
@@ -22,7 +22,12 @@ import {
|
|||||||
import { User as FirebaseUser } from 'firebase/auth';
|
import { User as FirebaseUser } from 'firebase/auth';
|
||||||
import { firestoreDb } from './connect';
|
import { firestoreDb } from './connect';
|
||||||
import { User } from '@nirvana/core/src/models/user.model';
|
import { User } from '@nirvana/core/src/models/user.model';
|
||||||
import Conversation, { ConversationMember, MemberMap, MemberRole, MemberState } from '@nirvana/core/src/models/conversation.model';
|
import Conversation, {
|
||||||
|
ConversationMember,
|
||||||
|
MemberMap,
|
||||||
|
MemberRole,
|
||||||
|
MemberState,
|
||||||
|
} from '@nirvana/core/src/models/conversation.model';
|
||||||
import useAuth from '../providers/AuthProvider';
|
import useAuth from '../providers/AuthProvider';
|
||||||
|
|
||||||
interface Document {
|
interface Document {
|
||||||
@@ -129,7 +134,7 @@ export const getUserById = async (userId: string): Promise<User | undefined> =>
|
|||||||
|
|
||||||
// get the conversations for particular user
|
// get the conversations for particular user
|
||||||
export const getConversationsQueryLIVE = (userId: string) =>
|
export const getConversationsQueryLIVE = (userId: string) =>
|
||||||
query(db.conversations, where('membersList', 'array-contains', userId));
|
query(db.conversations, where('memberIdsList', 'array-contains', userId));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -141,14 +146,13 @@ export const createOneOnOneConversation = async (
|
|||||||
otherUserId: string,
|
otherUserId: string,
|
||||||
myUserId: string,
|
myUserId: string,
|
||||||
): Promise<string | undefined> => {
|
): Promise<string | undefined> => {
|
||||||
|
const myMember = new ConversationMember(myUserId, MemberRole.admin, MemberState.inbox);
|
||||||
const myMember = new ConversationMember(myUserId, MemberRole.admin, MemberState.inbox)
|
const otherMember = new ConversationMember(otherUserId, MemberRole.regular, MemberState.inbox);
|
||||||
const otherMember = new ConversationMember(otherUserId, MemberRole.regular, MemberState.inbox)
|
|
||||||
|
|
||||||
const newMemberMap: MemberMap = {
|
const newMemberMap: MemberMap = {
|
||||||
[myUserId]: {...myMember},
|
[myUserId]: { ...myMember },
|
||||||
[otherUserId]: {...otherMember}
|
[otherUserId]: { ...otherMember },
|
||||||
}
|
};
|
||||||
const newConversation = new Conversation(myUserId, [myUserId, otherUserId], newMemberMap);
|
const newConversation = new Conversation(myUserId, [myUserId, otherUserId], newMemberMap);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -165,16 +169,20 @@ export const createGroupConversation = async (
|
|||||||
otherUserIds: string[],
|
otherUserIds: string[],
|
||||||
myUserId: string,
|
myUserId: string,
|
||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
const myMember = new ConversationMember(myUserId, MemberRole.admin, MemberState.inbox)
|
const myMember = new ConversationMember(myUserId, MemberRole.admin, MemberState.inbox);
|
||||||
|
|
||||||
const newMemberMap: MemberMap = {
|
const newMemberMap: MemberMap = {
|
||||||
[myUserId]: {...myMember}
|
[myUserId]: { ...myMember },
|
||||||
}
|
};
|
||||||
|
|
||||||
otherUserIds.forEach((otherMemberId) => {
|
otherUserIds.forEach((otherMemberId) => {
|
||||||
const otherMember = new ConversationMember(otherMemberId, MemberRole.regular, MemberState.inbox)
|
const otherMember = new ConversationMember(
|
||||||
newMemberMap[otherMemberId] = {...otherMember}
|
otherMemberId,
|
||||||
})
|
MemberRole.regular,
|
||||||
|
MemberState.inbox,
|
||||||
|
);
|
||||||
|
newMemberMap[otherMemberId] = { ...otherMember };
|
||||||
|
});
|
||||||
|
|
||||||
const newConversation = new Conversation(myUserId, [myUserId, ...otherUserIds], newMemberMap);
|
const newConversation = new Conversation(myUserId, [myUserId, ...otherUserIds], newMemberMap);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user