From 5c376b1bb55472360f9178eb4ff57ee7de338d00 Mon Sep 17 00:00:00 2001 From: Kristina Date: Tue, 4 Feb 2025 16:33:11 +0400 Subject: [PATCH] Rename person workspace (#17) Signed-off-by: Kristina Fefelova --- packages/client-sqlite/src/client.ts | 12 ++++---- .../migrations/05_notificationContext.sql | 4 +-- packages/cockroach/package.json | 7 +++++ packages/cockroach/src/adapter.ts | 12 ++++---- packages/cockroach/src/db/notification.ts | 28 +++++++++---------- packages/cockroach/src/db/types.ts | 2 +- packages/examples/src/index.ts | 4 +-- packages/sdk-types/src/db.ts | 6 ++-- packages/sdk-types/src/event.ts | 8 +++--- packages/server/src/eventProcessor.ts | 12 ++++---- packages/server/src/main.ts | 4 +-- packages/server/src/manager.ts | 10 +++---- packages/server/src/session.ts | 6 ++-- packages/server/src/triggers.ts | 21 ++++++++------ packages/server/src/types.ts | 2 +- packages/sqlite-wasm/src/adapter.ts | 12 ++++---- packages/sqlite-wasm/src/db/notification.ts | 26 ++++++++--------- packages/sqlite-wasm/src/db/types.ts | 2 +- packages/sqlite-wasm/src/migrations.ts | 4 +-- packages/types/src/notification.ts | 2 +- 20 files changed, 97 insertions(+), 87 deletions(-) diff --git a/packages/client-sqlite/src/client.ts b/packages/client-sqlite/src/client.ts index e2645b9a85..51b350c9c4 100644 --- a/packages/client-sqlite/src/client.ts +++ b/packages/client-sqlite/src/client.ts @@ -30,7 +30,7 @@ class DbClient implements Client { constructor( private readonly db: DbAdapter, private readonly workspace: string, - private readonly personWorkspace: string + private readonly personalWorkspace: string ) {} async createMessage(thread: ThreadID, content: RichText, creator: SocialID): Promise { @@ -137,7 +137,7 @@ class DbClient implements Client { } async createNotificationContext(card: CardID, lastView?: Date, lastUpdate?: Date): Promise { - return await this.db.createContext(this.personWorkspace, this.workspace, card, lastView, lastUpdate) + return await this.db.createContext(this.personalWorkspace, this.workspace, card, lastView, lastUpdate) } async updateNotificationContext(context: ContextID, update: NotificationContextUpdate): Promise { @@ -150,12 +150,12 @@ class DbClient implements Client { async findNotificationContexts(params: FindNotificationContextParams): Promise { //TODO: should we filter by workspace? - return await this.db.findContexts(params, [this.personWorkspace]) + return await this.db.findContexts(params, [this.personalWorkspace]) } async findNotifications(params: FindNotificationsParams): Promise { //TODO: should we filter by workspace? - return await this.db.findNotifications(params, this.personWorkspace) + return await this.db.findNotifications(params, this.personalWorkspace) } async unsubscribeQuery() { @@ -169,9 +169,9 @@ class DbClient implements Client { export async function getSqliteClient( workspace: string, - personWorkspace: string, + personalWorkspace: string, dbUrl = 'file:communication.sqlite3?vfs=opfs' ): Promise { const db = await createSqliteDbAdapter(dbUrl) - return new DbClient(db, workspace, personWorkspace) + return new DbClient(db, workspace, personalWorkspace) } diff --git a/packages/cockroach/migrations/05_notificationContext.sql b/packages/cockroach/migrations/05_notificationContext.sql index b461c45fc5..b08a691a91 100644 --- a/packages/cockroach/migrations/05_notificationContext.sql +++ b/packages/cockroach/migrations/05_notificationContext.sql @@ -4,12 +4,12 @@ CREATE TABLE IF NOT EXISTS notification_context workspace_id UUID NOT NULL, card_id UUID NOT NULL, - person_workspace UUID NOT NULL, + personal_workspace UUID NOT NULL, archived_from TIMESTAMPTZ, last_view TIMESTAMPTZ, last_update TIMESTAMPTZ, PRIMARY KEY (id), - UNIQUE (workspace_id, card_id, person_workspace) + UNIQUE (workspace_id, card_id, personal_workspace) ); diff --git a/packages/cockroach/package.json b/packages/cockroach/package.json index 1a52dccfd5..ec3644aec9 100644 --- a/packages/cockroach/package.json +++ b/packages/cockroach/package.json @@ -21,5 +21,12 @@ }, "peerDependencies": { "typescript": "^5.6.3" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/hcengineering/communication.git" + }, + "publishConfig": { + "registry": "https://npm.pkg.github.com" } } diff --git a/packages/cockroach/src/adapter.ts b/packages/cockroach/src/adapter.ts index 1064bbdfe6..aa88a61570 100644 --- a/packages/cockroach/src/adapter.ts +++ b/packages/cockroach/src/adapter.ts @@ -81,11 +81,11 @@ export class CockroachAdapter implements DbAdapter { async createContext( workspace: string, card: CardID, - personWorkspace: string, + personalWorkspace: string, lastView?: Date, lastUpdate?: Date ): Promise { - return await this.notification.createContext(workspace, card, personWorkspace, lastView, lastUpdate) + return await this.notification.createContext(workspace, card, personalWorkspace, lastView, lastUpdate) } async updateContext(context: ContextID, update: NotificationContextUpdate): Promise { @@ -98,18 +98,18 @@ export class CockroachAdapter implements DbAdapter { async findContexts( params: FindNotificationContextParams, - personWorkspaces: string[], + personalWorkspaces: string[], workspace?: string ): Promise { - return await this.notification.findContexts(params, personWorkspaces, workspace) + return await this.notification.findContexts(params, personalWorkspaces, workspace) } async findNotifications( params: FindNotificationsParams, - personWorkspace: string, + personalWorkspace: string, workspace?: string ): Promise { - return await this.notification.findNotifications(params, personWorkspace, workspace) + return await this.notification.findNotifications(params, personalWorkspace, workspace) } close(): void { diff --git a/packages/cockroach/src/db/notification.ts b/packages/cockroach/src/db/notification.ts index ec5d2d125c..d58fa56f5e 100644 --- a/packages/cockroach/src/db/notification.ts +++ b/packages/cockroach/src/db/notification.ts @@ -27,11 +27,11 @@ export class NotificationsDb extends BaseDb { }) } - async createContext(workspace: string, card: CardID, personWorkspace: string, lastView?: Date, lastUpdate?: Date): Promise { + async createContext(workspace: string, card: CardID, personalWorkspace: string, lastView?: Date, lastUpdate?: Date): Promise { const dbData: ContextDb = { workspace_id: workspace, card_id: card, - person_workspace: personWorkspace, + personal_workspace: personalWorkspace, last_view: lastView, last_update: lastUpdate } @@ -71,11 +71,11 @@ export class NotificationsDb extends BaseDb { await this.client.unsafe(sql, [values, context]) } - async findContexts(params: FindNotificationContextParams, personWorkspaces: string[], workspace?: string,): Promise { + async findContexts(params: FindNotificationContextParams, personalWorkspaces: string[], workspace?: string,): Promise { const select = ` SELECT nc.id, nc.card_id, nc.archived_from, nc.last_view, nc.last_update FROM ${TableName.NotificationContext} nc`; - const {where, values} = this.buildContextWhere(params, personWorkspaces, workspace) + const {where, values} = this.buildContextWhere(params, personalWorkspaces, workspace) // const orderSql = `ORDER BY nc.created ${params.sort === SortOrder.Asc ? 'ASC' : 'DESC'}` const limit = params.limit ? ` LIMIT ${params.limit}` : '' const sql = [select, where, limit].join(' ') @@ -86,7 +86,7 @@ export class NotificationsDb extends BaseDb { } - async findNotifications(params: FindNotificationsParams, personWorkspace: string, workspace?: string): Promise { + async findNotifications(params: FindNotificationsParams, personalWorkspace: string, workspace?: string): Promise { //TODO: experiment with select to improve performance, should join with attachments and reactions? const select = ` SELECT n.message_id, @@ -113,7 +113,7 @@ export class NotificationsDb extends BaseDb { JOIN ${TableName.NotificationContext} nc ON n.context = nc.id JOIN ${TableName.Message} m ON n.message_id = m.id `; - const {where, values} = this.buildNotificationWhere(params, personWorkspace, workspace) + const {where, values} = this.buildNotificationWhere(params, personalWorkspace, workspace) const orderBy = params.sort ? `ORDER BY m.created ${params.sort === SortOrder.Asc ? 'ASC' : 'DESC'}` : '' const limit = params.limit ? ` LIMIT ${params.limit}` : '' const sql = [select, where, orderBy, limit].join(' ') @@ -123,7 +123,7 @@ export class NotificationsDb extends BaseDb { return result.map(this.toNotification); } - buildContextWhere(params: FindNotificationContextParams, personWorkspaces: string[], workspace?: string,): { + buildContextWhere(params: FindNotificationContextParams, personalWorkspaces: string[], workspace?: string,): { where: string, values: any[] } { @@ -136,9 +136,9 @@ export class NotificationsDb extends BaseDb { values.push(workspace) } - if (personWorkspaces.length > 0) { - where.push(`nc.person_workspace IN (${personWorkspaces.map((it) => `$${index++}`).join(', ')})`) - values.push(...personWorkspaces) + if (personalWorkspaces.length > 0) { + where.push(`nc.personal_workspace IN (${personalWorkspaces.map((it) => `$${index++}`).join(', ')})`) + values.push(...personalWorkspaces) } if (params.card != null) { @@ -149,12 +149,12 @@ export class NotificationsDb extends BaseDb { return {where: `WHERE ${where.join(' AND ')}`, values} } - buildNotificationWhere(params: FindNotificationsParams, personWorkspace: string, workspace?: string): { + buildNotificationWhere(params: FindNotificationsParams, personalWorkspace: string, workspace?: string): { where: string, values: any[] } { - const where: string[] = ['nc.person_workspace = $1'] - const values: any[] = [personWorkspace] + const where: string[] = ['nc.personal_workspace = $1'] + const values: any[] = [personalWorkspace] let index = 2 if (workspace != null) { @@ -193,7 +193,7 @@ export class NotificationsDb extends BaseDb { id: row.id, card: row.card_id, workspace: row.workspace_id, - personWorkspace: row.person_workspace, + personalWorkspace: row.personal_workspace, archivedFrom: row.archived_from ? new Date(row.archived_from) : undefined, lastView: row.last_view ? new Date(row.last_view) : undefined, lastUpdate: row.last_update ? new Date(row.last_update) : undefined diff --git a/packages/cockroach/src/db/types.ts b/packages/cockroach/src/db/types.ts index 2a88a6a80a..7742067ebf 100644 --- a/packages/cockroach/src/db/types.ts +++ b/packages/cockroach/src/db/types.ts @@ -45,7 +45,7 @@ export interface NotificationDb { export interface ContextDb { workspace_id: string card_id: CardID - person_workspace: string + personal_workspace: string archived_from?: Date last_view?: Date diff --git a/packages/examples/src/index.ts b/packages/examples/src/index.ts index bceebf8794..3b1764a9b1 100644 --- a/packages/examples/src/index.ts +++ b/packages/examples/src/index.ts @@ -5,7 +5,7 @@ import { createMessagesQuery, initLiveQueries } from '@hcengineering/communicati const thread = 'cd0aba36-1c4f-4170-95f2-27a12a5415f6' as ThreadID const workspace = 'cd0aba36-1c4f-4170-95f2-27a12a5415f6' -const personWorkspace = 'cd0aba36-1c4f-4170-95f2-27a12a5415f5' +const personalWorkspace = 'cd0aba36-1c4f-4170-95f2-27a12a5415f5' const creator1 = 'email:vasya@huly.com' as SocialID async function getClient(type: 'ws' | 'sqlite') { @@ -15,7 +15,7 @@ async function getClient(type: 'ws' | 'sqlite') { return await getWebsocketClient(platformUrl, token) } - return await getSqliteClient(workspace, personWorkspace) + return await getSqliteClient(workspace, personalWorkspace) } export async function example() { diff --git a/packages/sdk-types/src/db.ts b/packages/sdk-types/src/db.ts index 621102b46c..ceba22316b 100644 --- a/packages/sdk-types/src/db.ts +++ b/packages/sdk-types/src/db.ts @@ -36,7 +36,7 @@ export interface DbAdapter { createNotification(message: MessageID, context: ContextID): Promise removeNotification(message: MessageID, context: ContextID): Promise createContext( - personWorkspace: string, + personalWorkspace: string, workspace: string, card: CardID, lastView?: Date, @@ -46,12 +46,12 @@ export interface DbAdapter { removeContext(context: ContextID): Promise findContexts( params: FindNotificationContextParams, - personWorkspaces: string[], + personalWorkspaces: string[], workspace?: string ): Promise findNotifications( params: FindNotificationsParams, - personWorkspace: string, + personalWorkspace: string, workspace?: string ): Promise diff --git a/packages/sdk-types/src/event.ts b/packages/sdk-types/src/event.ts index 70f287ceb5..0bd2927290 100644 --- a/packages/sdk-types/src/event.ts +++ b/packages/sdk-types/src/event.ts @@ -209,13 +209,13 @@ export interface AttachmentRemovedEvent { export interface NotificationCreatedEvent { type: EventType.NotificationCreated - personWorkspace: string + personalWorkspace: string notification: Notification } export interface NotificationRemovedEvent { type: EventType.NotificationRemoved - personWorkspace: string + personalWorkspace: string message: MessageID context: ContextID } @@ -227,13 +227,13 @@ export interface NotificationContextCreatedEvent { export interface NotificationContextRemovedEvent { type: EventType.NotificationContextRemoved - personWorkspace: string + personalWorkspace: string context: ContextID } export interface NotificationContextUpdatedEvent { type: EventType.NotificationContextUpdated - personWorkspace: string + personalWorkspace: string context: ContextID update: NotificationContextUpdate } diff --git a/packages/server/src/eventProcessor.ts b/packages/server/src/eventProcessor.ts index 6d7d72a175..1dde23ae60 100644 --- a/packages/server/src/eventProcessor.ts +++ b/packages/server/src/eventProcessor.ts @@ -39,7 +39,7 @@ export class EventProcessor { constructor( private readonly db: DbAdapter, private readonly workspace: string, - private readonly personWorkspace: string + private readonly personalWorkspace: string ) {} async process(event: Event): Promise { @@ -215,7 +215,7 @@ export class EventProcessor { const broadcastEvent: NotificationRemovedEvent = { type: EventType.NotificationRemoved, - personWorkspace: this.personWorkspace, + personalWorkspace: this.personalWorkspace, message: event.message, context: event.context } @@ -227,7 +227,7 @@ export class EventProcessor { private async createNotificationContext(event: CreateNotificationContextEvent): Promise { const id = await this.db.createContext( - this.personWorkspace, + this.personalWorkspace, this.workspace, event.card, event.lastView, @@ -238,7 +238,7 @@ export class EventProcessor { context: { id, workspace: this.workspace, - personWorkspace: this.personWorkspace, + personalWorkspace: this.personalWorkspace, card: event.card, lastView: event.lastView, lastUpdate: event.lastUpdate @@ -254,7 +254,7 @@ export class EventProcessor { await this.db.removeContext(event.context) const broadcastEvent: NotificationContextRemovedEvent = { type: EventType.NotificationContextRemoved, - personWorkspace: this.personWorkspace, + personalWorkspace: this.personalWorkspace, context: event.context } return { @@ -268,7 +268,7 @@ export class EventProcessor { const broadcastEvent: NotificationContextUpdatedEvent = { type: EventType.NotificationContextUpdated, - personWorkspace: this.personWorkspace, + personalWorkspace: this.personalWorkspace, context: event.context, update: event.update } diff --git a/packages/server/src/main.ts b/packages/server/src/main.ts index a45aca6077..78f8af0174 100644 --- a/packages/server/src/main.ts +++ b/packages/server/src/main.ts @@ -137,6 +137,6 @@ async function validateToken(token: string): Promise { throw new Error('No workspace info') } - const personWorkspace = 'cd0aba36-1c4f-4170-95f2-27a12a5415f7' - return { workspace: info.workspaceId, personWorkspace, socialId: email as SocialID } + const personalWorkspace = 'cd0aba36-1c4f-4170-95f2-27a12a5415f7' + return { workspace: info.workspaceId, personalWorkspace, socialId: email as SocialID } } diff --git a/packages/server/src/manager.ts b/packages/server/src/manager.ts index b6afedd4bf..b9a8503920 100644 --- a/packages/server/src/manager.ts +++ b/packages/server/src/manager.ts @@ -152,20 +152,20 @@ export class Manager { ) case EventType.NotificationCreated: return ( - info.session.info.personWorkspace === event.personWorkspace && + info.session.info.personalWorkspace === event.personalWorkspace && this.matchNotificationQuery(event, Array.from(info.notificationQueries.values())) ) case EventType.NotificationRemoved: - return info.session.info.personWorkspace === event.personWorkspace && info.notificationQueries.size > 0 + return info.session.info.personalWorkspace === event.personalWorkspace && info.notificationQueries.size > 0 case EventType.NotificationContextCreated: return ( - info.session.info.personWorkspace === event.context.personWorkspace && + info.session.info.personalWorkspace === event.context.personalWorkspace && this.matchContextQuery(event, Array.from(info.contextQueries.values())) ) case EventType.NotificationContextRemoved: - return info.session.info.personWorkspace === event.personWorkspace && info.contextQueries.size > 0 + return info.session.info.personalWorkspace === event.personalWorkspace && info.contextQueries.size > 0 case EventType.NotificationContextUpdated: - return info.session.info.personWorkspace === event.personWorkspace && info.contextQueries.size > 0 + return info.session.info.personalWorkspace === event.personalWorkspace && info.contextQueries.size > 0 } } diff --git a/packages/server/src/session.ts b/packages/server/src/session.ts index fdf487d334..246294ded3 100644 --- a/packages/server/src/session.ts +++ b/packages/server/src/session.ts @@ -24,7 +24,7 @@ export class Session { private readonly db: DbAdapter, private readonly manager: Manager ) { - this.eventProcessor = new EventProcessor(db, info.workspace, info.personWorkspace) + this.eventProcessor = new EventProcessor(db, info.workspace, info.personalWorkspace) } ping(): string { @@ -46,7 +46,7 @@ export class Session { async findNotifications(params: FindNotificationsParams, queryId?: number): Promise { //TODO: do we need filter by workspace by default? - const result = await this.db.findNotifications(params, this.info.personWorkspace) + const result = await this.db.findNotifications(params, this.info.personalWorkspace) if (queryId != null) { this.manager.subscribeQuery(this.id, this.info.workspace, 'notification', queryId, params) } @@ -58,7 +58,7 @@ export class Session { queryId?: number ): Promise { //TODO: do we need filter by workspace by default? - const result = await this.db.findContexts(params, [this.info.personWorkspace]) + const result = await this.db.findContexts(params, [this.info.personalWorkspace]) if (queryId != null) { this.manager.subscribeQuery(this.id, this.info.workspace, 'context', queryId, params) } diff --git a/packages/server/src/triggers.ts b/packages/server/src/triggers.ts index 12197b98ae..589205b18f 100644 --- a/packages/server/src/triggers.ts +++ b/packages/server/src/triggers.ts @@ -22,21 +22,24 @@ export class Triggers { private async createNotifications(event: MessageCreatedEvent, workspace: string): Promise { const card = event.message.thread as any as CardID - const subscribedPersonWorkspaces = ['cd0aba36-1c4f-4170-95f2-27a12a5415f7', 'cd0aba36-1c4f-4170-95f2-27a12a5415f8'] + const subscribedPersonalWorkspaces = [ + 'cd0aba36-1c4f-4170-95f2-27a12a5415f7', + 'cd0aba36-1c4f-4170-95f2-27a12a5415f8' + ] const res: BroadcastEvent[] = [] const contexts = await this.db.findContexts({ card }, [], workspace) res.push(...(await this.updateNotificationContexts(event.message.created, contexts))) - for (const personWorkspace of subscribedPersonWorkspaces) { + for (const personalWorkspace of subscribedPersonalWorkspaces) { const existsContext = contexts.find( - (it) => it.card === card && it.personWorkspace === personWorkspace && workspace === it.workspace + (it) => it.card === card && it.personalWorkspace === personalWorkspace && workspace === it.workspace ) const contextId = await this.getOrCreateContextId( workspace, card, - personWorkspace, + personalWorkspace, res, event.message.created, existsContext @@ -46,7 +49,7 @@ export class Triggers { const resultEvent: NotificationCreatedEvent = { type: EventType.NotificationCreated, - personWorkspace, + personalWorkspace, notification: { context: contextId, message: event.message, @@ -63,7 +66,7 @@ export class Triggers { private async getOrCreateContextId( workspace: string, card: CardID, - personWorkspace: string, + personalWorkspace: string, res: BroadcastEvent[], lastUpdate: Date, context?: NotificationContext @@ -71,12 +74,12 @@ export class Triggers { if (context !== undefined) { return context.id } else { - const contextId = await this.db.createContext(personWorkspace, workspace, card, undefined, lastUpdate) + const contextId = await this.db.createContext(personalWorkspace, workspace, card, undefined, lastUpdate) const newContext = { id: contextId, card, workspace, - personWorkspace + personalWorkspace } const resultEvent: NotificationContextCreatedEvent = { type: EventType.NotificationContextCreated, @@ -99,7 +102,7 @@ export class Triggers { await this.db.updateContext(context.id, { lastUpdate }) res.push({ type: EventType.NotificationContextUpdated, - personWorkspace: context.personWorkspace, + personalWorkspace: context.personalWorkspace, context: context.id, update: { lastUpdate diff --git a/packages/server/src/types.ts b/packages/server/src/types.ts index 69ca3515c0..26760ef707 100644 --- a/packages/server/src/types.ts +++ b/packages/server/src/types.ts @@ -2,6 +2,6 @@ import type { SocialID } from '@hcengineering/communication-types' export interface ConnectionInfo { workspace: string - personWorkspace: string + personalWorkspace: string socialId: SocialID } diff --git a/packages/sqlite-wasm/src/adapter.ts b/packages/sqlite-wasm/src/adapter.ts index 7a08c1dec4..2ee4a3c98f 100644 --- a/packages/sqlite-wasm/src/adapter.ts +++ b/packages/sqlite-wasm/src/adapter.ts @@ -80,11 +80,11 @@ export class SqliteAdapter implements DbAdapter { async createContext( workspace: string, card: CardID, - personWorkspace: string, + personalWorkspace: string, lastView?: Date, lastUpdate?: Date ): Promise { - return await this.notification.createContext(workspace, card, personWorkspace, lastView, lastUpdate) + return await this.notification.createContext(workspace, card, personalWorkspace, lastView, lastUpdate) } async removeContext(context: ContextID): Promise { @@ -97,18 +97,18 @@ export class SqliteAdapter implements DbAdapter { async findContexts( params: FindNotificationContextParams, - personWorkspaces: string[], + personalWorkspaces: string[], workspace?: string ): Promise { - return await this.notification.findContexts(params, personWorkspaces, workspace) + return await this.notification.findContexts(params, personalWorkspaces, workspace) } async findNotifications( params: FindNotificationsParams, - personWorkspace: string, + personalWorkspace: string, workspace?: string ): Promise { - return await this.notification.findNotifications(params, personWorkspace, workspace) + return await this.notification.findNotifications(params, personalWorkspace, workspace) } close(): void { diff --git a/packages/sqlite-wasm/src/db/notification.ts b/packages/sqlite-wasm/src/db/notification.ts index 83edb04e96..1b0784eb5b 100644 --- a/packages/sqlite-wasm/src/db/notification.ts +++ b/packages/sqlite-wasm/src/db/notification.ts @@ -27,12 +27,12 @@ export class NotificationsDb extends BaseDb { }) } - async createContext(workspace: string, card: CardID, personWorkspace: string, lastView?: Date, lastUpdate?: Date): Promise { + async createContext(workspace: string, card: CardID, personalWorkspace: string, lastView?: Date, lastUpdate?: Date): Promise { const dbData: ContextDb = { id: self.crypto.randomUUID(), workspace_id: workspace, card_id: card, - person_workspace: personWorkspace, + personal_workspace: personalWorkspace, last_view: lastView, last_update: lastUpdate } @@ -78,7 +78,7 @@ export class NotificationsDb extends BaseDb { }); } - async findContexts(params: FindNotificationContextParams, personWorkspaces: string[], workspace?: string,): Promise { + async findContexts(params: FindNotificationContextParams, personalWorkspaces: string[], workspace?: string,): Promise { const select = ` SELECT nc.id, nc.card_id, @@ -86,9 +86,9 @@ export class NotificationsDb extends BaseDb { nc.last_view, nc.last_update, nc.workspace_id, - nc.person_workspace + nc.personal_workspace FROM ${TableName.NotificationContext} nc`; - const where = this.buildContextWhere(params, personWorkspaces, workspace); + const where = this.buildContextWhere(params, personalWorkspaces, workspace); // const orderSql = `ORDER BY nc.created ${params.sort === SortOrder.Asc ? 'ASC' : 'DESC'}` const limit = params.limit ? ` LIMIT ${params.limit}` : '' const sql = [select, where, limit].join(' ') @@ -99,7 +99,7 @@ export class NotificationsDb extends BaseDb { } - async findNotifications(params: FindNotificationsParams, personWorkspace: string, workspace?: string): Promise { + async findNotifications(params: FindNotificationsParams, personalWorkspace: string, workspace?: string): Promise { //TODO: should join with attachments and reactions? const select = ` SELECT n.message_id, @@ -128,7 +128,7 @@ export class NotificationsDb extends BaseDb { LEFT JOIN ${TableName.Patch} p ON p.message_id = m.id `; - const where = this.buildNotificationWhere(params, personWorkspace, workspace) + const where = this.buildNotificationWhere(params, personalWorkspace, workspace) const groupBy = `GROUP BY n.message_id, n.context_id, m.id, nc.card_id, nc.archived_from, nc.last_view, nc.last_update`; const orderBy = `ORDER BY m.created ${params.sort === SortOrder.Asc ? 'ASC' : 'DESC'}` const limit = params.limit ? ` LIMIT ${params.limit}` : '' @@ -139,14 +139,14 @@ export class NotificationsDb extends BaseDb { return result.map(it => this.toNotification(it)); } - buildContextWhere(params: FindNotificationContextParams, personWorkspaces: string[], workspace?: string,): string { + buildContextWhere(params: FindNotificationContextParams, personalWorkspaces: string[], workspace?: string,): string { const where: string[] = [] if (workspace != null) { where.push(`nc.workspace_id = '${workspace}'`) } - if (personWorkspaces.length > 0) { - where.push(`nc.person_workspace IN (${personWorkspaces.map(it => `'${it}'`).join(', ')})`) + if (personalWorkspaces.length > 0) { + where.push(`nc.personal_workspace IN (${personalWorkspaces.map(it => `'${it}'`).join(', ')})`) } if (params.card != null) { @@ -156,8 +156,8 @@ export class NotificationsDb extends BaseDb { return `WHERE ${where.join(' AND ')}` } - buildNotificationWhere(params: FindNotificationsParams, personWorkspace: string, workspace?: string): string { - const where: string[] = [`nc.person_workspace = '${personWorkspace}'`] + buildNotificationWhere(params: FindNotificationsParams, personalWorkspace: string, workspace?: string): string { + const where: string[] = [`nc.personal_workspace = '${personalWorkspace}'`] if (workspace != null) { where.push(`nc.workspace_id = '${workspace}'`) } @@ -193,7 +193,7 @@ export class NotificationsDb extends BaseDb { lastView: row.last_view ? new Date(row.last_view) : undefined, lastUpdate: row.last_update ? new Date(row.last_update) : undefined, workspace: row.workspace, - personWorkspace: row.person_workspace + personalWorkspace: row.personal_workspace } } diff --git a/packages/sqlite-wasm/src/db/types.ts b/packages/sqlite-wasm/src/db/types.ts index 7834993bd6..5aff499ee8 100644 --- a/packages/sqlite-wasm/src/db/types.ts +++ b/packages/sqlite-wasm/src/db/types.ts @@ -49,7 +49,7 @@ export interface ContextDb { id: string workspace_id: string card_id: CardID - person_workspace: string + personal_workspace: string archived_from?: Date last_view?: Date diff --git a/packages/sqlite-wasm/src/migrations.ts b/packages/sqlite-wasm/src/migrations.ts index 1a59020ab3..e729111a0a 100644 --- a/packages/sqlite-wasm/src/migrations.ts +++ b/packages/sqlite-wasm/src/migrations.ts @@ -92,13 +92,13 @@ async function migrationV1(worker: Sqlite3Worker1Promiser, dbId: string): Promis id TEXT NOT NULL, workspace_id TEXT NOT NULL, card_id TEXT NOT NULL, - person_workspace TEXT NOT NULL, + personal_workspace TEXT NOT NULL, archived_from DATETIME, last_view DATETIME, last_update DATETIME, PRIMARY KEY (id), - UNIQUE (workspace_id, card_id, person_workspace) + UNIQUE (workspace_id, card_id, personal_workspace) ); CREATE TABLE IF NOT EXISTS notification diff --git a/packages/types/src/notification.ts b/packages/types/src/notification.ts index 79b9b83a5e..007e19b4c1 100644 --- a/packages/types/src/notification.ts +++ b/packages/types/src/notification.ts @@ -13,7 +13,7 @@ export interface NotificationContext { id: ContextID card: CardID workspace: string - personWorkspace: string + personalWorkspace: string archivedFrom?: Date lastView?: Date lastUpdate?: Date