mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-26 16:53:09 +02:00
upd: store old date and use it in previous versions
This commit is contained in:
parent
2706b6b618
commit
83be996a3d
6 changed files with 27 additions and 6 deletions
11
packages/backend/migration/1697970083001-oldDateNoteEdit.js
Normal file
11
packages/backend/migration/1697970083001-oldDateNoteEdit.js
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
export class OldDateNoteEdit1697970083001 {
|
||||||
|
name = "OldDateNoteEdit1697970083001";
|
||||||
|
|
||||||
|
async up(queryRunner) {
|
||||||
|
await queryRunner.query(`ALTER TABLE "note_edit" ADD COLUMN "oldDate" TIMESTAMP WITH TIME ZONE`);
|
||||||
|
}
|
||||||
|
|
||||||
|
async down(queryRunner) {
|
||||||
|
await queryRunner.query(`ALTER TABLE "note_edit" DROP COLUMN "oldDate"`);
|
||||||
|
}
|
||||||
|
}
|
|
@ -388,6 +388,8 @@ export class NoteEditService implements OnApplicationShutdown {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Object.keys(update).length > 0) {
|
if (Object.keys(update).length > 0) {
|
||||||
|
const exists = await this.noteEditRepository.findOneBy({ noteId: oldnote.id });
|
||||||
|
|
||||||
await this.noteEditRepository.insert({
|
await this.noteEditRepository.insert({
|
||||||
id: this.idService.gen(),
|
id: this.idService.gen(),
|
||||||
noteId: oldnote.id,
|
noteId: oldnote.id,
|
||||||
|
@ -395,6 +397,7 @@ export class NoteEditService implements OnApplicationShutdown {
|
||||||
newText: update.text || undefined,
|
newText: update.text || undefined,
|
||||||
cw: update.cw || undefined,
|
cw: update.cw || undefined,
|
||||||
fileIds: undefined,
|
fileIds: undefined,
|
||||||
|
oldDate: exists ? oldnote.updatedAt as Date : this.idService.parse(oldnote.id).date,
|
||||||
updatedAt: new Date(),
|
updatedAt: new Date(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -48,4 +48,9 @@ export class NoteEdit {
|
||||||
comment: "The updated date of the Note.",
|
comment: "The updated date of the Note.",
|
||||||
})
|
})
|
||||||
public updatedAt: Date;
|
public updatedAt: Date;
|
||||||
|
|
||||||
|
@Column("timestamp with time zone", {
|
||||||
|
comment: "The old date from before the edit",
|
||||||
|
})
|
||||||
|
public oldDate: Date;
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,12 +50,13 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
||||||
|
|
||||||
for (const edit of edits) {
|
for (const edit of edits) {
|
||||||
editArray.push({
|
editArray.push({
|
||||||
|
oldDate: edit.oldDate,
|
||||||
updatedAt: edit.updatedAt,
|
updatedAt: edit.updatedAt,
|
||||||
text: edit.oldText,
|
text: edit.oldText,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
editArray = editArray.sort((a, b) => { return new Date(b.updatedAt).getTime() - new Date(a.updatedAt).getTime(); });
|
editArray = editArray.sort((a, b) => { return new Date(b.oldDate).getTime() - new Date(a.oldDate).getTime(); });
|
||||||
|
|
||||||
return editArray;
|
return editArray;
|
||||||
});
|
});
|
||||||
|
|
|
@ -24,7 +24,7 @@ export async function getNoteVersionsMenu(props: {
|
||||||
os.popup(defineAsyncComponent(() => import('@/components/SkOldNoteWindow.vue')), {
|
os.popup(defineAsyncComponent(() => import('@/components/SkOldNoteWindow.vue')), {
|
||||||
note: appearNote,
|
note: appearNote,
|
||||||
oldText: info.text,
|
oldText: info.text,
|
||||||
updatedAt: info.updatedAt,
|
updatedAt: info.oldDate ? info.oldDate : info.updatedAt,
|
||||||
}, {
|
}, {
|
||||||
}, 'closed');
|
}, 'closed');
|
||||||
}
|
}
|
||||||
|
@ -36,13 +36,13 @@ export async function getNoteVersionsMenu(props: {
|
||||||
|
|
||||||
await statePromise.then((versions) => {
|
await statePromise.then((versions) => {
|
||||||
for (const edit of versions) {
|
for (const edit of versions) {
|
||||||
const _time = edit.updatedAt == null ? NaN :
|
const _time = edit.oldDate == null ? NaN :
|
||||||
typeof edit.updatedAt === 'number' ? edit.updatedAt :
|
typeof edit.oldDate === 'number' ? edit.oldDate :
|
||||||
(edit.updatedAt instanceof Date ? edit.updatedAt : new Date(edit.updatedAt)).getTime();
|
(edit.oldDate instanceof Date ? edit.oldDate : new Date(edit.oldDate)).getTime();
|
||||||
|
|
||||||
menu.push({
|
menu.push({
|
||||||
icon: 'ph-pencil ph-bold ph-lg',
|
icon: 'ph-pencil ph-bold ph-lg',
|
||||||
text: dateTimeFormat.format(_time),
|
text: _time ? dateTimeFormat.format(_time) : dateTimeFormat.format(new Date(edit.updatedAt)),
|
||||||
action: () => openVersion(edit),
|
action: () => openVersion(edit),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -235,6 +235,7 @@ export type NoteEdit = {
|
||||||
cw: string;
|
cw: string;
|
||||||
fileIds: DriveFile['id'][];
|
fileIds: DriveFile['id'][];
|
||||||
updatedAt?: DateString;
|
updatedAt?: DateString;
|
||||||
|
oldDate: DateString;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Notification = {
|
export type Notification = {
|
||||||
|
|
Loading…
Reference in a new issue