refs #662 Update direct messages with streaming

This commit is contained in:
AkiraFukushima 2018-11-04 01:37:30 +09:00
parent 6ed4fb0d65
commit 968039b5ae
3 changed files with 43 additions and 15 deletions

View File

@ -421,40 +421,40 @@ ipcMain.on('stop-user-streaming', (event, _) => {
} }
}) })
let directMessageStreaming = null let directMessagesStreaming = null
ipcMain.on('start-directmessage-streaming', (event, ac) => { ipcMain.on('start-directmessages-streaming', (event, ac) => {
accountManager.getAccount(ac._id) accountManager.getAccount(ac._id)
.catch((err) => { .catch((err) => {
log.error(err) log.error(err)
event.sender.send('error-start-directmessage-streaming', err) event.sender.send('error-start-directmessages-streaming', err)
}) })
.then((account) => { .then((account) => {
// Stop old directmessage streaming // Stop old directmessages streaming
if (directMessageStreaming !== null) { if (directMessagesStreaming !== null) {
directMessageStreaming.stop() directMessagesStreaming.stop()
directMessageStreaming = null directMessagesStreaming = null
} }
directMessageStreaming = new StreamingManager(account) directMessagesStreaming = new StreamingManager(account)
directMessageStreaming.start( directMessagesStreaming.start(
'direct', 'direct',
null, null,
(update) => { (update) => {
event.sender.send('update-start-directmessage-streaming', update) event.sender.send('update-start-directmessages-streaming', update)
}, },
(err) => { (err) => {
log.error(err) log.error(err)
event.sender.send('error-start-directmessage-streaming', err) event.sender.send('error-start-directmessages-streaming', err)
} }
) )
}) })
}) })
ipcMain.on('stop-directmessage-streaming', (event, _) => { ipcMain.on('stop-directmessages-streaming', (event, _) => {
if (directMessageStreaming !== null) { if (directMessagesStreaming !== null) {
directMessageStreaming.stop() directMessagesStreaming.stop()
directMessageStreaming = null directMessagesStreaming = null
} }
}) })

View File

@ -74,6 +74,8 @@ export default {
window.removeEventListener('drop', this.handleDrop) window.removeEventListener('drop', this.handleDrop)
this.$store.dispatch('TimelineSpace/stopUserStreaming') this.$store.dispatch('TimelineSpace/stopUserStreaming')
this.$store.dispatch('TimelineSpace/unbindUserStreaming') this.$store.dispatch('TimelineSpace/unbindUserStreaming')
this.$store.dispatch('TimelineSpace/stopDirectMessagesStreaming')
this.$store.dispatch('TimelineSpace/unbindDirectMessagesStreaming')
this.$store.dispatch('TimelineSpace/stopLocalStreaming') this.$store.dispatch('TimelineSpace/stopLocalStreaming')
this.$store.dispatch('TimelineSpace/unbindLocalStreaming') this.$store.dispatch('TimelineSpace/unbindLocalStreaming')
}, },
@ -134,6 +136,8 @@ export default {
}) })
this.$store.dispatch('TimelineSpace/bindLocalStreaming', account) this.$store.dispatch('TimelineSpace/bindLocalStreaming', account)
this.$store.dispatch('TimelineSpace/startLocalStreaming', account) this.$store.dispatch('TimelineSpace/startLocalStreaming', account)
this.$store.dispatch('TimelineSpace/bindDirectMessagesStreaming', account)
this.$store.dispatch('TimelineSpace/startDirectMessagesStreaming', account)
this.$store.dispatch('TimelineSpace/fetchEmojis', account) this.$store.dispatch('TimelineSpace/fetchEmojis', account)
this.$store.dispatch('TimelineSpace/fetchInstance', account) this.$store.dispatch('TimelineSpace/fetchInstance', account)
}, },

View File

@ -135,6 +135,23 @@ const TimelineSpace = {
}) })
}) })
}, },
bindDirectMessagesStreaming ({ commit, rootState }) {
ipcRenderer.on('update-start-directmessages-streaming', (event, update) => {
commit('TimelineSpace/Contents/DirectMessages/appendTimeline', update, { root: true })
if (rootState.TimelineSpace.Contents.DirectMessages.heading && Math.random() > 0.8) {
commit('TimelineSpace/Contents/DirectMessages/archiveTimeline', {}, { root: true })
}
commit('TimelineSpace/SideMenu/changeUnreadDirectMessagesTimeline', true, { root: true })
})
},
startDirectMessagesStreaming (_, account) {
return new Promise((resolve, reject) => {
ipcRenderer.send('start-directmessages-streaming', account)
ipcRenderer.once('error-start-directmessages-streaming', (event, err) => {
reject(err)
})
})
},
unbindUserStreaming () { unbindUserStreaming () {
ipcRenderer.removeAllListeners('update-start-user-streaming') ipcRenderer.removeAllListeners('update-start-user-streaming')
ipcRenderer.removeAllListeners('notification-start-user-streaming') ipcRenderer.removeAllListeners('notification-start-user-streaming')
@ -150,6 +167,13 @@ const TimelineSpace = {
stopLocalStreaming () { stopLocalStreaming () {
ipcRenderer.send('stop-local-streaming') ipcRenderer.send('stop-local-streaming')
}, },
unbindDirectMessagesStreaming () {
ipcRenderer.removeAllListeners('error-start-directmessages-streaming')
ipcRenderer.removeAllListeners('update-start-directmessages-streaming')
},
stopDirectMessagesStreaming () {
ipcRenderer.send('stop-drectmessages-streaming')
},
watchShortcutEvents ({ commit, dispatch }) { watchShortcutEvents ({ commit, dispatch }) {
ipcRenderer.on('CmdOrCtrl+N', () => { ipcRenderer.on('CmdOrCtrl+N', () => {
dispatch('TimelineSpace/Modals/NewToot/openModal', {}, { root: true }) dispatch('TimelineSpace/Modals/NewToot/openModal', {}, { root: true })