From 7d01b3d8baf5bb6b34dfa4e9fe14a32805a821a1 Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Fri, 12 Apr 2019 10:49:22 +0300 Subject: [PATCH 01/82] Fix wrong usercard notification --- src/components/notification/notification.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/notification/notification.js b/src/components/notification/notification.js index 67d54724..e59e7497 100644 --- a/src/components/notification/notification.js +++ b/src/components/notification/notification.js @@ -23,7 +23,7 @@ const Notification = { return generateProfileLink(user.id, user.screen_name, this.$store.state.instance.restrictedNicknames) }, getUser (notification) { - return this.$store.state.users.usersObject[notification.action.user.id] + return this.$store.state.users.usersObject[notification.from_profile.id] } }, computed: { From 2ae05075758fef79c0a184faf398ddce1617e182 Mon Sep 17 00:00:00 2001 From: Brenden Bice Date: Fri, 12 Apr 2019 23:09:05 -0400 Subject: [PATCH 02/82] remove error message on no more following --- src/modules/users.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/modules/users.js b/src/modules/users.js index cd789f09..934bfd0b 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -81,7 +81,8 @@ export const mutations = { user.friends.push(friend) } }) - user.lastFriendId = last(friends).id + + user.lastFriendId = friends.length ? last(friends).id : last(user.friends).id }, addFollowers (state, { id, followers }) { const user = state.usersObject[id] From 41845389a9e5a9e905087057a721bb68ec5c732a Mon Sep 17 00:00:00 2001 From: Brenden Bice Date: Fri, 12 Apr 2019 23:12:22 -0400 Subject: [PATCH 03/82] display no message on empty data fetched from api --- src/modules/users.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/modules/users.js b/src/modules/users.js index 934bfd0b..6de50b80 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -81,8 +81,7 @@ export const mutations = { user.friends.push(friend) } }) - - user.lastFriendId = friends.length ? last(friends).id : last(user.friends).id + user.lastFriendId = last(user.friends).id }, addFollowers (state, { id, followers }) { const user = state.usersObject[id] @@ -91,7 +90,7 @@ export const mutations = { user.followers.push(follower) } }) - user.lastFollowerId = last(followers).id + user.lastFollowerId = last(user.followers).id }, // Because frontend doesn't have a reason to keep these stuff in memory // outside of viewing someones user profile. From e7010d73aca4a2555ef55c41de372ebdd28bd799 Mon Sep 17 00:00:00 2001 From: taehoon Date: Wed, 10 Apr 2019 13:49:39 -0400 Subject: [PATCH 04/82] store friends/followers in the global user repository --- src/components/user_profile/user_profile.js | 8 +-- src/modules/users.js | 65 +++++++------------ .../entity_normalizer.service.js | 4 +- 3 files changed, 30 insertions(+), 47 deletions(-) diff --git a/src/components/user_profile/user_profile.js b/src/components/user_profile/user_profile.js index d55d1517..4b0072ad 100644 --- a/src/components/user_profile/user_profile.js +++ b/src/components/user_profile/user_profile.js @@ -9,8 +9,8 @@ import withList from '../../hocs/with_list/with_list' const FollowerList = compose( withLoadMore({ - fetch: (props, $store) => $store.dispatch('addFollowers', props.userId), - select: (props, $store) => get($store.getters.findUser(props.userId), 'followers', []), + fetch: (props, $store) => $store.dispatch('fetchFollowers', props.userId), + select: (props, $store) => get($store.getters.findUser(props.userId), 'followerIds', []).map(id => $store.getters.findUser(id)), destory: (props, $store) => $store.dispatch('clearFollowers', props.userId), childPropName: 'entries', additionalPropNames: ['userId'] @@ -20,8 +20,8 @@ const FollowerList = compose( const FriendList = compose( withLoadMore({ - fetch: (props, $store) => $store.dispatch('addFriends', props.userId), - select: (props, $store) => get($store.getters.findUser(props.userId), 'friends', []), + fetch: (props, $store) => $store.dispatch('fetchFriends', props.userId), + select: (props, $store) => get($store.getters.findUser(props.userId), 'friendIds', []).map(id => $store.getters.findUser(id)), destory: (props, $store) => $store.dispatch('clearFriends', props.userId), childPropName: 'entries', additionalPropNames: ['userId'] diff --git a/src/modules/users.js b/src/modules/users.js index 6de50b80..74f33b81 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -1,5 +1,5 @@ import backendInteractorService from '../services/backend_interactor_service/backend_interactor_service.js' -import { compact, map, each, merge, find, last } from 'lodash' +import { compact, map, each, merge, last, concat, uniq } from 'lodash' import { set } from 'vue' import { registerPushNotifications, unregisterPushNotifications } from '../services/push/push.js' import oauthApi from '../services/new_api/oauth' @@ -73,42 +73,27 @@ export const mutations = { endLogin (state) { state.loggingIn = false }, - // TODO Clean after ourselves? - addFriends (state, { id, friends }) { + saveFriendIds (state, { id, friendIds }) { const user = state.usersObject[id] - each(friends, friend => { - if (!find(user.friends, { id: friend.id })) { - user.friends.push(friend) - } - }) - user.lastFriendId = last(user.friends).id + user.friendIds = uniq(concat(user.friendIds, friendIds)) }, - addFollowers (state, { id, followers }) { + saveFollowerIds (state, { id, followerIds }) { const user = state.usersObject[id] - each(followers, follower => { - if (!find(user.followers, { id: follower.id })) { - user.followers.push(follower) - } - }) - user.lastFollowerId = last(user.followers).id + user.followerIds = uniq(concat(user.followerIds, followerIds)) }, // Because frontend doesn't have a reason to keep these stuff in memory // outside of viewing someones user profile. clearFriends (state, userId) { const user = state.usersObject[userId] - if (!user) { - return + if (user) { + set(user, 'friendIds', []) } - user.friends = [] - user.lastFriendId = null }, clearFollowers (state, userId) { const user = state.usersObject[userId] - if (!user) { - return + if (user) { + set(user, 'followerIds', []) } - user.followers = [] - user.lastFollowerId = null }, addNewUsers (state, users) { each(users, (user) => mergeOrAdd(state.users, state.usersObject, user)) @@ -240,25 +225,23 @@ const users = { return store.rootState.api.backendInteractor.unmuteUser(id) .then((relationship) => store.commit('updateUserRelationship', [relationship])) }, - addFriends ({ rootState, commit }, fetchBy) { - return new Promise((resolve, reject) => { - const user = rootState.users.usersObject[fetchBy] - const maxId = user.lastFriendId - rootState.api.backendInteractor.fetchFriends({ id: user.id, maxId }) - .then((friends) => { - commit('addFriends', { id: user.id, friends }) - resolve(friends) - }).catch(() => { - reject() - }) - }) + fetchFriends ({ rootState, commit }, id) { + const user = rootState.users.usersObject[id] + const maxId = last(user.friendIds) + return rootState.api.backendInteractor.fetchFriends({ id, maxId }) + .then((friends) => { + commit('addNewUsers', friends) + commit('saveFriendIds', { id, friendIds: map(friends, 'id') }) + return friends + }) }, - addFollowers ({ rootState, commit }, fetchBy) { - const user = rootState.users.usersObject[fetchBy] - const maxId = user.lastFollowerId - return rootState.api.backendInteractor.fetchFollowers({ id: user.id, maxId }) + fetchFollowers ({ rootState, commit }, id) { + const user = rootState.users.usersObject[id] + const maxId = last(user.followerIds) + return rootState.api.backendInteractor.fetchFollowers({ id, maxId }) .then((followers) => { - commit('addFollowers', { id: user.id, followers }) + commit('addNewUsers', followers) + commit('saveFollowerIds', { id, followerIds: map(followers, 'id') }) return followers }) }, diff --git a/src/services/entity_normalizer/entity_normalizer.service.js b/src/services/entity_normalizer/entity_normalizer.service.js index aef7062d..d68e5a98 100644 --- a/src/services/entity_normalizer/entity_normalizer.service.js +++ b/src/services/entity_normalizer/entity_normalizer.service.js @@ -129,8 +129,8 @@ export const parseUser = (data) => { output.locked = data.locked output.followers_count = data.followers_count output.statuses_count = data.statuses_count - output.friends = [] - output.followers = [] + output.friendIds = [] + output.followerIds = [] if (data.pleroma) { output.follow_request_count = data.pleroma.follow_request_count } From d05bd31092cc41f45314a50eb71e0eb0ed6bafbe Mon Sep 17 00:00:00 2001 From: taehoon Date: Mon, 1 Apr 2019 15:34:18 -0400 Subject: [PATCH 05/82] setup vue-autosuggest --- package.json | 1 + yarn.lock | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/package.json b/package.json index c80e0f63..6b7a368e 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "sanitize-html": "^1.13.0", "sass-loader": "^4.0.2", "vue": "^2.5.13", + "vue-autosuggest": "^1.8.3", "vue-chat-scroll": "^1.2.1", "vue-compose": "^0.7.1", "vue-i18n": "^7.3.2", diff --git a/yarn.lock b/yarn.lock index 58007622..1f8caca1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6422,6 +6422,10 @@ void-elements@^2.0.0: version "2.0.1" resolved "https://registry.yarnpkg.com/void-elements/-/void-elements-2.0.1.tgz#c066afb582bb1cb4128d60ea92392e94d5e9dbec" +vue-autosuggest@^1.8.3: + version "1.8.3" + resolved "https://registry.yarnpkg.com/vue-autosuggest/-/vue-autosuggest-1.8.3.tgz#dcce3d3ed90441c9788b6d18b2e67e5b9d4cad52" + vue-chat-scroll@^1.2.1: version "1.3.5" resolved "https://registry.yarnpkg.com/vue-chat-scroll/-/vue-chat-scroll-1.3.5.tgz#a5ee5bae5058f614818a96eac5ee3be4394a2f68" From da5844205c5e2ead4da42f89f1f9586683af693e Mon Sep 17 00:00:00 2001 From: taehoon Date: Tue, 2 Apr 2019 06:12:31 -0400 Subject: [PATCH 06/82] add user autosuggest component --- .../user_autosuggest/user_autosuggest.js | 41 ++++++++ .../user_autosuggest/user_autosuggest.vue | 93 +++++++++++++++++++ src/components/user_settings/user_settings.js | 4 +- .../user_settings/user_settings.vue | 3 +- 4 files changed, 139 insertions(+), 2 deletions(-) create mode 100644 src/components/user_autosuggest/user_autosuggest.js create mode 100644 src/components/user_autosuggest/user_autosuggest.vue diff --git a/src/components/user_autosuggest/user_autosuggest.js b/src/components/user_autosuggest/user_autosuggest.js new file mode 100644 index 00000000..6612c2f3 --- /dev/null +++ b/src/components/user_autosuggest/user_autosuggest.js @@ -0,0 +1,41 @@ +import { VueAutosuggest } from 'vue-autosuggest' +import BasicUserCard from '../basic_user_card/basic_user_card.vue' +import userSearchApi from '../../services/new_api/user_search.js' + +export default { + components: { + VueAutosuggest, + BasicUserCard + }, + data () { + return { + results: [], + timeout: null, + selected: null, + debounceMilliseconds: 500, + inputProps: { + id: 'autosuggest__input', + onInputChange: this.fetchResults, + placeholder: 'Search...', + class: 'form-control' + }, + suggestions: [] + } + }, + methods: { + fetchResults (query) { + clearTimeout(this.timeout) + this.timeout = setTimeout(() => { + userSearchApi.search({query, store: this.$store}) + .then((data) => { this.suggestions = [{ data }] }) + }, this.debounceMilliseconds) + }, + clickHandler (item) { + return false + }, + clickUserHandler () { + console.log('clickUserHandler') + return false + } + } +} diff --git a/src/components/user_autosuggest/user_autosuggest.vue b/src/components/user_autosuggest/user_autosuggest.vue new file mode 100644 index 00000000..48fe350d --- /dev/null +++ b/src/components/user_autosuggest/user_autosuggest.vue @@ -0,0 +1,93 @@ + + + + + diff --git a/src/components/user_settings/user_settings.js b/src/components/user_settings/user_settings.js index b6a0479d..d5772082 100644 --- a/src/components/user_settings/user_settings.js +++ b/src/components/user_settings/user_settings.js @@ -9,6 +9,7 @@ import fileSizeFormatService from '../../services/file_size_format/file_size_for import BlockCard from '../block_card/block_card.vue' import MuteCard from '../mute_card/mute_card.vue' import EmojiInput from '../emoji-input/emoji-input.vue' +import UserAutoSuggest from '../user_autosuggest/user_autosuggest.vue' import withSubscription from '../../hocs/with_subscription/with_subscription' import withList from '../../hocs/with_list/with_list' @@ -73,7 +74,8 @@ const UserSettings = { ImageCropper, BlockList, MuteList, - EmojiInput + EmojiInput, + UserAutoSuggest }, computed: { user () { diff --git a/src/components/user_settings/user_settings.vue b/src/components/user_settings/user_settings.vue index c08698dc..d98a8eba 100644 --- a/src/components/user_settings/user_settings.vue +++ b/src/components/user_settings/user_settings.vue @@ -22,7 +22,7 @@

{{$t('settings.name_bio')}}

{{$t('settings.name')}}

-
+ From 94e67ff11894c13bf34f1b31802a1497caa03897 Mon Sep 17 00:00:00 2001 From: taehoon Date: Tue, 2 Apr 2019 12:31:45 -0400 Subject: [PATCH 07/82] rewrite USerAutoSuggest without any dependency --- .../user_autosuggest/user_autosuggest.js | 37 +++----- .../user_autosuggest/user_autosuggest.vue | 94 +++---------------- 2 files changed, 29 insertions(+), 102 deletions(-) diff --git a/src/components/user_autosuggest/user_autosuggest.js b/src/components/user_autosuggest/user_autosuggest.js index 6612c2f3..eff6ef75 100644 --- a/src/components/user_autosuggest/user_autosuggest.js +++ b/src/components/user_autosuggest/user_autosuggest.js @@ -1,41 +1,34 @@ -import { VueAutosuggest } from 'vue-autosuggest' import BasicUserCard from '../basic_user_card/basic_user_card.vue' import userSearchApi from '../../services/new_api/user_search.js' +const debounceMilliseconds = 500 + export default { components: { - VueAutosuggest, BasicUserCard }, data () { return { + query: '', results: [], - timeout: null, - selected: null, - debounceMilliseconds: 500, - inputProps: { - id: 'autosuggest__input', - onInputChange: this.fetchResults, - placeholder: 'Search...', - class: 'form-control' - }, - suggestions: [] + timeout: null + } + }, + watch: { + query (val) { + this.fetchResults(val) } }, methods: { fetchResults (query) { clearTimeout(this.timeout) this.timeout = setTimeout(() => { - userSearchApi.search({query, store: this.$store}) - .then((data) => { this.suggestions = [{ data }] }) - }, this.debounceMilliseconds) - }, - clickHandler (item) { - return false - }, - clickUserHandler () { - console.log('clickUserHandler') - return false + this.results = [] + if (query) { + userSearchApi.search({query, store: this.$store}) + .then((data) => { this.results = data }) + } + }, debounceMilliseconds) } } } diff --git a/src/components/user_autosuggest/user_autosuggest.vue b/src/components/user_autosuggest/user_autosuggest.vue index 48fe350d..04e38a60 100644 --- a/src/components/user_autosuggest/user_autosuggest.vue +++ b/src/components/user_autosuggest/user_autosuggest.vue @@ -1,93 +1,27 @@ From b2eb43e3c8d49fcd43c3d864d7cc50dff9c5e3ff Mon Sep 17 00:00:00 2001 From: taehoon Date: Tue, 2 Apr 2019 12:33:01 -0400 Subject: [PATCH 08/82] rename css classes --- src/components/user_autosuggest/user_autosuggest.vue | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/user_autosuggest/user_autosuggest.vue b/src/components/user_autosuggest/user_autosuggest.vue index 04e38a60..743d9eaf 100644 --- a/src/components/user_autosuggest/user_autosuggest.vue +++ b/src/components/user_autosuggest/user_autosuggest.vue @@ -1,7 +1,7 @@ diff --git a/src/modules/users.js b/src/modules/users.js index 6de50b80..545b1d58 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -281,6 +281,9 @@ const users = { unregisterPushNotifications(token) }, + addNewUsers ({ commit }, users) { + commit('addNewUsers', users) + }, addNewStatuses (store, { statuses }) { const users = map(statuses, 'user') const retweetedUsers = compact(map(statuses, 'retweeted_status.user')) From 60b07eeaa44bcfa99e90aa075cd18086d25ef194 Mon Sep 17 00:00:00 2001 From: taehoon Date: Tue, 2 Apr 2019 14:01:21 -0400 Subject: [PATCH 13/82] filter out blocked user or me from the results --- src/components/user_autosuggest/user_autosuggest.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/components/user_autosuggest/user_autosuggest.js b/src/components/user_autosuggest/user_autosuggest.js index 42914b36..c8332e34 100644 --- a/src/components/user_autosuggest/user_autosuggest.js +++ b/src/components/user_autosuggest/user_autosuggest.js @@ -1,3 +1,4 @@ +import reject from 'lodash/reject' import BlockCard from '../block_card/block_card.vue' import userSearchApi from '../../services/new_api/user_search.js' @@ -27,9 +28,12 @@ export default { this.results = [] if (query) { userSearchApi.search({query, store: this.$store}) - .then((data) => { - this.$store.dispatch('addNewUsers', data) - this.results = data + .then((users) => { + const filteredUsers = reject(users, (user) => { + return user.statusnet_blocking || user.id === this.$store.state.users.currentUser.id + }) + this.$store.dispatch('addNewUsers', filteredUsers) + this.results = filteredUsers this.resultsVisible = true }) } From 33467880edc80f2bce205b8d426a65a751b9baf2 Mon Sep 17 00:00:00 2001 From: taehoon Date: Tue, 2 Apr 2019 14:07:03 -0400 Subject: [PATCH 14/82] improve ui --- src/components/user_autosuggest/user_autosuggest.vue | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/components/user_autosuggest/user_autosuggest.vue b/src/components/user_autosuggest/user_autosuggest.vue index d85fabf1..6253ca6b 100644 --- a/src/components/user_autosuggest/user_autosuggest.vue +++ b/src/components/user_autosuggest/user_autosuggest.vue @@ -1,7 +1,7 @@