aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHenry Jameson <me@hjkos.com>2019-01-11 03:00:11 +0300
committerHenry Jameson <me@hjkos.com>2019-01-11 03:00:11 +0300
commit48e811e6edc774affa3526e7a25df6bb07597c9d (patch)
treea461f78dab0c97b590aebe558d130d174726205b
parentef2585e32b546722f2157bd6203701deb495d2e9 (diff)
added some more explicit to string conversion since BE seem to be sending
numbers and it could cause an issue.
-rw-r--r--src/modules/statuses.js8
-rw-r--r--src/modules/users.js7
2 files changed, 13 insertions, 2 deletions
diff --git a/src/modules/statuses.js b/src/modules/statuses.js
index fe65d843..05626a02 100644
--- a/src/modules/statuses.js
+++ b/src/modules/statuses.js
@@ -105,6 +105,9 @@ export const findMaxId = (...args) => {
}
const mergeOrAdd = (arr, obj, item) => {
+ // For sequential IDs BE passes numbers as numbers, we want them as strings.
+ item.id = String(item.id)
+
const oldItem = obj[item.id]
if (oldItem) {
@@ -292,8 +295,13 @@ const addNewNotifications = (state, { dispatch, notifications, older, visibleNot
each(notifications, (notification) => {
const result = mergeOrAdd(allStatuses, allStatusesObject, notification.notice)
const action = result.item
+ // For sequential IDs BE passes numbers as numbers, we want them as strings.
+ action.id = String(action.id)
+
// Only add a new notification if we don't have one for the same action
+ // TODO: this technically works but should be checking for notification.id, not action.id i think
if (!find(state.notifications.data, (oldNotification) => oldNotification.action.id === action.id)) {
+ // TODO: adapt to "what if notification ids are not actually numbers"
state.notifications.maxId = Math.max(notification.id, state.notifications.maxId)
state.notifications.minId = Math.min(notification.id, state.notifications.minId)
diff --git a/src/modules/users.js b/src/modules/users.js
index adbd37dd..9d00b782 100644
--- a/src/modules/users.js
+++ b/src/modules/users.js
@@ -7,6 +7,9 @@ import { humanizeErrors } from './errors'
// TODO: Unify with mergeOrAdd in statuses.js
export const mergeOrAdd = (arr, obj, item) => {
+ // For sequential IDs BE passes numbers as numbers, we want them as strings.
+ item.id = String(item.id)
+
if (!item) { return false }
const oldItem = obj[item.id]
if (oldItem) {
@@ -64,10 +67,10 @@ export const mutations = {
each(users, (user) => mergeOrAdd(state.users, state.usersObject, user))
},
setUserForStatus (state, status) {
- status.user = state.usersObject[status.user.id]
+ status.user = state.usersObject[String(status.user.id)]
},
setUserForNotification (state, notification) {
- notification.action.user = state.usersObject[notification.action.user.id]
+ notification.action.user = state.usersObject[String(notification.action.user.id)]
},
setColor (state, { user: { id }, highlighted }) {
const user = state.usersObject[id]