This commit is contained in:
Tom Moor
2023-09-07 22:36:10 -04:00
parent bb555de1ba
commit d8bfb0fe5d
2 changed files with 44 additions and 15 deletions

View File

@@ -18,24 +18,48 @@ class Notification extends BaseModel {
@observable @observable
id: string; id: string;
/**
* The date the notification was marked as read.
*/
@Field @Field
@observable @observable
viewedAt: Date | null; viewedAt: Date | null;
/**
* The date the notification was archived.
*/
@Field @Field
@observable @observable
archivedAt: Date | null; archivedAt: Date | null;
/**
* The user that triggered the notification.
*/
actor?: User; actor?: User;
/**
* The document ID that the notification is associated with.
*/
documentId?: string; documentId?: string;
collectionId?: string; /**
* The document that the notification is associated with.
*/
document?: Document; document?: Document;
/**
* The collection ID that the notification is associated with.
*/
collectionId?: string;
/**
* The comment that the notification is associated with.
*/
comment?: Comment; comment?: Comment;
/**
* The type of notification.
*/
event: NotificationEventType; event: NotificationEventType;
/** /**
@@ -72,23 +96,29 @@ class Notification extends BaseModel {
*/ */
eventText(t: TFunction): string { eventText(t: TFunction): string {
switch (this.event) { switch (this.event) {
case "documents.publish": case NotificationEventType.PublishDocument:
return t("published"); return t("published");
case "documents.update": case NotificationEventType.UpdateDocument:
case "revisions.create": case NotificationEventType.CreateRevision:
return t("edited"); return t("edited");
case "collections.create": case NotificationEventType.CreateCollection:
return t("created the collection"); return t("created the collection");
case "documents.mentioned": case NotificationEventType.MentionedInDocument:
case "comments.mentioned": case NotificationEventType.MentionedInComment:
return t("mentioned you in"); return t("mentioned you in");
case "comments.create": case NotificationEventType.CreateComment:
return t("left a comment on"); return t("left a comment on");
default: default:
return this.event; return this.event;
} }
} }
/**
* Returns the subject of the notification. This is the title of the associated
* document.
*
* @returns The subject
*/
get subject() { get subject() {
return this.document?.title; return this.document?.title;
} }
@@ -131,10 +161,9 @@ class Notification extends BaseModel {
case NotificationEventType.ExportCompleted: { case NotificationEventType.ExportCompleted: {
return settingsPath("export"); return settingsPath("export");
} }
default: { default:
const check: never = this.event; this.event satisfies never;
throw new Error(`Unhandled case: ${check}`); return;
}
} }
} }
} }

View File

@@ -12,13 +12,13 @@ export async function changeLanguage(
toLanguageString: string | null | undefined, toLanguageString: string | null | undefined,
i18n: i18n i18n: i18n
) { ) {
// Languages are stored in en_US format in the database, however the
// frontend translation framework (i18next) expects en-US
const locale = toLanguageString const locale = toLanguageString
? unicodeCLDRtoBCP47(toLanguageString) ? unicodeCLDRtoBCP47(toLanguageString)
: undefined; : undefined;
if (locale && i18n.languages?.[0] !== locale) { if (locale && i18n.languages?.[0] !== locale) {
// Languages are stored in en_US format in the database, however the
// frontend translation framework (i18next) expects en-US
await i18n.changeLanguage(locale); await i18n.changeLanguage(locale);
await Desktop.bridge?.setSpellCheckerLanguages(["en-US", locale]); await Desktop.bridge?.setSpellCheckerLanguages(["en-US", locale]);
} }