Skip to content

Commit

Permalink
Merge pull request #693 from h3poteto/iss-662
Browse files Browse the repository at this point in the history
refs #662 Add streaming update for direct message
  • Loading branch information
h3poteto committed Nov 4, 2018
2 parents b1efcda + 78a6fbd commit 45fd989
Show file tree
Hide file tree
Showing 12 changed files with 118 additions and 159 deletions.
37 changes: 37 additions & 0 deletions src/main/index.js
Expand Up @@ -421,6 +421,43 @@ ipcMain.on('stop-user-streaming', (event, _) => {
}
})

let directMessagesStreaming = null

ipcMain.on('start-directmessages-streaming', (event, ac) => {
accountManager.getAccount(ac._id)
.catch((err) => {
log.error(err)
event.sender.send('error-start-directmessages-streaming', err)
})
.then((account) => {
// Stop old directmessages streaming
if (directMessagesStreaming !== null) {
directMessagesStreaming.stop()
directMessagesStreaming = null
}

directMessagesStreaming = new StreamingManager(account)
directMessagesStreaming.start(
'direct',
null,
(update) => {
event.sender.send('update-start-directmessages-streaming', update)
},
(err) => {
log.error(err)
event.sender.send('error-start-directmessages-streaming', err)
}
)
})
})

ipcMain.on('stop-directmessages-streaming', (event, _) => {
if (directMessagesStreaming !== null) {
directMessagesStreaming.stop()
directMessagesStreaming = null
}
})

let localStreaming = null

ipcMain.on('start-local-streaming', (event, ac) => {
Expand Down
4 changes: 4 additions & 0 deletions src/renderer/components/TimelineSpace.vue
Expand Up @@ -74,6 +74,8 @@ export default {
window.removeEventListener('drop', this.handleDrop)
this.$store.dispatch('TimelineSpace/stopUserStreaming')
this.$store.dispatch('TimelineSpace/unbindUserStreaming')
this.$store.dispatch('TimelineSpace/stopDirectMessagesStreaming')
this.$store.dispatch('TimelineSpace/unbindDirectMessagesStreaming')
this.$store.dispatch('TimelineSpace/stopLocalStreaming')
this.$store.dispatch('TimelineSpace/unbindLocalStreaming')
},
Expand Down Expand Up @@ -134,6 +136,8 @@ export default {
})
this.$store.dispatch('TimelineSpace/bindLocalStreaming', 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/fetchInstance', account)
},
Expand Down
30 changes: 3 additions & 27 deletions src/renderer/components/TimelineSpace/Contents/DirectMessages.vue
Expand Up @@ -32,10 +32,12 @@
import { mapState, mapGetters } from 'vuex'
import Toot from './Cards/Toot'
import scrollTop from '../../utils/scroll'
import reloadable from '~/src/renderer/components/mixins/reloadable'
export default {
name: 'directmessages',
components: { Toot },
mixins: [reloadable],
data () {
return {
focusedId: null
Expand Down Expand Up @@ -132,33 +134,7 @@ export default {
async reload () {
this.$store.commit('TimelineSpace/changeLoading', true)
try {
const account = await this.$store.dispatch('TimelineSpace/localAccount', this.$route.params.id).catch((err) => {
this.$message({
message: this.$t('message.account_load_error'),
type: 'error'
})
throw err
})
await this.$store.dispatch('TimelineSpace/stopUserStreaming')
await this.$store.dispatch('TimelineSpace/stopLocalStreaming')
await this.$store.dispatch('TimelineSpace/Contents/DirectMessages/fetchTimeline', account)
.catch(() => {
this.$message({
message: this.$t('message.timeline_fetch_error'),
type: 'error'
})
})
await this.$store.dispatch('TimelineSpace/Contents/Local/fetchLocalTimeline', account)
this.$store.dispatch('TimelineSpace/startUserStreaming', account)
.catch(() => {
this.$message({
message: this.$t('message.start_streaming_error'),
type: 'error'
})
})
this.$store.dispatch('TimelineSpace/startLocalStreaming', account)
await this.reloadable()
} finally {
this.$store.commit('TimelineSpace/changeLoading', false)
}
Expand Down
19 changes: 3 additions & 16 deletions src/renderer/components/TimelineSpace/Contents/Favourites.vue
Expand Up @@ -29,10 +29,12 @@
import { mapState, mapGetters } from 'vuex'
import Toot from './Cards/Toot'
import scrollTop from '../../utils/scroll'
import reloadable from '~/src/renderer/components/mixins/reloadable'
export default {
name: 'favourites',
components: { Toot },
mixins: [reloadable],
data () {
return {
heading: true,
Expand Down Expand Up @@ -123,29 +125,14 @@ export default {
async reload () {
this.$store.commit('TimelineSpace/changeLoading', true)
try {
const account = await this.$store.dispatch('TimelineSpace/localAccount', this.$route.params.id).catch((err) => {
this.$message({
message: this.$t('message.account_load_error'),
type: 'error'
})
throw err
})
await this.$store.dispatch('TimelineSpace/stopUserStreaming')
await this.$store.dispatch('TimelineSpace/stopLocalStreaming')
await this.$store.dispatch('TimelineSpace/Contents/Home/fetchTimeline', account)
await this.$store.dispatch('TimelineSpace/Contents/Local/fetchLocalTimeline', account)
const account = await this.reloadable()
await this.$store.dispatch('TimelineSpace/Contents/Favourites/fetchFavourites', account)
.catch(() => {
this.$message({
message: this.$t('message.favourite_fetch_error'),
type: 'error'
})
})
this.$store.dispatch('TimelineSpace/startUserStreaming', account)
this.$store.dispatch('TimelineSpace/startLocalStreaming', account)
} finally {
this.$store.commit('TimelineSpace/changeLoading', false)
}
Expand Down
21 changes: 4 additions & 17 deletions src/renderer/components/TimelineSpace/Contents/Hashtag/Tag.vue
Expand Up @@ -14,7 +14,7 @@
v-on:delete="deleteToot"
@focusNext="focusNext"
@focusPrev="focusPrev"
@selectToot="focusToot(index)"
@selectToot="focusToot(message)"
>
</toot>
</div>
Expand All @@ -31,10 +31,12 @@
import { mapState, mapGetters } from 'vuex'
import Toot from '../Cards/Toot'
import scrollTop from '../../../utils/scroll'
import reloadable from '~/src/renderer/components/mixins/reloadable'
export default {
name: 'tag',
components: { Toot },
mixins: [reloadable],
props: ['tag'],
data () {
return {
Expand Down Expand Up @@ -158,30 +160,15 @@ export default {
const tag = this.tag
this.$store.commit('TimelineSpace/changeLoading', true)
try {
const account = await this.$store.dispatch('TimelineSpace/localAccount', this.$route.params.id).catch((err) => {
this.$message({
message: this.$t('message.account_load_error'),
type: 'error'
})
throw err
})
await this.$store.dispatch('TimelineSpace/stopUserStreaming')
await this.$store.dispatch('TimelineSpace/stopLocalStreaming')
await this.reloadable()
await this.$store.dispatch('TimelineSpace/Contents/Hashtag/Tag/stopStreaming')
await this.$store.dispatch('TimelineSpace/Contents/Hashtag/Tag/fetchTimeline', account)
await this.$store.dispatch('TimelineSpace/Contents/Local/fetchLocalTimeline', account)
await this.$store.dispatch('TimelineSpace/Contents/Hashtag/Tag/fetch', tag)
.catch(() => {
this.$message({
message: this.$t('message.timeline_fetch_error'),
type: 'error'
})
})
this.$store.dispatch('TimelineSpace/startUserStreaming', account)
this.$store.dispatch('TimelineSpace/startLocalStreaming', account)
this.$store.dispatch('TimelineSpace/Contents/Hashtag/Tag/startStreaming', tag)
.catch(() => {
this.$message({
Expand Down
30 changes: 3 additions & 27 deletions src/renderer/components/TimelineSpace/Contents/Home.vue
Expand Up @@ -32,10 +32,12 @@
import { mapState, mapGetters } from 'vuex'
import Toot from './Cards/Toot'
import scrollTop from '../../utils/scroll'
import reloadable from '~/src/renderer/components/mixins/reloadable'
export default {
name: 'home',
components: { Toot },
mixins: [reloadable],
data () {
return {
focusedId: null
Expand Down Expand Up @@ -132,33 +134,7 @@ export default {
async reload () {
this.$store.commit('TimelineSpace/changeLoading', true)
try {
const account = await this.$store.dispatch('TimelineSpace/localAccount', this.$route.params.id).catch((err) => {
this.$message({
message: this.$t('message.account_load_error'),
type: 'error'
})
throw err
})
await this.$store.dispatch('TimelineSpace/stopUserStreaming')
await this.$store.dispatch('TimelineSpace/stopLocalStreaming')
await this.$store.dispatch('TimelineSpace/Contents/Home/fetchTimeline', account)
.catch(() => {
this.$message({
message: this.$t('message.timeline_fetch_error'),
type: 'error'
})
})
await this.$store.dispatch('TimelineSpace/Contents/Local/fetchLocalTimeline', account)
this.$store.dispatch('TimelineSpace/startUserStreaming', account)
.catch(() => {
this.$message({
message: this.$t('message.start_streaming_error'),
type: 'error'
})
})
this.$store.dispatch('TimelineSpace/startLocalStreaming', account)
await this.reloadable()
} finally {
this.$store.commit('TimelineSpace/changeLoading', false)
}
Expand Down
19 changes: 3 additions & 16 deletions src/renderer/components/TimelineSpace/Contents/Lists/Show.vue
Expand Up @@ -31,11 +31,13 @@
import { mapState, mapGetters } from 'vuex'
import Toot from '../Cards/Toot'
import scrollTop from '../../../utils/scroll'
import reloadable from '~/src/renderer/components/mixins/reloadable'
export default {
name: 'list',
props: ['list_id'],
components: { Toot },
mixins: [reloadable],
data () {
return {
focusedId: null
Expand Down Expand Up @@ -157,30 +159,15 @@ export default {
async reload () {
this.$store.commit('TimelineSpace/changeLoading', true)
try {
const account = await this.$store.dispatch('TimelineSpace/localAccount', this.$route.params.id).catch((err) => {
this.$message({
message: this.$t('message.account_load_error'),
type: 'error'
})
throw err
})
await this.$store.dispatch('TimelineSpace/stopUserStreaming')
await this.$store.dispatch('TimelineSpace/stopLocalStreaming')
await this.reloadable()
await this.$store.dispatch('TimelineSpace/Contents/Lists/Show/stopStreaming')
await this.$store.dispatch('TimelineSpace/Contents/Lists/Show/fetchTimeline', account)
await this.$store.dispatch('TimelineSpace/Contents/Local/fetchLocalTimeline', account)
await this.$store.dispatch('TimelineSpace/Contents/Lists/Show/fetchTimeline', this.list_id)
.catch(() => {
this.$message({
message: this.$t('message.timeline_fetch_error'),
type: 'error'
})
})
this.$store.dispatch('TimelineSpace/startUserStreaming', account)
this.$store.dispatch('TimelineSpace/startLocalStreaming', account)
this.$store.dispatch('TimelineSpace/Contents/Lists/Show/startStreaming', this.list_id)
.catch(() => {
this.$message({
Expand Down
30 changes: 3 additions & 27 deletions src/renderer/components/TimelineSpace/Contents/Local.vue
Expand Up @@ -32,10 +32,12 @@
import { mapState, mapGetters } from 'vuex'
import Toot from './Cards/Toot'
import scrollTop from '../../utils/scroll'
import reloadable from '~/src/renderer/components/mixins/reloadable'
export default {
name: 'local',
components: { Toot },
mixins: [reloadable],
data () {
return {
focusedId: null
Expand Down Expand Up @@ -131,33 +133,7 @@ export default {
async reload () {
this.$store.commit('TimelineSpace/changeLoading', true)
try {
const account = await this.$store.dispatch('TimelineSpace/localAccount', this.$route.params.id).catch((err) => {
this.$message({
message: this.$t('message.account_load_error'),
type: 'error'
})
throw err
})
await this.$store.dispatch('TimelineSpace/stopUserStreaming')
await this.$store.dispatch('TimelineSpace/stopLocalStreaming')
await this.$store.dispatch('TimelineSpace/Contents/Home/fetchTimeline', account)
await this.$store.dispatch('TimelineSpace/Contents/Local/fetchLocalTimeline', account)
.catch(() => {
this.$message({
message: this.$t('message.timeline_fetch_error'),
type: 'error'
})
})
this.$store.dispatch('TimelineSpace/startUserStreaming', account)
this.$store.dispatch('TimelineSpace/startLocalStreaming', account)
.catch(() => {
this.$message({
message: this.$t('message.start_streaming_error'),
type: 'error'
})
})
await this.reloadable()
} finally {
this.$store.commit('TimelineSpace/changeLoading', false)
}
Expand Down
17 changes: 3 additions & 14 deletions src/renderer/components/TimelineSpace/Contents/Notifications.vue
Expand Up @@ -30,10 +30,12 @@
import { mapState, mapGetters } from 'vuex'
import Notification from './Cards/Notification'
import scrollTop from '../../utils/scroll'
import reloadable from '~/src/renderer/components/mixins/reloadable'
export default {
name: 'notifications',
components: { Notification },
mixins: [reloadable],
data () {
return {
focusedId: null
Expand Down Expand Up @@ -126,18 +128,7 @@ export default {
async reload () {
this.$store.commit('TimelineSpace/changeLoading', true)
try {
const account = await this.$store.dispatch('TimelineSpace/localAccount', this.$route.params.id).catch((err) => {
this.$message({
message: this.$t('message.account_load_error'),
type: 'error'
})
throw err
})
await this.$store.dispatch('TimelineSpace/stopUserStreaming')
await this.$store.dispatch('TimelineSpace/stopLocalStreaming')
await this.$store.dispatch('TimelineSpace/Contents/Home/fetchTimeline', account)
await this.$store.dispatch('TimelineSpace/Contents/Local/fetchLocalTimeline', account)
const account = await this.reloadable()
await this.$store.dispatch('TimelineSpace/Contents/Notifications/fetchNotifications', account)
.catch(() => {
this.$message({
Expand All @@ -147,8 +138,6 @@ export default {
})
this.$store.dispatch('TimelineSpace/Contents/Notifications/resetBadge')
this.$store.dispatch('TimelineSpace/startUserStreaming', account)
this.$store.dispatch('TimelineSpace/startLocalStreaming', account)
} finally {
this.$store.commit('TimelineSpace/changeLoading', false)
}
Expand Down

0 comments on commit 45fd989

Please sign in to comment.