Remove unread timeline and fix scroll position in direct messages
This commit is contained in:
parent
7d11dcf18d
commit
97bec5be6d
|
@ -133,8 +133,7 @@ let state = (): DirectMessagesState => {
|
||||||
return {
|
return {
|
||||||
lazyLoading: false,
|
lazyLoading: false,
|
||||||
heading: true,
|
heading: true,
|
||||||
timeline: [],
|
timeline: []
|
||||||
unreadTimeline: []
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -197,7 +196,6 @@ describe('Home', () => {
|
||||||
lazyLoading: false,
|
lazyLoading: false,
|
||||||
heading: true,
|
heading: true,
|
||||||
timeline: [status1],
|
timeline: [status1],
|
||||||
unreadTimeline: [],
|
|
||||||
showReblogs: true,
|
showReblogs: true,
|
||||||
showReplies: true
|
showReplies: true
|
||||||
}
|
}
|
||||||
|
|
|
@ -136,8 +136,7 @@ describe('TimelineSpace/Contents/DirectMessages', () => {
|
||||||
state = {
|
state = {
|
||||||
lazyLoading: false,
|
lazyLoading: false,
|
||||||
heading: true,
|
heading: true,
|
||||||
timeline: [status2, status1],
|
timeline: [status2, status1]
|
||||||
unreadTimeline: []
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
it('should be deleted', () => {
|
it('should be deleted', () => {
|
||||||
|
@ -151,8 +150,7 @@ describe('TimelineSpace/Contents/DirectMessages', () => {
|
||||||
state = {
|
state = {
|
||||||
lazyLoading: false,
|
lazyLoading: false,
|
||||||
heading: true,
|
heading: true,
|
||||||
timeline: [status2, rebloggedStatus],
|
timeline: [status2, rebloggedStatus]
|
||||||
unreadTimeline: []
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
it('should be deleted', () => {
|
it('should be deleted', () => {
|
||||||
|
@ -169,14 +167,12 @@ describe('TimelineSpace/Contents/DirectMessages', () => {
|
||||||
state = {
|
state = {
|
||||||
lazyLoading: false,
|
lazyLoading: false,
|
||||||
heading: true,
|
heading: true,
|
||||||
timeline: [status2, status1],
|
timeline: [status2, status1]
|
||||||
unreadTimeline: []
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
it('should be updated timeline', () => {
|
it('should be updated timeline', () => {
|
||||||
DirectMessages.mutations![MUTATION_TYPES.APPEND_TIMELINE](state, rebloggedStatus)
|
DirectMessages.mutations![MUTATION_TYPES.APPEND_TIMELINE](state, rebloggedStatus)
|
||||||
expect(state.timeline).toEqual([rebloggedStatus, status2, status1])
|
expect(state.timeline).toEqual([rebloggedStatus, status2, status1])
|
||||||
expect(state.unreadTimeline).toEqual([])
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -185,14 +181,12 @@ describe('TimelineSpace/Contents/DirectMessages', () => {
|
||||||
state = {
|
state = {
|
||||||
lazyLoading: false,
|
lazyLoading: false,
|
||||||
heading: true,
|
heading: true,
|
||||||
timeline: [rebloggedStatus, status2, status1],
|
timeline: [rebloggedStatus, status2, status1]
|
||||||
unreadTimeline: []
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
it('should not be updated timeline', () => {
|
it('should not be updated timeline', () => {
|
||||||
DirectMessages.mutations![MUTATION_TYPES.APPEND_TIMELINE](state, rebloggedStatus)
|
DirectMessages.mutations![MUTATION_TYPES.APPEND_TIMELINE](state, rebloggedStatus)
|
||||||
expect(state.timeline).toEqual([rebloggedStatus, status2, status1])
|
expect(state.timeline).toEqual([rebloggedStatus, status2, status1])
|
||||||
expect(state.unreadTimeline).toEqual([])
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -203,14 +197,12 @@ describe('TimelineSpace/Contents/DirectMessages', () => {
|
||||||
state = {
|
state = {
|
||||||
lazyLoading: false,
|
lazyLoading: false,
|
||||||
heading: false,
|
heading: false,
|
||||||
timeline: [status2, status1],
|
timeline: [status2, status1]
|
||||||
unreadTimeline: []
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
it('should be updated timeline', () => {
|
it('should be updated timeline', () => {
|
||||||
DirectMessages.mutations![MUTATION_TYPES.APPEND_TIMELINE](state, rebloggedStatus)
|
DirectMessages.mutations![MUTATION_TYPES.APPEND_TIMELINE](state, rebloggedStatus)
|
||||||
expect(state.timeline).toEqual([status2, status1])
|
expect(state.timeline).toEqual([rebloggedStatus, status2, status1])
|
||||||
expect(state.unreadTimeline).toEqual([rebloggedStatus])
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -219,14 +211,12 @@ describe('TimelineSpace/Contents/DirectMessages', () => {
|
||||||
state = {
|
state = {
|
||||||
lazyLoading: false,
|
lazyLoading: false,
|
||||||
heading: false,
|
heading: false,
|
||||||
timeline: [rebloggedStatus, status2, status1],
|
timeline: [rebloggedStatus, status2, status1]
|
||||||
unreadTimeline: []
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
it('should not be updated timeline', () => {
|
it('should not be updated timeline', () => {
|
||||||
DirectMessages.mutations![MUTATION_TYPES.APPEND_TIMELINE](state, rebloggedStatus)
|
DirectMessages.mutations![MUTATION_TYPES.APPEND_TIMELINE](state, rebloggedStatus)
|
||||||
expect(state.timeline).toEqual([rebloggedStatus, status2, status1])
|
expect(state.timeline).toEqual([rebloggedStatus, status2, status1])
|
||||||
expect(state.unreadTimeline).toEqual([])
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
<template>
|
<template>
|
||||||
<div id="directmessages" v-shortkey="shortcutEnabled ? { next: ['j'] } : {}" @shortkey="handleKey">
|
<div id="directmessages" v-shortkey="shortcutEnabled ? { next: ['j'] } : {}" @shortkey="handleKey">
|
||||||
<div class="unread">{{ unread.length > 0 ? unread.length : '' }}</div>
|
|
||||||
<div v-shortkey="{ linux: ['ctrl', 'r'], mac: ['meta', 'r'] }" @shortkey="reload()"></div>
|
<div v-shortkey="{ linux: ['ctrl', 'r'], mac: ['meta', 'r'] }" @shortkey="reload()"></div>
|
||||||
<DynamicScroller :items="timeline" :min-item-size="60" id="scroller" class="scroller" ref="scroller">
|
<DynamicScroller :items="timeline" :min-item-size="60" id="scroller" class="scroller" ref="scroller">
|
||||||
<template v-slot="{ item, index, active }">
|
<template v-slot="{ item, index, active }">
|
||||||
|
@ -32,6 +31,7 @@ import { mapState, mapGetters } from 'vuex'
|
||||||
import Toot from '~/src/renderer/components/organisms/Toot'
|
import Toot from '~/src/renderer/components/organisms/Toot'
|
||||||
import reloadable from '~/src/renderer/components/mixins/reloadable'
|
import reloadable from '~/src/renderer/components/mixins/reloadable'
|
||||||
import { Event } from '~/src/renderer/components/event'
|
import { Event } from '~/src/renderer/components/event'
|
||||||
|
import { ScrollPosition } from '~/src/renderer/components/utils/scroll'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'directmessages',
|
name: 'directmessages',
|
||||||
|
@ -39,15 +39,15 @@ export default {
|
||||||
mixins: [reloadable],
|
mixins: [reloadable],
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
focusedId: null
|
focusedId: null,
|
||||||
|
scroll: null
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
...mapState('TimelineSpace/Contents/DirectMessages', {
|
...mapState('TimelineSpace/Contents/DirectMessages', {
|
||||||
timeline: state => state.timeline,
|
timeline: state => state.timeline,
|
||||||
lazyLoading: state => state.lazyLoading,
|
lazyLoading: state => state.lazyLoading,
|
||||||
heading: state => state.heading,
|
heading: state => state.heading
|
||||||
unread: state => state.unreadTimeline
|
|
||||||
}),
|
}),
|
||||||
...mapState({
|
...mapState({
|
||||||
openSideBar: state => state.TimelineSpace.Contents.SideBar.openSideBar,
|
openSideBar: state => state.TimelineSpace.Contents.SideBar.openSideBar,
|
||||||
|
@ -86,11 +86,24 @@ export default {
|
||||||
this.focusedId = previousFocusedId
|
this.focusedId = previousFocusedId
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
const el = document.getElementById('scroller')
|
||||||
|
this.scroll = new ScrollPosition(el)
|
||||||
|
this.scroll.prepare()
|
||||||
},
|
},
|
||||||
beforeUpdate() {
|
beforeUpdate() {
|
||||||
if (this.$store.state.TimelineSpace.SideMenu.unreadDirectMessagesTimeline && this.heading) {
|
if (this.$store.state.TimelineSpace.SideMenu.unreadDirectMessagesTimeline && this.heading) {
|
||||||
this.$store.commit('TimelineSpace/SideMenu/changeUnreadDirectMessagesTimeline', false)
|
this.$store.commit('TimelineSpace/SideMenu/changeUnreadDirectMessagesTimeline', false)
|
||||||
}
|
}
|
||||||
|
if (!this.heading && !this.lazyLoading) {
|
||||||
|
const el = document.getElementById('scroller')
|
||||||
|
this.scroll = new ScrollPosition(el)
|
||||||
|
this.scroll.prepare()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
updated() {
|
||||||
|
if (this.scroll && !this.heading && !this.lazyLoading) {
|
||||||
|
this.scroll.restore()
|
||||||
|
}
|
||||||
},
|
},
|
||||||
beforeDestroy() {
|
beforeDestroy() {
|
||||||
if (!this.unreadNotification.direct) {
|
if (!this.unreadNotification.direct) {
|
||||||
|
@ -101,7 +114,6 @@ export default {
|
||||||
},
|
},
|
||||||
destroyed() {
|
destroyed() {
|
||||||
this.$store.commit('TimelineSpace/Contents/DirectMessages/changeHeading', true)
|
this.$store.commit('TimelineSpace/Contents/DirectMessages/changeHeading', true)
|
||||||
this.$store.commit('TimelineSpace/Contents/DirectMessages/mergeTimeline')
|
|
||||||
this.$store.commit('TimelineSpace/Contents/DirectMessages/archiveTimeline')
|
this.$store.commit('TimelineSpace/Contents/DirectMessages/archiveTimeline')
|
||||||
if (!this.unreadNotification.direct) {
|
if (!this.unreadNotification.direct) {
|
||||||
this.$store.commit('TimelineSpace/Contents/DirectMessages/clearTimeline')
|
this.$store.commit('TimelineSpace/Contents/DirectMessages/clearTimeline')
|
||||||
|
@ -124,7 +136,6 @@ export default {
|
||||||
this.$store.commit('TimelineSpace/Contents/DirectMessages/changeHeading', false)
|
this.$store.commit('TimelineSpace/Contents/DirectMessages/changeHeading', false)
|
||||||
} else if (newState === null && !this.heading) {
|
} else if (newState === null && !this.heading) {
|
||||||
this.$store.commit('TimelineSpace/Contents/DirectMessages/changeHeading', true)
|
this.$store.commit('TimelineSpace/Contents/DirectMessages/changeHeading', true)
|
||||||
this.$store.commit('TimelineSpace/Contents/DirectMessages/mergeTimeline')
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -154,16 +165,11 @@ export default {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
// for unread control
|
|
||||||
if (event.target.scrollTop > 5 && this.heading) {
|
if (event.target.scrollTop > 10 && this.heading) {
|
||||||
this.$store.commit('TimelineSpace/Contents/DirectMessages/changeHeading', false)
|
this.$store.commit('TimelineSpace/Contents/DirectMessages/changeHeading', false)
|
||||||
} else if (event.target.scrollTop <= 5 && !this.heading) {
|
} else if (event.target.scrollTop <= 10 && !this.heading) {
|
||||||
const currentPos = this.unread.length
|
this.$store.commit('TimelineSpace/Contents/DirectMessages/changeHeading', true)
|
||||||
if (currentPos === 0) {
|
|
||||||
this.$store.commit('TimelineSpace/Contents/DirectMessages/changeHeading', true)
|
|
||||||
}
|
|
||||||
this.$store.commit('TimelineSpace/Contents/DirectMessages/mergeTimeline')
|
|
||||||
this.$refs.scroller.scrollToItem(currentPos)
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
updateToot(message) {
|
updateToot(message) {
|
||||||
|
@ -227,21 +233,6 @@ export default {
|
||||||
height: 100%;
|
height: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.unread {
|
|
||||||
position: fixed;
|
|
||||||
right: 24px;
|
|
||||||
top: 48px;
|
|
||||||
background-color: rgba(0, 0, 0, 0.7);
|
|
||||||
color: #fff;
|
|
||||||
padding: 4px 8px;
|
|
||||||
border-radius: 0 0 2px 2px;
|
|
||||||
z-index: 1;
|
|
||||||
|
|
||||||
&:empty {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.loading-card {
|
.loading-card {
|
||||||
height: 60px;
|
height: 60px;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,14 +6,12 @@ export type DirectMessagesState = {
|
||||||
lazyLoading: boolean
|
lazyLoading: boolean
|
||||||
heading: boolean
|
heading: boolean
|
||||||
timeline: Array<Entity.Status>
|
timeline: Array<Entity.Status>
|
||||||
unreadTimeline: Array<Entity.Status>
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const state = (): DirectMessagesState => ({
|
const state = (): DirectMessagesState => ({
|
||||||
lazyLoading: false,
|
lazyLoading: false,
|
||||||
heading: true,
|
heading: true,
|
||||||
timeline: [],
|
timeline: []
|
||||||
unreadTimeline: []
|
|
||||||
})
|
})
|
||||||
|
|
||||||
export const MUTATION_TYPES = {
|
export const MUTATION_TYPES = {
|
||||||
|
@ -21,7 +19,6 @@ export const MUTATION_TYPES = {
|
||||||
CHANGE_HEADING: 'changeHeading',
|
CHANGE_HEADING: 'changeHeading',
|
||||||
APPEND_TIMELINE: 'appendTimeline',
|
APPEND_TIMELINE: 'appendTimeline',
|
||||||
UPDATE_TIMELINE: 'updateTimeline',
|
UPDATE_TIMELINE: 'updateTimeline',
|
||||||
MERGE_TIMELINE: 'mergeTimeline',
|
|
||||||
INSERT_TIMELINE: 'insertTimeline',
|
INSERT_TIMELINE: 'insertTimeline',
|
||||||
ARCHIVE_TIMELINE: 'archiveTimeline',
|
ARCHIVE_TIMELINE: 'archiveTimeline',
|
||||||
CLEAR_TIMELINE: 'clearTimeline',
|
CLEAR_TIMELINE: 'clearTimeline',
|
||||||
|
@ -38,21 +35,13 @@ const mutations: MutationTree<DirectMessagesState> = {
|
||||||
},
|
},
|
||||||
[MUTATION_TYPES.APPEND_TIMELINE]: (state, update: Entity.Status) => {
|
[MUTATION_TYPES.APPEND_TIMELINE]: (state, update: Entity.Status) => {
|
||||||
// Reject duplicated status in timeline
|
// Reject duplicated status in timeline
|
||||||
if (!state.timeline.find(item => item.id === update.id) && !state.unreadTimeline.find(item => item.id === update.id)) {
|
if (!state.timeline.find(item => item.id === update.id)) {
|
||||||
if (state.heading) {
|
state.timeline = [update].concat(state.timeline)
|
||||||
state.timeline = [update].concat(state.timeline)
|
|
||||||
} else {
|
|
||||||
state.unreadTimeline = [update].concat(state.unreadTimeline)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[MUTATION_TYPES.UPDATE_TIMELINE]: (state, messages: Array<Entity.Status>) => {
|
[MUTATION_TYPES.UPDATE_TIMELINE]: (state, messages: Array<Entity.Status>) => {
|
||||||
state.timeline = messages
|
state.timeline = messages
|
||||||
},
|
},
|
||||||
[MUTATION_TYPES.MERGE_TIMELINE]: state => {
|
|
||||||
state.timeline = state.unreadTimeline.slice(0, 80).concat(state.timeline)
|
|
||||||
state.unreadTimeline = []
|
|
||||||
},
|
|
||||||
[MUTATION_TYPES.INSERT_TIMELINE]: (state, messages: Array<Entity.Status>) => {
|
[MUTATION_TYPES.INSERT_TIMELINE]: (state, messages: Array<Entity.Status>) => {
|
||||||
state.timeline = state.timeline.concat(messages)
|
state.timeline = state.timeline.concat(messages)
|
||||||
},
|
},
|
||||||
|
@ -61,7 +50,6 @@ const mutations: MutationTree<DirectMessagesState> = {
|
||||||
},
|
},
|
||||||
[MUTATION_TYPES.CLEAR_TIMELINE]: state => {
|
[MUTATION_TYPES.CLEAR_TIMELINE]: state => {
|
||||||
state.timeline = []
|
state.timeline = []
|
||||||
state.unreadTimeline = []
|
|
||||||
},
|
},
|
||||||
[MUTATION_TYPES.UPDATE_TOOT]: (state, message: Entity.Status) => {
|
[MUTATION_TYPES.UPDATE_TOOT]: (state, message: Entity.Status) => {
|
||||||
// Replace target message in DirectMessagesTimeline and notifications
|
// Replace target message in DirectMessagesTimeline and notifications
|
||||||
|
|
Loading…
Reference in New Issue