diff --git a/.gitignore b/.gitignore index 411a6e3..4185b0a 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,4 @@ /build /dist -/packages/api/core \ No newline at end of file +/packages/api/common \ No newline at end of file diff --git a/packages/api/package.json b/packages/api/package.json index 576e291..d972edf 100644 --- a/packages/api/package.json +++ b/packages/api/package.json @@ -4,11 +4,11 @@ "main": "index.ts", "license": "MIT", "scripts": { - "core": "cp -r ../core ./core", - "dev": "NODE_ENV=development nodemon", + "common": "rm -rf ./common && cp -r ../common/src ./common/", + "dev": "NODE_ENV=development && yarn common && nodemon", "start:dev": "ts-node index.ts", "start": "node dist/index.js", - "gcp-build": "yarn core & tsc -p .", + "gcp-build": "npm run common && tsc -p .", "production": "NODE_ENV=production nodemon" }, "devDependencies": { @@ -19,6 +19,7 @@ }, "dependencies": { "axios": "^0.26.1", + "firebase": "^9.8.2", "cors": "^2.8.5", "dotenv": "^16.0.0", "express": "^4.17.3", diff --git a/packages/common/package.json b/packages/common/package.json new file mode 100644 index 0000000..5bd0970 --- /dev/null +++ b/packages/common/package.json @@ -0,0 +1,6 @@ +{ + "name": "@nirvana/common", + "version": "1.0.0", + "main": "index.js", + "license": "MIT" +} diff --git a/packages/common/src/index.ts b/packages/common/src/index.ts new file mode 100644 index 0000000..76f132f --- /dev/null +++ b/packages/common/src/index.ts @@ -0,0 +1,3 @@ +export const connectCore = () => { + console.log('CONNECTED COREEEE'); +}; diff --git a/packages/common/src/models/content.model.ts b/packages/common/src/models/content.model.ts new file mode 100644 index 0000000..ba59f4c --- /dev/null +++ b/packages/common/src/models/content.model.ts @@ -0,0 +1,35 @@ +export interface IContent { + id: string; + creatorUserId: string; + contentUrl: string; // remote resource of file/media + createdDate: Date; + + // visitCount +} + +// ? persist length of clip for easier viewing for others... +// ?they have to load it anyway and will get metadata anyway? +export class ContentBlock implements IContent { + constructor( + public id: string, + public creatorUserId: string, + public contentUrl: string, + + public contentType: ContentType, + public blobType: string, + + public createdDate: Date, + ) {} +} + +export enum ContentType { + audio = 'audio', + + link = 'link', + + image = 'image', +} + +export function isUrlImage(url: string) { + return url.match(/\.(jpeg|jpg|gif|png)$/) != null; +} diff --git a/packages/common/src/models/conversation.model.ts b/packages/common/src/models/conversation.model.ts new file mode 100644 index 0000000..b5a2c72 --- /dev/null +++ b/packages/common/src/models/conversation.model.ts @@ -0,0 +1,48 @@ +import { User } from './user.model'; +export default class Conversation { + constructor( + public id: string, + public createdByUserId: string, + + public memberIdsList: string[], + + public members: MemberMap, + + public userCache: User[], + + public name: string | null = null, + + public lastUpdatedDate: Date, + + public createdDate: Date, + + public membersInRoom: string[] = [], + ) {} +} + +export type MemberMap = { + [memberId: string]: ConversationMember; +}; + +export class ConversationMember { + constructor( + public userId: string, // NOTE: serves as the user ID + + public role: MemberRole, + + public memberState: MemberState, + public isActive: boolean = true, + public lastActiveDate: Date = null, + public joinedDate = Date, + ) {} +} + +export enum MemberRole { + admin = 'admin', + regular = 'regular', +} +export enum MemberState { + priority = 'priority', + inbox = 'inbox', + // deleted = "deleted" +} diff --git a/packages/common/src/models/user.model.ts b/packages/common/src/models/user.model.ts new file mode 100644 index 0000000..6fa5b16 --- /dev/null +++ b/packages/common/src/models/user.model.ts @@ -0,0 +1,16 @@ +export class User { + lastUpdatedDate?: Date; + + priorityConversations?: string[]; // id of all priority convos + + constructor( + public id: string, + public uid: string, + public providerId: string, + public email: string, + public displayName?: string, + public photoUrl?: string, + public phoneNumber?: string, + public createdDate: Date = new Date(), + ) {} +}