diff --git a/packages/syncing-server/migrations/mysql/1684318117584-add_group_uuid_to_items.ts b/packages/syncing-server/migrations/mysql/1684318117584-add_group_uuid_to_items.ts index 251a0af7e..4412ed52c 100644 --- a/packages/syncing-server/migrations/mysql/1684318117584-add_group_uuid_to_items.ts +++ b/packages/syncing-server/migrations/mysql/1684318117584-add_group_uuid_to_items.ts @@ -13,9 +13,19 @@ export class AddGroupUuidToItems1684318117584 implements MigrationInterface { isNullable: true, }), ) + await queryRunner.addColumn( + 'items', + new TableColumn({ + name: 'last_edited_by_uuid', + type: 'varchar', + length: '36', + isNullable: true, + }), + ) } public async down(queryRunner: QueryRunner): Promise { await queryRunner.dropColumn('items', 'group_uuid') + await queryRunner.dropColumn('items', 'last_edited_by_uuid') } } diff --git a/packages/syncing-server/src/Domain/Item/Item.ts b/packages/syncing-server/src/Domain/Item/Item.ts index 187e6f50f..52c090b8e 100644 --- a/packages/syncing-server/src/Domain/Item/Item.ts +++ b/packages/syncing-server/src/Domain/Item/Item.ts @@ -81,6 +81,12 @@ export class Item { @Index('index_items_on_user_uuid') declare userUuid: string + @Column({ + name: 'last_edited_by_uuid', + length: 36, + }) + declare lastEditedByUuid: string + @Column({ type: 'tinyint', precision: 1, diff --git a/packages/syncing-server/src/Domain/Item/ItemFactory.ts b/packages/syncing-server/src/Domain/Item/ItemFactory.ts index 892d1dae5..ec43b1443 100644 --- a/packages/syncing-server/src/Domain/Item/ItemFactory.ts +++ b/packages/syncing-server/src/Domain/Item/ItemFactory.ts @@ -32,10 +32,14 @@ export class ItemFactory implements ItemFactoryInterface { newItem.uuid = dto.itemHash.uuid newItem.updatedWithSession = dto.sessionUuid newItem.contentSize = 0 + newItem.userUuid = dto.userUuid + if (dto.itemHash.content) { newItem.content = dto.itemHash.content } - newItem.userUuid = dto.userUuid + if (dto.itemHash.last_edited_by_uuid) { + newItem.lastEditedByUuid = dto.itemHash.last_edited_by_uuid + } if (dto.itemHash.group_uuid) { newItem.groupUuid = dto.itemHash.group_uuid } diff --git a/packages/syncing-server/src/Domain/Item/ItemHash.ts b/packages/syncing-server/src/Domain/Item/ItemHash.ts index 23971f95e..7aa71410e 100644 --- a/packages/syncing-server/src/Domain/Item/ItemHash.ts +++ b/packages/syncing-server/src/Domain/Item/ItemHash.ts @@ -2,6 +2,7 @@ import { ContentType } from '@standardnotes/common' export type ItemHash = { uuid: string + user_uuid: string content?: string content_type: ContentType deleted?: boolean @@ -10,6 +11,7 @@ export type ItemHash = { enc_item_key?: string items_key_id?: string group_uuid?: string + last_edited_by_uuid?: string | null created_at?: string created_at_timestamp?: number updated_at?: string diff --git a/packages/syncing-server/src/Domain/Item/ItemService.ts b/packages/syncing-server/src/Domain/Item/ItemService.ts index fe45a2050..4b590d685 100644 --- a/packages/syncing-server/src/Domain/Item/ItemService.ts +++ b/packages/syncing-server/src/Domain/Item/ItemService.ts @@ -133,6 +133,7 @@ export class ItemService implements ItemServiceInterface { existingItem, itemHash, sessionUuid: dto.sessionUuid, + userUuid: dto.userUuid, }) savedItems.push(updatedItem) } else { @@ -201,10 +202,14 @@ export class ItemService implements ItemServiceInterface { private async updateExistingItem(dto: { existingItem: Item itemHash: ItemHash + userUuid: string sessionUuid: string | null }): Promise { dto.existingItem.updatedWithSession = dto.sessionUuid dto.existingItem.contentSize = 0 + dto.existingItem.groupUuid = dto.itemHash.group_uuid ?? null + dto.existingItem.lastEditedByUuid = dto.userUuid + if (dto.itemHash.content) { dto.existingItem.content = dto.itemHash.content } @@ -215,8 +220,6 @@ export class ItemService implements ItemServiceInterface { dto.existingItem.deleted = dto.itemHash.deleted } - dto.existingItem.groupUuid = dto.itemHash.group_uuid ?? null - let wasMarkedAsDuplicate = false if (dto.itemHash.duplicate_of) { wasMarkedAsDuplicate = !dto.existingItem.duplicateOf diff --git a/packages/syncing-server/src/Projection/ItemProjection.ts b/packages/syncing-server/src/Projection/ItemProjection.ts index 9bf6b32bd..11e491af1 100644 --- a/packages/syncing-server/src/Projection/ItemProjection.ts +++ b/packages/syncing-server/src/Projection/ItemProjection.ts @@ -8,6 +8,8 @@ export type ItemProjection = { content_type: string auth_hash: string | null deleted: boolean + user_uuid: string + last_edited_by_uuid: string | null created_at: string created_at_timestamp: number updated_at: string diff --git a/packages/syncing-server/src/Projection/ItemProjector.ts b/packages/syncing-server/src/Projection/ItemProjector.ts index 5efe220ed..d5856b2f7 100644 --- a/packages/syncing-server/src/Projection/ItemProjector.ts +++ b/packages/syncing-server/src/Projection/ItemProjector.ts @@ -15,10 +15,7 @@ export class ItemProjector implements ProjectorInterface { projectCustom(_projectionType: string, item: Item): ItemProjectionWithUser { const fullProjection = this.projectFull(item) - return { - ...fullProjection, - user_uuid: item.userUuid, - } + return fullProjection } projectFull(item: Item): ItemProjection { @@ -37,6 +34,8 @@ export class ItemProjector implements ProjectorInterface { updated_at_timestamp: item.updatedAtTimestamp, updated_with_session: item.updatedWithSession, group_uuid: item.groupUuid, + user_uuid: item.userUuid, + last_edited_by_uuid: item.lastEditedByUuid, } } } diff --git a/packages/syncing-server/src/Projection/SavedItemProjection.ts b/packages/syncing-server/src/Projection/SavedItemProjection.ts index 1faafda56..1e2f5f098 100644 --- a/packages/syncing-server/src/Projection/SavedItemProjection.ts +++ b/packages/syncing-server/src/Projection/SavedItemProjection.ts @@ -9,4 +9,5 @@ export type SavedItemProjection = { updated_at: string updated_at_timestamp: number group_uuid: string | null + last_edited_by_uuid: string | null } diff --git a/packages/syncing-server/src/Projection/SavedItemProjector.ts b/packages/syncing-server/src/Projection/SavedItemProjector.ts index f4552b907..ca3d52f6a 100644 --- a/packages/syncing-server/src/Projection/SavedItemProjector.ts +++ b/packages/syncing-server/src/Projection/SavedItemProjector.ts @@ -28,6 +28,7 @@ export class SavedItemProjector implements ProjectorInterface