From 3e604d94e9a28a03a48992f6f84a7d4969621f31 Mon Sep 17 00:00:00 2001
From: AkiraFukushima
Date: Thu, 24 Feb 2022 21:16:30 +0900
Subject: [PATCH] refs #3159 Create all account notification when launching
---
src/main/index.ts | 39 +++++++++++++++----
.../TimelineSpace/Contents/Notifications.ts | 8 +---
2 files changed, 32 insertions(+), 15 deletions(-)
diff --git a/src/main/index.ts b/src/main/index.ts
index a2b3bba1..2a4e52da 100644
--- a/src/main/index.ts
+++ b/src/main/index.ts
@@ -25,7 +25,7 @@ import path from 'path'
import ContextMenu from 'electron-context-menu'
import { initSplashScreen, Config } from '@trodi/electron-splashscreen'
import openAboutWindow from 'about-window'
-import { Entity, detector, NotificationType } from 'megalodon'
+import generator, { Entity, detector, NotificationType, MegalodonInterface } from 'megalodon'
import sanitizeHtml from 'sanitize-html'
import AutoLaunch from 'auto-launch'
import minimist from 'minimist'
@@ -672,6 +672,15 @@ ipcMain.on('start-all-user-streamings', (event: IpcMainEvent, accounts: Array {
+ await publishNotification(notification, event, id)
+ })
+ }
} catch (err: any) {
log.error(err)
const streamingError = new StreamingError(err.message, account.domain)
@@ -963,13 +972,6 @@ ipcMain.on('stop-tag-streaming', () => {
}
})
-ipcMain.handle(
- 'publish-notification',
- async (event: IpcMainInvokeEvent, notification: { notification: Entity.Notification; id: string }) => {
- await publishNotification(notification.notification, event, notification.id)
- }
-)
-
// sounds
ipcMain.on('fav-rt-action-sound', () => {
const preferences = new Preferences(preferencesDBPath)
@@ -1664,3 +1666,24 @@ const decodeLanguage = (lang: string): LanguageType => {
return Language[l]
}
}
+
+const getMarker = async (client: MegalodonInterface, accountID: string): Promise => {
+ let serverMarker: Entity.Marker | {} = {}
+ try {
+ const res = await client.getMarkers(['notifications'])
+ serverMarker = res.data
+ } catch (err) {
+ console.warn(err)
+ }
+ if ((serverMarker as Entity.Marker).notifications !== undefined) {
+ return {
+ timeline: 'notifications',
+ last_read_id: (serverMarker as Entity.Marker).notifications.last_read_id
+ } as LocalMarker
+ }
+ if (markerRepo === null) {
+ return null
+ }
+ const marker = await markerRepo.get(accountID, 'notifications')
+ return marker
+}
diff --git a/src/renderer/store/TimelineSpace/Contents/Notifications.ts b/src/renderer/store/TimelineSpace/Contents/Notifications.ts
index 07c03557..32f96121 100644
--- a/src/renderer/store/TimelineSpace/Contents/Notifications.ts
+++ b/src/renderer/store/TimelineSpace/Contents/Notifications.ts
@@ -142,17 +142,11 @@ const actions: ActionTree = {
const res = await client.getNotifications({ limit: 30, max_id: localMarker.last_read_id })
// Make sure whether new notifications exist or not
- const nextResponse = await client.getNotifications({ min_id: lastReadNotification.id })
+ const nextResponse = await client.getNotifications({ limit: 1, min_id: lastReadNotification.id })
if (nextResponse.data.length > 0) {
notifications = ([card] as Array).concat(notifications).concat(res.data)
// Generate notifications received while the app was not running
commit('TimelineSpace/SideMenu/changeUnreadNotifications', true, { root: true })
- nextResponse.data.forEach(n => {
- win.ipcRenderer.invoke('publish-notification', {
- notification: n,
- id: rootState.TimelineSpace.account._id
- })
- })
} else {
notifications = notifications.concat(res.data)
}