From f18f87747f72e8ee45ea0eebe5fd2878e116e02e Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Thu, 8 Dec 2016 09:08:59 +0100 Subject: [PATCH 1/4] Also add retweeted users to user store. --- src/modules/users.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/modules/users.js b/src/modules/users.js index 1821e0f2..8ba365f3 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -1,6 +1,6 @@ import timelineFetcher from '../services/timeline_fetcher/timeline_fetcher.service.js' import backendInteractorService from '../services/backend_interactor_service/backend_interactor_service.js' -import { map, each, find, merge } from 'lodash' +import { compact, map, each, find, merge } from 'lodash' // TODO: Unify with mergeOrAdd in statuses.js export const mergeOrAdd = (arr, item) => { @@ -44,7 +44,9 @@ const users = { actions: { addNewStatuses (store, { statuses }) { const users = map(statuses, 'user') + const retweetedUsers = compact(map(statuses, 'retweeted_status.user')) store.commit('addNewUsers', users) + store.commit('addNewUsers', retweetedUsers) }, loginUser (store, userCredentials) { const commit = store.commit From fc268c48bc95ee8947da071305a436b293f44c02 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Thu, 8 Dec 2016 09:09:21 +0100 Subject: [PATCH 2/4] Very basic user following. --- .../user_card_content/user_card_content.vue | 24 +++++++++++++++++++ src/components/user_profile/user_profile.vue | 17 +++++++++++++ src/services/api/api.service.js | 12 ++++++++++ .../backend_interactor_service.js | 5 ++++ 4 files changed, 58 insertions(+) diff --git a/src/components/user_card_content/user_card_content.vue b/src/components/user_card_content/user_card_content.vue index 7ad86e63..484597ab 100644 --- a/src/components/user_card_content/user_card_content.vue +++ b/src/components/user_card_content/user_card_content.vue @@ -6,6 +6,21 @@
{{user.name}}
@{{user.screen_name}}
+
+
+ Follows you! +
+
+ + Following them! + + + + +
+
@@ -37,6 +52,15 @@ color: `#${this.user.profile_link_color}`, 'background-image': `url(${this.user.cover_photo})` } + }, + isOtherUser () { + return this.user !== this.$store.state.users.currentUser + } + }, + methods: { + followUser () { + this.$store.state.api.backendInteractor.followUser(this.user.id) + .then((x) => console.log) } } } diff --git a/src/components/user_profile/user_profile.vue b/src/components/user_profile/user_profile.vue index eaa5396d..2ceb13ec 100644 --- a/src/components/user_profile/user_profile.vue +++ b/src/components/user_profile/user_profile.vue @@ -5,3 +5,20 @@ + + diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js index a78ab5c9..106432e7 100644 --- a/src/services/api/api.service.js +++ b/src/services/api/api.service.js @@ -13,6 +13,9 @@ const MEDIA_UPLOAD_URL = '/api/statusnet/media/upload' const CONVERSATION_URL = '/api/statusnet/conversation' const MENTIONS_URL = '/api/statuses/mentions.json' const FRIENDS_URL = '/api/statuses/friends.json' +const FOLLOWING_URL = '/api/friendships/create.json' +// const UNFOLLOWING_URL = '/api/friendships/create.json' +// const USER_URL = '/api/users/show.json' const oldfetch = window.fetch @@ -30,6 +33,14 @@ const authHeaders = (user) => { } } +const followUser = ({id, credentials}) => { + let url = `${FOLLOWING_URL}?user_id=${id}` + return fetch(url, { + headers: authHeaders(credentials), + method: 'POST' + }).then((data) => data.json()) +} + const fetchFriends = ({credentials}) => { return fetch(FRIENDS_URL, { headers: authHeaders(credentials) }) .then((data) => data.json()) @@ -143,6 +154,7 @@ const apiService = { fetchStatus, fetchMentions, fetchFriends, + followUser, favorite, unfavorite, retweet, diff --git a/src/services/backend_interactor_service/backend_interactor_service.js b/src/services/backend_interactor_service/backend_interactor_service.js index 36a1ff3b..c7cf0f88 100644 --- a/src/services/backend_interactor_service/backend_interactor_service.js +++ b/src/services/backend_interactor_service/backend_interactor_service.js @@ -17,11 +17,16 @@ const backendInteractorService = (credentials) => { return apiService.fetchFriends({credentials}) } + const followUser = (id) => { + return apiService.followUser({credentials, id}) + } + const backendInteractorServiceInstance = { fetchStatus, fetchConversation, fetchMentions, fetchFriends, + followUser, verifyCredentials: apiService.verifyCredentials } From 2088b3c4dd39aa8d8b516108130d0ac0a9fd855e Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Fri, 23 Dec 2016 16:16:02 +0100 Subject: [PATCH 3/4] Add returned user to store after following. --- src/components/user_card_content/user_card_content.vue | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/components/user_card_content/user_card_content.vue b/src/components/user_card_content/user_card_content.vue index 484597ab..18a582e7 100644 --- a/src/components/user_card_content/user_card_content.vue +++ b/src/components/user_card_content/user_card_content.vue @@ -59,8 +59,9 @@ }, methods: { followUser () { - this.$store.state.api.backendInteractor.followUser(this.user.id) - .then((x) => console.log) + const store = this.$store + store.state.api.backendInteractor.followUser(this.user.id) + .then((followedUser) => store.commit('addNewUsers', [followedUser])) } } } From 8f494b14f0917cabfa584e9a9b3b4521c598c7bb Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Fri, 23 Dec 2016 16:45:57 +0100 Subject: [PATCH 4/4] Add unfollowing. --- .../user_card_content/user_card_content.vue | 8 ++++++++ src/services/api/api.service.js | 11 ++++++++++- .../backend_interactor_service.js | 5 +++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/components/user_card_content/user_card_content.vue b/src/components/user_card_content/user_card_content.vue index 18a582e7..d9e661a9 100644 --- a/src/components/user_card_content/user_card_content.vue +++ b/src/components/user_card_content/user_card_content.vue @@ -13,6 +13,9 @@
Following them! +