From 58ac8f51a219681e237494b8a730048f2eafbe58 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Sat, 3 Dec 2016 12:43:21 +0100 Subject: [PATCH 1/3] Treat mentions more like a timeline. --- src/components/mentions/mentions.js | 21 ++++++++--------- src/components/mentions/mentions.vue | 4 +--- src/modules/statuses.js | 29 +++++++++++++++++++++--- test/unit/specs/modules/statuses.spec.js | 16 +++++++++++++ 4 files changed, 53 insertions(+), 17 deletions(-) diff --git a/src/components/mentions/mentions.js b/src/components/mentions/mentions.js index e84d1912..46a1c63e 100644 --- a/src/components/mentions/mentions.js +++ b/src/components/mentions/mentions.js @@ -1,26 +1,25 @@ -import Status from '../status/status.vue' -// Temporary -import { prepareStatus } from '../../modules/statuses.js' -import { map } from 'lodash' +import Timeline from '../timeline/timeline.vue' const Mentions = { - data () { - return { - mentions: [] - } - }, computed: { username () { return this.$route.params.username + }, + timeline () { + return this.$store.state.statuses.timelines.mentions } }, components: { - Status + Timeline }, created () { this.$store.state.api.backendInteractor.fetchMentions({username: this.username}) .then((mentions) => { - this.mentions = map(mentions, prepareStatus) + this.$store.dispatch('addNewStatuses', { + statuses: mentions, + timeline: 'mentions', + showImmediately: true + }) }) } } diff --git a/src/components/mentions/mentions.vue b/src/components/mentions/mentions.vue index a760719c..6287ca11 100644 --- a/src/components/mentions/mentions.vue +++ b/src/components/mentions/mentions.vue @@ -2,9 +2,7 @@
Mentions
-
- -
+
diff --git a/src/modules/statuses.js b/src/modules/statuses.js index 7ce07c96..f58b763a 100644 --- a/src/modules/statuses.js +++ b/src/modules/statuses.js @@ -8,6 +8,15 @@ export const defaultState = { notifications: [], favorites: new Set(), timelines: { + mentions: { + statuses: [], + faves: [], + visibleStatuses: [], + newStatusCount: 0, + maxId: 0, + minVisibleId: 0, + loading: false + }, public: { statuses: [], 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 }) => { // Sanity check if (!isArray(statuses)) { @@ -117,7 +134,15 @@ const addNewStatuses = (state, { statuses, showImmediately = false, timeline, us 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 })) { + const mentions = state.timelines.mentions + + mergeOrAdd(mentions.statuses, status) + mentions.newStatusCount += 1 + + sortTimeline(mentions) + addNotification({ type: 'mention', status, action: status }) } } @@ -213,9 +238,7 @@ const addNewStatuses = (state, { statuses, showImmediately = false, timeline, us // Keep the visible statuses sorted if (timeline) { - timelineObject.visibleStatuses = sortBy(timelineObject.visibleStatuses, ({id}) => -id) - timelineObject.statuses = sortBy(timelineObject.statuses, ({id}) => -id) - timelineObject.minVisibleId = (last(timelineObject.statuses) || {}).id + sortTimeline(timelineObject) } } diff --git a/test/unit/specs/modules/statuses.spec.js b/test/unit/specs/modules/statuses.spec.js index c9c1ad2c..deeeb477 100644 --- a/test/unit/specs/modules/statuses.spec.js +++ b/test/unit/specs/modules/statuses.spec.js @@ -292,6 +292,22 @@ describe('The Statuses module', () => { 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', () => { const state = cloneDeep(defaultState) const status = makeMockStatus({id: 1}) From 917917596fe7c9185590bf3c6cc267a0d6a89e5a Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Sat, 3 Dec 2016 12:48:37 +0100 Subject: [PATCH 2/3] Only add mentions to the mentions timeline once. --- src/modules/statuses.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/modules/statuses.js b/src/modules/statuses.js index f58b763a..f4bffebf 100644 --- a/src/modules/statuses.js +++ b/src/modules/statuses.js @@ -138,10 +138,13 @@ const addNewStatuses = (state, { statuses, showImmediately = false, timeline, us if (statusType(status) === 'status' && find(status.attentions, { id: user.id })) { const mentions = state.timelines.mentions - mergeOrAdd(mentions.statuses, status) - mentions.newStatusCount += 1 + // Add the mention to the mentions timeline + if (timelineObject !== mentions) { + mergeOrAdd(mentions.statuses, status) + mentions.newStatusCount += 1 - sortTimeline(mentions) + sortTimeline(mentions) + } addNotification({ type: 'mention', status, action: status }) } From 7b5a30db14f34f59932b072964355b4a0e0a9ddf Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Wed, 7 Dec 2016 09:34:48 +0100 Subject: [PATCH 3/3] Work around hotlinking restrictions. --- src/components/attachment/attachment.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/attachment/attachment.vue b/src/components/attachment/attachment.vue index 6bc0356a..e16cc7cd 100644 --- a/src/components/attachment/attachment.vue +++ b/src/components/attachment/attachment.vue @@ -9,7 +9,7 @@ - +