From e2b786d6f173331a37a9226d4eb6d4a67699d148 Mon Sep 17 00:00:00 2001 From: Arjun Patel Date: Wed, 2 Feb 2022 14:47:30 -0800 Subject: [PATCH] setting up a lot of models and such and now time to implement --- packages/common/models/conversation.ts | 138 ++++++++++++++++-- packages/common/models/usersConverations.ts | 32 ---- .../MainTabsOrPages/Conversations.tsx | 4 +- 3 files changed, 129 insertions(+), 45 deletions(-) delete mode 100644 packages/common/models/usersConverations.ts diff --git a/packages/common/models/conversation.ts b/packages/common/models/conversation.ts index 993c59c..13c0135 100644 --- a/packages/common/models/conversation.ts +++ b/packages/common/models/conversation.ts @@ -1,27 +1,143 @@ import { v4 as uuid } from "uuid"; import { Timestamp } from "firebase/firestore"; +export class CompleteConversation { + id: string; // conversation id + + conversation: Conversation; + + constructor(convo: Conversation) { + this.conversation = convo; + this.id = this.conversation.id; + } + + userMember?: ConversationMember; + + members: ConversationMember[] = [] as ConversationMember[]; + audioClips: AudioClip[] = [] as AudioClip[]; + links: Link[] = [] as Link[]; +} export default class Conversation { id: string = uuid(); - type: ConversationType; - name?: string; // engineering, general, arjun, jacob and rachel... + name: string; // engineering, general, arjun, jacob and rachel... createdDate: Timestamp = Timestamp.now(); createdByUserId: string; - constructor( - _createdByUserId: string, - _type: ConversationType, - _name?: string - ) { + lastActivityDate?: Timestamp; // caching this for purpose of saving on listeners + + membersInLiveRoom: string[] = [] as string[]; // all members in a live call right now for this convo + + constructor(_createdByUserId: string, _name: string) { this.name = _name; this.createdByUserId = _createdByUserId; - this.type = _type; } } -export enum ConversationType { - personal = "personal", // no conversation name then - group = "group", // must have conversation name +export class ConversationMember { + id: string; // will be the userId + state: ConversationMemberState; + + role: ConversationMemberRole; + + createdDate: Timestamp = Timestamp.now(); + lastUpdatedDate?: Timestamp; + + constructor( + _userId: string, + _state: ConversationMemberState, + _role: ConversationMemberRole + ) { + this.id = _userId; + this.state = _state; + this.role = _role; + } +} + +export enum ConversationMemberRole { + admin = "admin", + member = "member", + attendee = "attendee", // for future when only execs or higher ups want to talk in an async chat +} + +export enum ConversationMemberState { + inbox = "inbox", + default = "default", + priority = "priority", + later = "later", + done = "done", + blocked = "removed", // blocked from the conversation now +} + +export class AudioClip { + id: string = uuid(); + + audioDataUrl: string; + + senderUserId: string; + createdDate: Timestamp = Timestamp.now(); + + constructor(_audioDataurl: string, _senderUserId: string) { + this.audioDataUrl = _audioDataurl; + this.senderUserId = _senderUserId; + } +} + +export class Link { + id: string = uuid(); + + url: string; + name: string; + type: LinkType; + + createdByUserId: string; + createdDate: Timestamp = Timestamp.now(); + + constructor(_name: string, _linkUrl: string, _senderUserId: string) { + this.createdByUserId = _senderUserId; + this.url = _linkUrl; + this.name = _name; + this.type = Link.getLinkType(_linkUrl); + } + + static getLinkType(url: string): LinkType { + if (url.includes(LinkType.github)) { + return LinkType.github; + } else if (url.includes(LinkType.atlassian)) { + return LinkType.atlassian; + } else if ( + url.includes(LinkType.googleDrive) || + url.includes("docs.google") + ) { + return LinkType.googleDrive; + } else if ( + url.includes(".png") || + url.includes(".jpg") || + url.includes(".svg") || + url.includes(".gif") || + url.includes(LinkType.pastePics) + ) { + return LinkType.image; + } else if (url.includes(LinkType.pdf)) { + return LinkType.pdf; + } else if (url.includes(LinkType.codePile)) { + return LinkType.codePile; + } else { + return LinkType.default; + } + } +} + +export enum LinkType { + default = "default", + github = "github", + atlassian = "atlassian", + googleDrive = "drive.google", + onedrive = "onedrive", + image = "image", + pdf = "pdf", + codePile = "codepile", + pastePics = "paste.pics", + googleMeet = "googleMeet", } diff --git a/packages/common/models/usersConverations.ts b/packages/common/models/usersConverations.ts deleted file mode 100644 index 3cdccfc..0000000 --- a/packages/common/models/usersConverations.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { v4 as uuid } from "uuid"; -import { Timestamp } from "firebase/firestore"; - -export default class UserConversation { - id: string = uuid(); - - userId: string; - conversationId: string; - state: UserConversationState; - - createdDate: Timestamp = Timestamp.now(); - lastUpdatedDate?: Timestamp; - - constructor( - _userId: string, - _conversationId: string, - _state: UserConversationState - ) { - this.userId = _userId; - this.conversationId = _conversationId; - this.state = _state; - } -} - -export enum UserConversationState { - inbox = "inbox", - default = "default", - priority = "priority", - later = "later", - done = "done", - // blocked = "blocked" -} diff --git a/packages/web/components/MainTabsOrPages/Conversations.tsx b/packages/web/components/MainTabsOrPages/Conversations.tsx index dbd6085..b4273e8 100644 --- a/packages/web/components/MainTabsOrPages/Conversations.tsx +++ b/packages/web/components/MainTabsOrPages/Conversations.tsx @@ -36,8 +36,8 @@ export default function Conversations() { {/* row of live room cards */} - {/* engineering rooms */} - + {/* engineering liveroom */} +