forked from AkkomaGang/akkoma-fe
Treat mentions more like a timeline.
This commit is contained in:
parent
df51d08814
commit
58ac8f51a2
4 changed files with 53 additions and 17 deletions
|
@ -1,26 +1,25 @@
|
||||||
import Status from '../status/status.vue'
|
import Timeline from '../timeline/timeline.vue'
|
||||||
// Temporary
|
|
||||||
import { prepareStatus } from '../../modules/statuses.js'
|
|
||||||
import { map } from 'lodash'
|
|
||||||
|
|
||||||
const Mentions = {
|
const Mentions = {
|
||||||
data () {
|
|
||||||
return {
|
|
||||||
mentions: []
|
|
||||||
}
|
|
||||||
},
|
|
||||||
computed: {
|
computed: {
|
||||||
username () {
|
username () {
|
||||||
return this.$route.params.username
|
return this.$route.params.username
|
||||||
|
},
|
||||||
|
timeline () {
|
||||||
|
return this.$store.state.statuses.timelines.mentions
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
components: {
|
components: {
|
||||||
Status
|
Timeline
|
||||||
},
|
},
|
||||||
created () {
|
created () {
|
||||||
this.$store.state.api.backendInteractor.fetchMentions({username: this.username})
|
this.$store.state.api.backendInteractor.fetchMentions({username: this.username})
|
||||||
.then((mentions) => {
|
.then((mentions) => {
|
||||||
this.mentions = map(mentions, prepareStatus)
|
this.$store.dispatch('addNewStatuses', {
|
||||||
|
statuses: mentions,
|
||||||
|
timeline: 'mentions',
|
||||||
|
showImmediately: true
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,9 +2,7 @@
|
||||||
<div class="timeline panel panel-default">
|
<div class="timeline panel panel-default">
|
||||||
<div class="panel-heading">Mentions</div>
|
<div class="panel-heading">Mentions</div>
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
<div class="timeline">
|
<Timeline v-bind:timeline="timeline" v-bind:timeline-name="'mentions'"/>
|
||||||
<status v-for="status in mentions" :key="status.id" v-bind:statusoid="status"></status>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
@ -8,6 +8,15 @@ export const defaultState = {
|
||||||
notifications: [],
|
notifications: [],
|
||||||
favorites: new Set(),
|
favorites: new Set(),
|
||||||
timelines: {
|
timelines: {
|
||||||
|
mentions: {
|
||||||
|
statuses: [],
|
||||||
|
faves: [],
|
||||||
|
visibleStatuses: [],
|
||||||
|
newStatusCount: 0,
|
||||||
|
maxId: 0,
|
||||||
|
minVisibleId: 0,
|
||||||
|
loading: false
|
||||||
|
},
|
||||||
public: {
|
public: {
|
||||||
statuses: [],
|
statuses: [],
|
||||||
faves: [],
|
faves: [],
|
||||||
|
@ -91,6 +100,14 @@ const mergeOrAdd = (arr, item) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const sortTimeline = (timeline) => {
|
||||||
|
timeline.visibleStatuses = sortBy(timeline.visibleStatuses, ({id}) => -id)
|
||||||
|
timeline.statuses = sortBy(timeline.statuses, ({id}) => -id)
|
||||||
|
timeline.minVisibleId = (last(timeline.statuses) || {}).id
|
||||||
|
|
||||||
|
return timeline
|
||||||
|
}
|
||||||
|
|
||||||
const addNewStatuses = (state, { statuses, showImmediately = false, timeline, user = {}, noIdUpdate = false }) => {
|
const addNewStatuses = (state, { statuses, showImmediately = false, timeline, user = {}, noIdUpdate = false }) => {
|
||||||
// Sanity check
|
// Sanity check
|
||||||
if (!isArray(statuses)) {
|
if (!isArray(statuses)) {
|
||||||
|
@ -117,7 +134,15 @@ const addNewStatuses = (state, { statuses, showImmediately = false, timeline, us
|
||||||
addNotification({ type: 'repeat', status: status.retweeted_status, action: status })
|
addNotification({ type: 'repeat', status: status.retweeted_status, action: status })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We are mentioned in a post
|
||||||
if (statusType(status) === 'status' && find(status.attentions, { id: user.id })) {
|
if (statusType(status) === 'status' && find(status.attentions, { id: user.id })) {
|
||||||
|
const mentions = state.timelines.mentions
|
||||||
|
|
||||||
|
mergeOrAdd(mentions.statuses, status)
|
||||||
|
mentions.newStatusCount += 1
|
||||||
|
|
||||||
|
sortTimeline(mentions)
|
||||||
|
|
||||||
addNotification({ type: 'mention', status, action: status })
|
addNotification({ type: 'mention', status, action: status })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -213,9 +238,7 @@ const addNewStatuses = (state, { statuses, showImmediately = false, timeline, us
|
||||||
|
|
||||||
// Keep the visible statuses sorted
|
// Keep the visible statuses sorted
|
||||||
if (timeline) {
|
if (timeline) {
|
||||||
timelineObject.visibleStatuses = sortBy(timelineObject.visibleStatuses, ({id}) => -id)
|
sortTimeline(timelineObject)
|
||||||
timelineObject.statuses = sortBy(timelineObject.statuses, ({id}) => -id)
|
|
||||||
timelineObject.minVisibleId = (last(timelineObject.statuses) || {}).id
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -292,6 +292,22 @@ describe('The Statuses module', () => {
|
||||||
expect(state.notifications[0].type).to.eql('mention')
|
expect(state.notifications[0].type).to.eql('mention')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('adds the message to mentions when you are mentioned', () => {
|
||||||
|
const user = { id: 1 }
|
||||||
|
const state = cloneDeep(defaultState)
|
||||||
|
const status = makeMockStatus({id: 1})
|
||||||
|
const mentionedStatus = makeMockStatus({id: 2})
|
||||||
|
mentionedStatus.attentions = [user]
|
||||||
|
|
||||||
|
mutations.addNewStatuses(state, { statuses: [status], user })
|
||||||
|
|
||||||
|
expect(state.timelines.mentions.statuses).to.have.length(0)
|
||||||
|
|
||||||
|
mutations.addNewStatuses(state, { statuses: [mentionedStatus], user })
|
||||||
|
expect(state.timelines.mentions.statuses).to.have.length(1)
|
||||||
|
expect(state.timelines.mentions.statuses).to.eql([mentionedStatus])
|
||||||
|
})
|
||||||
|
|
||||||
it('adds a notfication when one of the user\'s status is favorited', () => {
|
it('adds a notfication when one of the user\'s status is favorited', () => {
|
||||||
const state = cloneDeep(defaultState)
|
const state = cloneDeep(defaultState)
|
||||||
const status = makeMockStatus({id: 1})
|
const status = makeMockStatus({id: 1})
|
||||||
|
|
Loading…
Reference in a new issue