refs #3159 Create all account notification when launching
This commit is contained in:
parent
3bfd6430df
commit
3e604d94e9
|
@ -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<Lo
|
|||
}
|
||||
}
|
||||
)
|
||||
// Generate notifications received while the app was not running
|
||||
const client = generator(sns, acct.baseURL, acct.accessToken, 'Whalebird', proxy)
|
||||
const marker = await getMarker(client, id)
|
||||
if (marker !== null) {
|
||||
const unreadResponse = await client.getNotifications({ min_id: marker.last_read_id })
|
||||
unreadResponse.data.map(async notification => {
|
||||
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<LocalMarker | null> => {
|
||||
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
|
||||
}
|
||||
|
|
|
@ -142,17 +142,11 @@ const actions: ActionTree<NotificationsState, RootState> = {
|
|||
|
||||
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<Entity.Notification | LoadingCard>).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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue