Add list of followed hashtags to profile
This commit is contained in:
parent
dfba8be134
commit
e9f16af82d
7 changed files with 147 additions and 13 deletions
|
@ -5,9 +5,9 @@ import { compact, map, each, mergeWith, last, concat, uniq, isArray } from 'loda
|
|||
import { registerPushNotifications, unregisterPushNotifications } from '../services/push/push.js'
|
||||
|
||||
// TODO: Unify with mergeOrAdd in statuses.js
|
||||
export const mergeOrAdd = (arr, obj, item) => {
|
||||
export const mergeOrAdd = (arr, obj, item, key = 'id') => {
|
||||
if (!item) { return false }
|
||||
const oldItem = obj[item.id]
|
||||
const oldItem = obj[item[key]]
|
||||
if (oldItem) {
|
||||
// We already have this, so only merge the new info.
|
||||
mergeWith(oldItem, item, mergeArrayLength)
|
||||
|
@ -15,7 +15,7 @@ export const mergeOrAdd = (arr, obj, item) => {
|
|||
} else {
|
||||
// This is a new item, prepare it
|
||||
arr.push(item)
|
||||
obj[item.id] = item
|
||||
obj[item[key]] = item
|
||||
if (item.screen_name && !item.screen_name.includes('@')) {
|
||||
obj[item.screen_name.toLowerCase()] = item
|
||||
}
|
||||
|
@ -157,6 +157,14 @@ export const mutations = {
|
|||
const user = state.usersObject[id]
|
||||
user.followerIds = uniq(concat(user.followerIds || [], followerIds))
|
||||
},
|
||||
saveFollowedTagIds (state, { id, followedTagIds }) {
|
||||
const user = state.usersObject[id]
|
||||
user.followedTagIds = uniq(concat(user.followedTagIds || [], followedTagIds))
|
||||
},
|
||||
saveFollowedTagPagination (state, { id, pagination }) {
|
||||
const user = state.usersObject[id]
|
||||
user.followedTagPagination = pagination
|
||||
},
|
||||
// Because frontend doesn't have a reason to keep these stuff in memory
|
||||
// outside of viewing someones user profile.
|
||||
clearFriends (state, userId) {
|
||||
|
@ -171,6 +179,12 @@ export const mutations = {
|
|||
user['followerIds'] = []
|
||||
}
|
||||
},
|
||||
clearFollowedTags (state, userId) {
|
||||
const user = state.usersObject[userId]
|
||||
if (user) {
|
||||
user['followedTagIds'] = []
|
||||
}
|
||||
},
|
||||
addNewUsers (state, users) {
|
||||
each(users, (user) => {
|
||||
if (user.relationship) {
|
||||
|
@ -179,6 +193,11 @@ export const mutations = {
|
|||
mergeOrAdd(state.users, state.usersObject, user)
|
||||
})
|
||||
},
|
||||
addNewTags (state, tags) {
|
||||
each(tags, (tag) => {
|
||||
mergeOrAdd(state.tags, state.tagsObject, tag, 'name')
|
||||
})
|
||||
},
|
||||
updateUserRelationship (state, relationships) {
|
||||
relationships.forEach((relationship) => {
|
||||
state.relationships[relationship.id] = relationship
|
||||
|
@ -271,7 +290,11 @@ export const getters = {
|
|||
relationship: state => id => {
|
||||
const rel = id && state.relationships[id]
|
||||
return rel || { id, loading: true }
|
||||
}
|
||||
},
|
||||
findTag: state => query => {
|
||||
const result = state.tagsObject[query]
|
||||
return result
|
||||
},
|
||||
}
|
||||
|
||||
export const defaultState = {
|
||||
|
@ -282,7 +305,9 @@ export const defaultState = {
|
|||
usersObject: {},
|
||||
signUpPending: false,
|
||||
signUpErrors: [],
|
||||
relationships: {}
|
||||
relationships: {},
|
||||
tags: [],
|
||||
tagsObject: {}
|
||||
}
|
||||
|
||||
const users = {
|
||||
|
@ -402,12 +427,27 @@ const users = {
|
|||
return followers
|
||||
})
|
||||
},
|
||||
fetchFollowedTags ({ rootState, commit }, id) {
|
||||
const user = rootState.users.usersObject[id]
|
||||
const pagination = user.followedTagPagination
|
||||
|
||||
return rootState.api.backendInteractor.getFollowedHashtags({ pagination })
|
||||
.then(({ data: tags, pagination }) => {
|
||||
commit('addNewTags', tags)
|
||||
commit('saveFollowedTagIds', { id, followedTagIds: tags.map(tag => tag.name) })
|
||||
commit('saveFollowedTagPagination', { id, pagination })
|
||||
return tags
|
||||
})
|
||||
},
|
||||
clearFriends ({ commit }, userId) {
|
||||
commit('clearFriends', userId)
|
||||
},
|
||||
clearFollowers ({ commit }, userId) {
|
||||
commit('clearFollowers', userId)
|
||||
},
|
||||
clearFollowedTags ({ commit }, userId) {
|
||||
commit('clearFollowedTags', userId)
|
||||
},
|
||||
subscribeUser ({ rootState, commit }, id) {
|
||||
return rootState.api.backendInteractor.subscribeUser({ id })
|
||||
.then((relationship) => commit('updateUserRelationship', [relationship]))
|
||||
|
@ -437,6 +477,9 @@ const users = {
|
|||
addNewUsers ({ commit }, users) {
|
||||
commit('addNewUsers', users)
|
||||
},
|
||||
addNewTags ({ commit }, tags) {
|
||||
commit('addNewTags', tags)
|
||||
},
|
||||
addNewStatuses (store, { statuses }) {
|
||||
const users = map(statuses, 'user')
|
||||
const retweetedUsers = compact(map(statuses, 'retweeted_status.user'))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue