feat: Badge documents in sidebar that have been newly shared with you
This commit is contained in:
@@ -2,7 +2,7 @@ import { addDays, differenceInDays } from "date-fns";
|
||||
import i18n, { t } from "i18next";
|
||||
import floor from "lodash/floor";
|
||||
import { action, autorun, computed, observable, set } from "mobx";
|
||||
import { ExportContentType } from "@shared/types";
|
||||
import { ExportContentType, NotificationEventType } from "@shared/types";
|
||||
import type { JSONObject, NavigationNode } from "@shared/types";
|
||||
import Storage from "@shared/utils/Storage";
|
||||
import { isRTL } from "@shared/utils/rtl";
|
||||
@@ -13,6 +13,7 @@ import type { Properties } from "~/types";
|
||||
import { client } from "~/utils/ApiClient";
|
||||
import { settingsPath } from "~/utils/routeHelpers";
|
||||
import Collection from "./Collection";
|
||||
import Notification from "./Notification";
|
||||
import View from "./View";
|
||||
import ParanoidModel from "./base/ParanoidModel";
|
||||
import Field from "./decorators/Field";
|
||||
@@ -160,6 +161,24 @@ export default class Document extends ParanoidModel {
|
||||
@observable
|
||||
isCollectionDeleted: boolean;
|
||||
|
||||
/**
|
||||
* Returns the notifications associated with this document.
|
||||
*/
|
||||
@computed
|
||||
get notifications(): Notification[] {
|
||||
return this.store.rootStore.notifications.filter(
|
||||
(notification: Notification) => notification.documentId === this.id
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the unread notifications associated with this document.
|
||||
*/
|
||||
@computed
|
||||
get unreadNotifications(): Notification[] {
|
||||
return this.notifications.filter((notification) => !notification.viewedAt);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the direction of the document text, either "rtl" or "ltr"
|
||||
*/
|
||||
@@ -391,6 +410,20 @@ export default class Document extends ParanoidModel {
|
||||
return;
|
||||
}
|
||||
|
||||
// Mark associated unread notifications as read when the document is viewed
|
||||
this.store.rootStore.notifications
|
||||
.filter(
|
||||
(notification: Notification) =>
|
||||
!notification.viewedAt &&
|
||||
notification.documentId === this.id &&
|
||||
[
|
||||
NotificationEventType.AddUserToDocument,
|
||||
NotificationEventType.UpdateDocument,
|
||||
NotificationEventType.PublishDocument,
|
||||
].includes(notification.event)
|
||||
)
|
||||
.forEach((notification) => notification.markAsRead());
|
||||
|
||||
this.lastViewedAt = new Date().toString();
|
||||
|
||||
return this.store.rootStore.views.create({
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { TFunction } from "i18next";
|
||||
import { action, observable } from "mobx";
|
||||
import { action, computed, observable } from "mobx";
|
||||
import { NotificationEventType } from "@shared/types";
|
||||
import {
|
||||
collectionPath,
|
||||
@@ -154,6 +154,7 @@ class Notification extends Model {
|
||||
*
|
||||
* @returns The router path.
|
||||
*/
|
||||
@computed
|
||||
get path() {
|
||||
switch (this.event) {
|
||||
case NotificationEventType.PublishDocument:
|
||||
|
||||
Reference in New Issue
Block a user