mirror of
https://github.com/hcengineering/platform.git
synced 2026-09-12 04:37:44 +02:00
Rename person workspace (#17)
Signed-off-by: Kristina Fefelova <kristin.fefelova@gmail.com>
This commit is contained in:
@@ -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<MessageID> {
|
||||
@@ -137,7 +137,7 @@ class DbClient implements Client {
|
||||
}
|
||||
|
||||
async createNotificationContext(card: CardID, lastView?: Date, lastUpdate?: Date): Promise<ContextID> {
|
||||
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<void> {
|
||||
@@ -150,12 +150,12 @@ class DbClient implements Client {
|
||||
|
||||
async findNotificationContexts(params: FindNotificationContextParams): Promise<NotificationContext[]> {
|
||||
//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<Notification[]> {
|
||||
//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<Client> {
|
||||
const db = await createSqliteDbAdapter(dbUrl)
|
||||
return new DbClient(db, workspace, personWorkspace)
|
||||
return new DbClient(db, workspace, personalWorkspace)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
);
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,11 +81,11 @@ export class CockroachAdapter implements DbAdapter {
|
||||
async createContext(
|
||||
workspace: string,
|
||||
card: CardID,
|
||||
personWorkspace: string,
|
||||
personalWorkspace: string,
|
||||
lastView?: Date,
|
||||
lastUpdate?: Date
|
||||
): Promise<ContextID> {
|
||||
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<void> {
|
||||
@@ -98,18 +98,18 @@ export class CockroachAdapter implements DbAdapter {
|
||||
|
||||
async findContexts(
|
||||
params: FindNotificationContextParams,
|
||||
personWorkspaces: string[],
|
||||
personalWorkspaces: string[],
|
||||
workspace?: string
|
||||
): Promise<NotificationContext[]> {
|
||||
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<Notification[]> {
|
||||
return await this.notification.findNotifications(params, personWorkspace, workspace)
|
||||
return await this.notification.findNotifications(params, personalWorkspace, workspace)
|
||||
}
|
||||
|
||||
close(): void {
|
||||
|
||||
@@ -27,11 +27,11 @@ export class NotificationsDb extends BaseDb {
|
||||
})
|
||||
}
|
||||
|
||||
async createContext(workspace: string, card: CardID, personWorkspace: string, lastView?: Date, lastUpdate?: Date): Promise<ContextID> {
|
||||
async createContext(workspace: string, card: CardID, personalWorkspace: string, lastView?: Date, lastUpdate?: Date): Promise<ContextID> {
|
||||
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<NotificationContext[]> {
|
||||
async findContexts(params: FindNotificationContextParams, personalWorkspaces: string[], workspace?: string,): Promise<NotificationContext[]> {
|
||||
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<Notification[]> {
|
||||
async findNotifications(params: FindNotificationsParams, personalWorkspace: string, workspace?: string): Promise<Notification[]> {
|
||||
//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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -36,7 +36,7 @@ export interface DbAdapter {
|
||||
createNotification(message: MessageID, context: ContextID): Promise<void>
|
||||
removeNotification(message: MessageID, context: ContextID): Promise<void>
|
||||
createContext(
|
||||
personWorkspace: string,
|
||||
personalWorkspace: string,
|
||||
workspace: string,
|
||||
card: CardID,
|
||||
lastView?: Date,
|
||||
@@ -46,12 +46,12 @@ export interface DbAdapter {
|
||||
removeContext(context: ContextID): Promise<void>
|
||||
findContexts(
|
||||
params: FindNotificationContextParams,
|
||||
personWorkspaces: string[],
|
||||
personalWorkspaces: string[],
|
||||
workspace?: string
|
||||
): Promise<NotificationContext[]>
|
||||
findNotifications(
|
||||
params: FindNotificationsParams,
|
||||
personWorkspace: string,
|
||||
personalWorkspace: string,
|
||||
workspace?: string
|
||||
): Promise<Notification[]>
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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<Result> {
|
||||
@@ -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<Result> {
|
||||
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
|
||||
}
|
||||
|
||||
@@ -137,6 +137,6 @@ async function validateToken(token: string): Promise<ConnectionInfo> {
|
||||
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 }
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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<Notification[]> {
|
||||
//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<NotificationContext[]> {
|
||||
//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)
|
||||
}
|
||||
|
||||
@@ -22,21 +22,24 @@ export class Triggers {
|
||||
|
||||
private async createNotifications(event: MessageCreatedEvent, workspace: string): Promise<BroadcastEvent[]> {
|
||||
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
|
||||
|
||||
@@ -2,6 +2,6 @@ import type { SocialID } from '@hcengineering/communication-types'
|
||||
|
||||
export interface ConnectionInfo {
|
||||
workspace: string
|
||||
personWorkspace: string
|
||||
personalWorkspace: string
|
||||
socialId: SocialID
|
||||
}
|
||||
|
||||
@@ -80,11 +80,11 @@ export class SqliteAdapter implements DbAdapter {
|
||||
async createContext(
|
||||
workspace: string,
|
||||
card: CardID,
|
||||
personWorkspace: string,
|
||||
personalWorkspace: string,
|
||||
lastView?: Date,
|
||||
lastUpdate?: Date
|
||||
): Promise<ContextID> {
|
||||
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<void> {
|
||||
@@ -97,18 +97,18 @@ export class SqliteAdapter implements DbAdapter {
|
||||
|
||||
async findContexts(
|
||||
params: FindNotificationContextParams,
|
||||
personWorkspaces: string[],
|
||||
personalWorkspaces: string[],
|
||||
workspace?: string
|
||||
): Promise<NotificationContext[]> {
|
||||
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<Notification[]> {
|
||||
return await this.notification.findNotifications(params, personWorkspace, workspace)
|
||||
return await this.notification.findNotifications(params, personalWorkspace, workspace)
|
||||
}
|
||||
|
||||
close(): void {
|
||||
|
||||
@@ -27,12 +27,12 @@ export class NotificationsDb extends BaseDb {
|
||||
})
|
||||
}
|
||||
|
||||
async createContext(workspace: string, card: CardID, personWorkspace: string, lastView?: Date, lastUpdate?: Date): Promise<ContextID> {
|
||||
async createContext(workspace: string, card: CardID, personalWorkspace: string, lastView?: Date, lastUpdate?: Date): Promise<ContextID> {
|
||||
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<NotificationContext[]> {
|
||||
async findContexts(params: FindNotificationContextParams, personalWorkspaces: string[], workspace?: string,): Promise<NotificationContext[]> {
|
||||
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<Notification[]> {
|
||||
async findNotifications(params: FindNotificationsParams, personalWorkspace: string, workspace?: string): Promise<Notification[]> {
|
||||
//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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -13,7 +13,7 @@ export interface NotificationContext {
|
||||
id: ContextID
|
||||
card: CardID
|
||||
workspace: string
|
||||
personWorkspace: string
|
||||
personalWorkspace: string
|
||||
archivedFrom?: Date
|
||||
lastView?: Date
|
||||
lastUpdate?: Date
|
||||
|
||||
Reference in New Issue
Block a user