Skip to content

Commit 375bdee

Browse files
Use rowid for message id and allow provide date (#44)
Signed-off-by: Kristina Fefelova <[email protected]>
1 parent de99172 commit 375bdee

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+621
-302
lines changed

.version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.1.168
1+
0.1.170

bun.lock

+3-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"@hcengineering/communication-shared": "workspace:*",
4040
"@hcengineering/communication-types": "workspace:*",
4141
"postgres": "^3.4.4",
42-
"uuid": "^11.0.3",
42+
"uuid": "^11.1.0",
4343
},
4444
"devDependencies": {
4545
"@types/bun": "^1.1.14",
@@ -57,6 +57,7 @@
5757
"@hcengineering/communication-types": "workspace:*",
5858
"@hcengineering/communication-yaml": "workspace:*",
5959
"fast-equals": "^5.0.1",
60+
"uuid": "^11.1.0",
6061
},
6162
"devDependencies": {
6263
"@types/bun": "^1.1.14",
@@ -125,6 +126,7 @@
125126
"name": "@hcengineering/communication-shared",
126127
"version": "0.1.0",
127128
"dependencies": {
129+
"@hcengineering/communication-sdk-types": "workspace:*",
128130
"@hcengineering/communication-types": "workspace:*",
129131
},
130132
"devDependencies": {

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"lint": "turbo run lint",
99
"format": "turbo run format",
1010
"reformat": "turbo run format && turbo run lint -- --fix",
11-
"format:check": "prettier --check \"**/*.ts\""
11+
"format:check": "prettier --check \"**/*.ts\"",
12+
"clean": "turbo run clean"
1213
},
1314
"devDependencies": {
1415
"@eslint/js": "^9.24.0",

packages/client-query/package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@hcengineering/communication-client-query",
33
"version": "0.1.0",
4-
"main": "src/index.ts",
4+
"main": "dist/index.js",
55
"module": "dist/index.js",
66
"types": "./types/index.d.ts",
77
"files": [
@@ -14,7 +14,8 @@
1414
"build:types": "tsc --project ./tsconfig.json --emitDeclarationOnly --declarationDir ./types",
1515
"build:browser": "bun build src/index.ts --outdir dist --target browser",
1616
"lint": "eslint src/*.ts",
17-
"format": "prettier --write src/**/*.ts "
17+
"format": "prettier --write src/**/*.ts ",
18+
"clean": "rm -rf dist && rm -rf types && rm -rf .turbo"
1819
},
1920
"devDependencies": {
2021
"@types/bun": "^1.1.14"

packages/client-query/src/index.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313
// limitations under the License.
1414
//
1515

16-
import { LiveQueries, type QueryClient } from '@hcengineering/communication-query'
16+
import { LiveQueries } from '@hcengineering/communication-query'
1717
import type { WorkspaceID } from '@hcengineering/communication-types'
18+
import type { FindClient } from '@hcengineering/communication-sdk-types'
1819

1920
import { LabelsQuery, MessagesQuery, NotificationContextsQuery, NotificationsQuery } from './query'
2021

@@ -38,7 +39,7 @@ export function createLabelsQuery(): LabelsQuery {
3839
}
3940

4041
export function initLiveQueries(
41-
client: QueryClient,
42+
client: FindClient,
4243
workspace: WorkspaceID,
4344
filesUrl: string,
4445
destroyFn?: (fn: () => void) => void

packages/cockroach/package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@hcengineering/communication-cockroach",
33
"version": "0.1.0",
4-
"main": "src/index.ts",
4+
"main": "dist/index.js",
55
"module": "dist/index.js",
66
"types": "./types/index.d.ts",
77
"files": [
@@ -14,7 +14,8 @@
1414
"build:types": "tsc --project ./tsconfig.json --emitDeclarationOnly --declarationDir ./types",
1515
"build:node": "bun build src/index.ts --target node --format cjs --outfile dist/index.js",
1616
"lint": "eslint src/*.ts",
17-
"format": "prettier --write src/**/*.ts"
17+
"format": "prettier --write src/**/*.ts",
18+
"clean": "rm -rf dist && rm -rf types && rm -rf .turbo"
1819
},
1920
"devDependencies": {
2021
"@types/bun": "^1.1.14"
@@ -24,7 +25,7 @@
2425
"@hcengineering/communication-sdk-types": "workspace:*",
2526
"@hcengineering/communication-types": "workspace:*",
2627
"postgres": "^3.4.4",
27-
"uuid": "^11.0.3"
28+
"uuid": "^11.1.0"
2829
},
2930
"peerDependencies": {
3031
"typescript": "^5.6.3"

packages/cockroach/src/adapter.ts

+22-7
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,13 @@ export class CockroachAdapter implements DbAdapter {
8989
async createPatch(
9090
card: CardID,
9191
message: MessageID,
92+
messageCreated: Date,
9293
type: PatchType,
9394
content: RichText,
9495
creator: SocialID,
9596
created: Date
9697
): Promise<void> {
97-
await this.message.createPatch(card, message, type, content, creator, created)
98+
await this.message.createPatch(card, message, messageCreated, type, content, creator, created)
9899
}
99100

100101
async createMessagesGroup(card: CardID, blobId: BlobID, fromDate: Date, toDate: Date, count: number): Promise<void> {
@@ -108,36 +109,50 @@ export class CockroachAdapter implements DbAdapter {
108109
async createReaction(
109110
card: CardID,
110111
message: MessageID,
112+
messageCreated: Date,
111113
reaction: string,
112114
creator: SocialID,
113115
created: Date
114116
): Promise<void> {
115-
await this.message.createReaction(card, message, reaction, creator, created)
117+
await this.message.createReaction(card, message, messageCreated, reaction, creator, created)
116118
}
117119

118-
async removeReaction(card: CardID, message: MessageID, reaction: string, creator: SocialID): Promise<void> {
119-
await this.message.removeReaction(card, message, reaction, creator, new Date())
120+
async removeReaction(
121+
card: CardID,
122+
message: MessageID,
123+
messageCreated: Date,
124+
reaction: string,
125+
creator: SocialID
126+
): Promise<void> {
127+
await this.message.removeReaction(card, message, messageCreated, reaction, creator, new Date())
120128
}
121129

122130
async createFile(
123131
card: CardID,
124132
message: MessageID,
133+
messageCreated: Date,
125134
blobId: BlobID,
126135
fileType: string,
127136
filename: string,
128137
size: number,
129138
creator: SocialID,
130139
created: Date
131140
): Promise<void> {
132-
await this.message.createFile(card, message, blobId, fileType, filename, size, creator, created)
141+
await this.message.createFile(card, message, messageCreated, blobId, fileType, filename, size, creator, created)
133142
}
134143

135144
async removeFile(card: CardID, message: MessageID, blobId: BlobID): Promise<void> {
136145
await this.message.removeFile(card, message, blobId)
137146
}
138147

139-
async createThread(card: CardID, message: MessageID, thread: CardID, created: Date): Promise<void> {
140-
await this.message.createThread(card, message, thread, created)
148+
async createThread(
149+
card: CardID,
150+
message: MessageID,
151+
messageCreated: Date,
152+
thread: CardID,
153+
created: Date
154+
): Promise<void> {
155+
await this.message.createThread(card, message, messageCreated, thread, created)
141156
}
142157

143158
async updateThread(thread: CardID, op: 'increment' | 'decrement', lastReply?: Date): Promise<void> {

packages/cockroach/src/db/mapping.ts

+12-8
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ interface RawNotification extends NotificationDb {
6767
message_external_id?: string
6868
message_created?: Date
6969
message_group_blob_id?: BlobID
70-
message_group_from_sec?: Date
71-
message_group_to_sec?: Date
70+
message_group_from_date?: Date
71+
message_group_to_date?: Date
7272
message_group_count?: number
7373
message_patches?: {
7474
patch_type: PatchType
@@ -100,6 +100,7 @@ export function toMessage(raw: RawMessage): Message {
100100
? {
101101
card: raw.card_id,
102102
message: String(raw.id) as MessageID,
103+
messageCreated: new Date(raw.created),
103104
thread: raw.thread_id,
104105
repliesCount: raw.replies_count ?? 0,
105106
lastReply: raw.last_reply ?? new Date()
@@ -123,6 +124,7 @@ export function toFile(raw: FileDb): File {
123124
return {
124125
card: raw.card_id,
125126
message: String(raw.message_id) as MessageID,
127+
messageCreated: new Date(raw.message_created),
126128
blobId: raw.blob_id,
127129
type: raw.type,
128130
filename: raw.filename,
@@ -136,16 +138,17 @@ export function toMessagesGroup(raw: MessagesGroupDb): MessagesGroup {
136138
return {
137139
card: raw.card_id,
138140
blobId: raw.blob_id,
139-
fromSec: raw.from_sec,
140-
toSec: raw.to_sec,
141-
count: raw.count,
141+
fromDate: raw.from_date,
142+
toDate: raw.to_date,
143+
count: Number(raw.count),
142144
patches: raw.patches == null ? [] : raw.patches.filter((it: any) => it.message_id != null).map(toPatch)
143145
}
144146
}
145147

146148
export function toPatch(raw: PatchDb): Patch {
147149
return {
148150
type: raw.type,
151+
messageCreated: new Date(raw.message_created),
149152
message: String(raw.message_id) as MessageID,
150153
content: raw.content,
151154
creator: raw.creator,
@@ -157,6 +160,7 @@ export function toThread(raw: ThreadDb): Thread {
157160
return {
158161
card: raw.card_id,
159162
message: String(raw.message_id) as MessageID,
163+
messageCreated: new Date(raw.message_created),
160164
thread: raw.thread_id,
161165
repliesCount: raw.replies_count,
162166
lastReply: raw.last_reply
@@ -223,12 +227,12 @@ function toNotificationRaw(
223227

224228
let messageGroup: MessagesGroup | undefined
225229

226-
if (raw.message_group_blob_id != null && raw.message_group_from_sec != null && raw.message_group_to_sec != null) {
230+
if (raw.message_group_blob_id != null && raw.message_group_from_date != null && raw.message_group_to_date != null) {
227231
messageGroup = {
228232
card,
229233
blobId: raw.message_group_blob_id,
230-
fromSec: new Date(raw.message_group_from_sec),
231-
toSec: new Date(raw.message_group_to_sec),
234+
fromDate: new Date(raw.message_group_from_date),
235+
toDate: new Date(raw.message_group_to_date),
232236
count: raw.message_group_count ?? 0
233237
}
234238
}

0 commit comments

Comments
 (0)