From ef2585e32b546722f2157bd6203701deb495d2e9 Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Fri, 11 Jan 2019 02:40:17 +0300 Subject: [PATCH] Remove all explicit and implicit conversions of statusId to number, changed explicit ones so that they convert them to string --- src/components/conversation-page/conversation-page.js | 4 ++-- src/components/conversation/conversation.js | 6 +++--- src/components/status/status.js | 4 ++-- src/modules/statuses.js | 10 ++++++---- src/services/notification_utils/notification_utils.js | 4 ++-- 5 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/components/conversation-page/conversation-page.js b/src/components/conversation-page/conversation-page.js index beffa5bb..bdf84d0c 100644 --- a/src/components/conversation-page/conversation-page.js +++ b/src/components/conversation-page/conversation-page.js @@ -1,5 +1,5 @@ import Conversation from '../conversation/conversation.vue' -import { find, toInteger } from 'lodash' +import { find } from 'lodash' const conversationPage = { components: { @@ -7,7 +7,7 @@ const conversationPage = { }, computed: { statusoid () { - const id = toInteger(this.$route.params.id) + const id = String(this.$route.params.id) const statuses = this.$store.state.statuses.allStatuses const status = find(statuses, {id}) diff --git a/src/components/conversation/conversation.js b/src/components/conversation/conversation.js index 9d9f7bbe..95432248 100644 --- a/src/components/conversation/conversation.js +++ b/src/components/conversation/conversation.js @@ -32,7 +32,7 @@ const conversation = { replies () { let i = 1 return reduce(this.conversation, (result, {id, in_reply_to_status_id}) => { - const irid = Number(in_reply_to_status_id) + const irid = String(in_reply_to_status_id) if (irid) { result[irid] = result[irid] || [] result[irid].push({ @@ -69,7 +69,7 @@ const conversation = { } }, getReplies (id) { - id = Number(id) + id = String(id) return this.replies[id] || [] }, focused (id) { @@ -80,7 +80,7 @@ const conversation = { } }, setHighlight (id) { - this.highlight = Number(id) + this.highlight = String(id) } } } diff --git a/src/components/status/status.js b/src/components/status/status.js index 73d53694..7e1e7dab 100644 --- a/src/components/status/status.js +++ b/src/components/status/status.js @@ -270,7 +270,7 @@ const Status = { }, replyEnter (id, event) { this.showPreview = true - const targetId = Number(id) + const targetId = String(id) const statuses = this.$store.state.statuses.allStatuses if (!this.preview) { @@ -295,7 +295,7 @@ const Status = { }, watch: { 'highlight': function (id) { - id = Number(id) + id = String(id) if (this.status.id === id) { let rect = this.$el.getBoundingClientRect() if (rect.top < 100) { diff --git a/src/modules/statuses.js b/src/modules/statuses.js index dccccf72..fe65d843 100644 --- a/src/modules/statuses.js +++ b/src/modules/statuses.js @@ -1,4 +1,4 @@ -import { includes, remove, slice, sortBy, toInteger, each, find, flatten, maxBy, minBy, merge, last, isArray } from 'lodash' +import { includes, remove, slice, each, find, flatten, maxBy, minBy, merge, last, isArray } from 'lodash' import apiService from '../services/api/api.service.js' // import parse from '../services/status_parser/status_parser.js' @@ -122,9 +122,11 @@ const mergeOrAdd = (arr, obj, item) => { } } +const sortById = (a, b) => a.id > b.id ? -1 : 1 + const sortTimeline = (timeline) => { - timeline.visibleStatuses = sortBy(timeline.visibleStatuses, ({id}) => -id) - timeline.statuses = sortBy(timeline.statuses, ({id}) => -id) + timeline.visibleStatuses = timeline.visibleStatuses.sort(sortById) + timeline.statuses = timeline.statuses.sort(sortById) timeline.minVisibleId = (last(timeline.visibleStatuses) || {}).id return timeline } @@ -200,7 +202,7 @@ const addNewStatuses = (state, { statuses, showImmediately = false, timeline, us } const favoriteStatus = (favorite, counter) => { - const status = find(allStatuses, { id: toInteger(favorite.in_reply_to_status_id) }) + const status = find(allStatuses, { id: String(favorite.in_reply_to_status_id) }) if (status) { // This is our favorite, so the relevant bit. if (favorite.user.id === user.id) { diff --git a/src/services/notification_utils/notification_utils.js b/src/services/notification_utils/notification_utils.js index f5ac0d47..c6782af4 100644 --- a/src/services/notification_utils/notification_utils.js +++ b/src/services/notification_utils/notification_utils.js @@ -10,8 +10,8 @@ export const visibleTypes = store => ([ ].filter(_ => _)) export const visibleNotificationsFromStore = store => { - // Don't know why, but sortBy([seen, -action.id]) doesn't work. - let sortedNotifications = sortBy(notificationsFromStore(store), ({action}) => -action.id) + // map is just to clone the array since sort mutates it and it causes some issues + let sortedNotifications = notificationsFromStore(store).map(_ => _).sort((a, b) => a.id > b.id ? -1 : 1) sortedNotifications = sortBy(sortedNotifications, 'seen') return sortedNotifications.filter((notification) => visibleTypes(store).includes(notification.type)) }