From fc268c48bc95ee8947da071305a436b293f44c02 Mon Sep 17 00:00:00 2001
From: Roger Braun <roger@rogerbraun.net>
Date: Thu, 8 Dec 2016 09:09:21 +0100
Subject: Very basic user following.

---
 .../user_card_content/user_card_content.vue        | 24 ++++++++++++++++++++++
 1 file changed, 24 insertions(+)

(limited to 'src/components/user_card_content/user_card_content.vue')

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 @@
         <span class="glyphicon glyphicon-user"></span>
         <div class='user-name'>{{user.name}}</div>
         <div class='user-screen-name'>@{{user.screen_name}}</div>
+        <div v-if="isOtherUser" class="following-info">
+          <div v-if="user.follows_you" class="following">
+            Follows you!
+          </div>
+          <div class="followed">
+            <span v-if="user.following">
+              Following them!
+            </span>
+            <span v-if="!user.following" >
+              <button @click="followUser">
+                Follow!
+              </button>
+            </span>
+          </div>
+        </div>
       </div>
     </div>
     <div class="panel-body">
@@ -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)
       }
     }
   }
-- 
cgit v1.2.3-70-g09d2


From 2088b3c4dd39aa8d8b516108130d0ac0a9fd855e Mon Sep 17 00:00:00 2001
From: Roger Braun <roger@rogerbraun.net>
Date: Fri, 23 Dec 2016 16:16:02 +0100
Subject: Add returned user to store after following.

---
 src/components/user_card_content/user_card_content.vue | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

(limited to 'src/components/user_card_content/user_card_content.vue')

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]))
       }
     }
   }
-- 
cgit v1.2.3-70-g09d2


From 8f494b14f0917cabfa584e9a9b3b4521c598c7bb Mon Sep 17 00:00:00 2001
From: Roger Braun <roger@rogerbraun.net>
Date: Fri, 23 Dec 2016 16:45:57 +0100
Subject: Add unfollowing.

---
 src/components/user_card_content/user_card_content.vue        |  8 ++++++++
 src/services/api/api.service.js                               | 11 ++++++++++-
 .../backend_interactor_service/backend_interactor_service.js  |  5 +++++
 3 files changed, 23 insertions(+), 1 deletion(-)

(limited to 'src/components/user_card_content/user_card_content.vue')

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 @@
           <div class="followed">
             <span v-if="user.following">
               Following them!
+              <button @click="unfollowUser">
+                Unfollow!
+              </button>
             </span>
             <span v-if="!user.following" >
               <button @click="followUser">
@@ -62,6 +65,11 @@
         const store = this.$store
         store.state.api.backendInteractor.followUser(this.user.id)
           .then((followedUser) => store.commit('addNewUsers', [followedUser]))
+      },
+      unfollowUser () {
+        const store = this.$store
+        store.state.api.backendInteractor.unfollowUser(this.user.id)
+          .then((unfollowedUser) => store.commit('addNewUsers', [unfollowedUser]))
       }
     }
   }
diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js
index 106432e7..87a7e2e5 100644
--- a/src/services/api/api.service.js
+++ b/src/services/api/api.service.js
@@ -14,7 +14,7 @@ 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 UNFOLLOWING_URL = '/api/friendships/destroy.json'
 // const USER_URL = '/api/users/show.json'
 
 const oldfetch = window.fetch
@@ -41,6 +41,14 @@ const followUser = ({id, credentials}) => {
   }).then((data) => data.json())
 }
 
+const unfollowUser = ({id, credentials}) => {
+  let url = `${UNFOLLOWING_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())
@@ -155,6 +163,7 @@ const apiService = {
   fetchMentions,
   fetchFriends,
   followUser,
+  unfollowUser,
   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 c7cf0f88..746776bf 100644
--- a/src/services/backend_interactor_service/backend_interactor_service.js
+++ b/src/services/backend_interactor_service/backend_interactor_service.js
@@ -21,12 +21,17 @@ const backendInteractorService = (credentials) => {
     return apiService.followUser({credentials, id})
   }
 
+  const unfollowUser = (id) => {
+    return apiService.unfollowUser({credentials, id})
+  }
+
   const backendInteractorServiceInstance = {
     fetchStatus,
     fetchConversation,
     fetchMentions,
     fetchFriends,
     followUser,
+    unfollowUser,
     verifyCredentials: apiService.verifyCredentials
   }
 
-- 
cgit v1.2.3-70-g09d2

