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
+3 -3
View File
@@ -12,7 +12,7 @@ export default class Conversation {
membersInLiveRoom: string[] = [] as string[]; // all members in a live call right now for this convo
cachedAudioClip?: AudioClip; // last message pretty much
cachedDrawerItem?: Link; // last link pretty much
cachedLink?: Link; // last link pretty much
tldr?: string; // description almost that people keep up to day in the convo
@@ -92,7 +92,7 @@ export class Link {
url: string;
name: string;
type: LinkType;
// type: LinkType;
createdByUserId: string;
createdDate: Timestamp = Timestamp.now();
@@ -101,7 +101,7 @@ export class Link {
this.createdByUserId = _senderUserId;
this.url = _linkUrl;
this.name = _name;
this.type = Link.getLinkType(_linkUrl);
// this.type = Link.getLinkType(_linkUrl);
}
static getLinkType(url: string): LinkType {
+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 }
);
});
}
}