Remove unread timeline and fix scroll position in direct messages

This commit is contained in:
AkiraFukushima 2021-07-25 23:23:12 +09:00
parent 7d11dcf18d
commit 97bec5be6d
No known key found for this signature in database
GPG Key ID: B6E51BAC4DE1A957
4 changed files with 32 additions and 65 deletions

View File

@ -133,8 +133,7 @@ let state = (): DirectMessagesState => {
return {
lazyLoading: false,
heading: true,
timeline: [],
unreadTimeline: []
timeline: []
}
}
@ -197,7 +196,6 @@ describe('Home', () => {
lazyLoading: false,
heading: true,
timeline: [status1],
unreadTimeline: [],
showReblogs: true,
showReplies: true
}

View File

@ -136,8 +136,7 @@ describe('TimelineSpace/Contents/DirectMessages', () => {
state = {
lazyLoading: false,
heading: true,
timeline: [status2, status1],
unreadTimeline: []
timeline: [status2, status1]
}
})
it('should be deleted', () => {
@ -151,8 +150,7 @@ describe('TimelineSpace/Contents/DirectMessages', () => {
state = {
lazyLoading: false,
heading: true,
timeline: [status2, rebloggedStatus],
unreadTimeline: []
timeline: [status2, rebloggedStatus]
}
})
it('should be deleted', () => {
@ -169,14 +167,12 @@ describe('TimelineSpace/Contents/DirectMessages', () => {
state = {
lazyLoading: false,
heading: true,
timeline: [status2, status1],
unreadTimeline: []
timeline: [status2, status1]
}
})
it('should be updated timeline', () => {
DirectMessages.mutations![MUTATION_TYPES.APPEND_TIMELINE](state, rebloggedStatus)
expect(state.timeline).toEqual([rebloggedStatus, status2, status1])
expect(state.unreadTimeline).toEqual([])
})
})
@ -185,14 +181,12 @@ describe('TimelineSpace/Contents/DirectMessages', () => {
state = {
lazyLoading: false,
heading: true,
timeline: [rebloggedStatus, status2, status1],
unreadTimeline: []
timeline: [rebloggedStatus, status2, status1]
}
})
it('should not be updated timeline', () => {
DirectMessages.mutations![MUTATION_TYPES.APPEND_TIMELINE](state, rebloggedStatus)
expect(state.timeline).toEqual([rebloggedStatus, status2, status1])
expect(state.unreadTimeline).toEqual([])
})
})
})
@ -203,14 +197,12 @@ describe('TimelineSpace/Contents/DirectMessages', () => {
state = {
lazyLoading: false,
heading: false,
timeline: [status2, status1],
unreadTimeline: []
timeline: [status2, status1]
}
})
it('should be updated timeline', () => {
DirectMessages.mutations![MUTATION_TYPES.APPEND_TIMELINE](state, rebloggedStatus)
expect(state.timeline).toEqual([status2, status1])
expect(state.unreadTimeline).toEqual([rebloggedStatus])
expect(state.timeline).toEqual([rebloggedStatus, status2, status1])
})
})
@ -219,14 +211,12 @@ describe('TimelineSpace/Contents/DirectMessages', () => {
state = {
lazyLoading: false,
heading: false,
timeline: [rebloggedStatus, status2, status1],
unreadTimeline: []
timeline: [rebloggedStatus, status2, status1]
}
})
it('should not be updated timeline', () => {
DirectMessages.mutations![MUTATION_TYPES.APPEND_TIMELINE](state, rebloggedStatus)
expect(state.timeline).toEqual([rebloggedStatus, status2, status1])
expect(state.unreadTimeline).toEqual([])
})
})
})

View File

@ -1,6 +1,5 @@
<template>
<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>
<DynamicScroller :items="timeline" :min-item-size="60" id="scroller" class="scroller" ref="scroller">
<template v-slot="{ item, index, active }">
@ -32,6 +31,7 @@ import { mapState, mapGetters } from 'vuex'
import Toot from '~/src/renderer/components/organisms/Toot'
import reloadable from '~/src/renderer/components/mixins/reloadable'
import { Event } from '~/src/renderer/components/event'
import { ScrollPosition } from '~/src/renderer/components/utils/scroll'
export default {
name: 'directmessages',
@ -39,15 +39,15 @@ export default {
mixins: [reloadable],
data() {
return {
focusedId: null
focusedId: null,
scroll: null
}
},
computed: {
...mapState('TimelineSpace/Contents/DirectMessages', {
timeline: state => state.timeline,
lazyLoading: state => state.lazyLoading,
heading: state => state.heading,
unread: state => state.unreadTimeline
heading: state => state.heading
}),
...mapState({
openSideBar: state => state.TimelineSpace.Contents.SideBar.openSideBar,
@ -86,11 +86,24 @@ export default {
this.focusedId = previousFocusedId
})
})
const el = document.getElementById('scroller')
this.scroll = new ScrollPosition(el)
this.scroll.prepare()
},
beforeUpdate() {
if (this.$store.state.TimelineSpace.SideMenu.unreadDirectMessagesTimeline && this.heading) {
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() {
if (!this.unreadNotification.direct) {
@ -101,7 +114,6 @@ export default {
},
destroyed() {
this.$store.commit('TimelineSpace/Contents/DirectMessages/changeHeading', true)
this.$store.commit('TimelineSpace/Contents/DirectMessages/mergeTimeline')
this.$store.commit('TimelineSpace/Contents/DirectMessages/archiveTimeline')
if (!this.unreadNotification.direct) {
this.$store.commit('TimelineSpace/Contents/DirectMessages/clearTimeline')
@ -124,7 +136,6 @@ export default {
this.$store.commit('TimelineSpace/Contents/DirectMessages/changeHeading', false)
} else if (newState === null && !this.heading) {
this.$store.commit('TimelineSpace/Contents/DirectMessages/changeHeading', true)
this.$store.commit('TimelineSpace/Contents/DirectMessages/mergeTimeline')
}
}
},
@ -154,17 +165,12 @@ 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)
} else if (event.target.scrollTop <= 5 && !this.heading) {
const currentPos = this.unread.length
if (currentPos === 0) {
} else if (event.target.scrollTop <= 10 && !this.heading) {
this.$store.commit('TimelineSpace/Contents/DirectMessages/changeHeading', true)
}
this.$store.commit('TimelineSpace/Contents/DirectMessages/mergeTimeline')
this.$refs.scroller.scrollToItem(currentPos)
}
},
updateToot(message) {
this.$store.commit('TimelineSpace/Contents/DirectMessages/updateToot', message)
@ -227,21 +233,6 @@ export default {
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 {
height: 60px;
}

View File

@ -6,14 +6,12 @@ export type DirectMessagesState = {
lazyLoading: boolean
heading: boolean
timeline: Array<Entity.Status>
unreadTimeline: Array<Entity.Status>
}
const state = (): DirectMessagesState => ({
lazyLoading: false,
heading: true,
timeline: [],
unreadTimeline: []
timeline: []
})
export const MUTATION_TYPES = {
@ -21,7 +19,6 @@ export const MUTATION_TYPES = {
CHANGE_HEADING: 'changeHeading',
APPEND_TIMELINE: 'appendTimeline',
UPDATE_TIMELINE: 'updateTimeline',
MERGE_TIMELINE: 'mergeTimeline',
INSERT_TIMELINE: 'insertTimeline',
ARCHIVE_TIMELINE: 'archiveTimeline',
CLEAR_TIMELINE: 'clearTimeline',
@ -38,21 +35,13 @@ const mutations: MutationTree<DirectMessagesState> = {
},
[MUTATION_TYPES.APPEND_TIMELINE]: (state, update: Entity.Status) => {
// Reject duplicated status in timeline
if (!state.timeline.find(item => item.id === update.id) && !state.unreadTimeline.find(item => item.id === update.id)) {
if (state.heading) {
if (!state.timeline.find(item => item.id === update.id)) {
state.timeline = [update].concat(state.timeline)
} else {
state.unreadTimeline = [update].concat(state.unreadTimeline)
}
}
},
[MUTATION_TYPES.UPDATE_TIMELINE]: (state, messages: Array<Entity.Status>) => {
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>) => {
state.timeline = state.timeline.concat(messages)
},
@ -61,7 +50,6 @@ const mutations: MutationTree<DirectMessagesState> = {
},
[MUTATION_TYPES.CLEAR_TIMELINE]: state => {
state.timeline = []
state.unreadTimeline = []
},
[MUTATION_TYPES.UPDATE_TOOT]: (state, message: Entity.Status) => {
// Replace target message in DirectMessagesTimeline and notifications