creating and retrieving links successfully

This commit is contained in:
Arjun Patel
2022-02-13 11:25:12 -08:00
parent bfc539671f
commit 244bdba9e1
7 changed files with 276 additions and 67 deletions
+1
View File
@@ -15,6 +15,7 @@ enum Collections {
conversations = "conversations",
conversationMembers = "members",
conversationAudioClips = "audioClips",
conversationLinks = "links",
}
export default Collections;
@@ -15,6 +15,7 @@ import Conversation, {
AudioClip,
ConversationMember,
ConversationMemberState,
Link,
} from "../models/conversation";
import Collections from "./collections";
import { cloudStorageService } from "./index";
@@ -210,4 +211,51 @@ export default class ConversationService {
{ merge: true }
);
}
async shareLink(createdByUserId: string, link: Link, convoId: string) {
const linkRef = doc(
this.db,
Collections.conversations,
convoId,
Collections.conversationLinks,
link.id
);
const conversationDoc = doc(this.db, Collections.conversations, convoId);
const userConvoAssocDoc = doc(
this.db,
Collections.conversations,
convoId,
Collections.conversationMembers,
createdByUserId
);
await runTransaction(this.db, async (transaction) => {
// want to add to the long term collection of all links for a conversation
transaction.set(
linkRef,
{ ...link, createdDate: serverTimestamp() },
{ merge: true }
);
// want to make updates to the conversation document itself: set the last item for just the basic information to be
// published to users
transaction.set(
conversationDoc,
{
lastActivityDate: serverTimestamp(),
cachedLink: { ...link, createdDate: serverTimestamp() },
},
{ merge: true }
);
// update the user's convo assoc so that their last interaction was set properly
transaction.set(
userConvoAssocDoc,
{
lastInteractionDate: serverTimestamp(),
},
{ merge: true }
);
});
}
}