Suppress comment notifications when viewing document (#4987)
* Updating views from collaboration server * refactor * Suppress comment notifications based on views * test
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { subMilliseconds } from "date-fns";
|
||||
import { Op } from "sequelize";
|
||||
import { FindOrCreateOptions, Op } from "sequelize";
|
||||
import {
|
||||
BelongsTo,
|
||||
Column,
|
||||
@@ -52,18 +52,21 @@ class View extends IdModel {
|
||||
@Column(DataType.UUID)
|
||||
documentId: string;
|
||||
|
||||
static async incrementOrCreate(where: {
|
||||
userId?: string;
|
||||
documentId?: string;
|
||||
collectionId?: string;
|
||||
}) {
|
||||
static async incrementOrCreate(
|
||||
where: {
|
||||
userId: string;
|
||||
documentId: string;
|
||||
},
|
||||
options?: FindOrCreateOptions
|
||||
) {
|
||||
const [model, created] = await this.findOrCreate({
|
||||
...options,
|
||||
where,
|
||||
});
|
||||
|
||||
if (!created) {
|
||||
model.count += 1;
|
||||
model.save();
|
||||
model.save(options);
|
||||
}
|
||||
|
||||
return model;
|
||||
@@ -104,20 +107,21 @@ class View extends IdModel {
|
||||
}
|
||||
|
||||
static async touch(documentId: string, userId: string, isEditing: boolean) {
|
||||
const [view] = await this.findOrCreate({
|
||||
const values: Partial<View> = {
|
||||
updatedAt: new Date(),
|
||||
};
|
||||
|
||||
if (isEditing) {
|
||||
values.lastEditingAt = new Date();
|
||||
}
|
||||
|
||||
await this.update(values, {
|
||||
where: {
|
||||
userId,
|
||||
documentId,
|
||||
},
|
||||
returning: false,
|
||||
});
|
||||
|
||||
if (isEditing) {
|
||||
const lastEditingAt = new Date();
|
||||
view.lastEditingAt = lastEditingAt;
|
||||
await view.save();
|
||||
}
|
||||
|
||||
return view;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user