From e86b1d71ee325a47fdcc10ffe1912e81fe7de9b5 Mon Sep 17 00:00:00 2001
From: shpuld <shpuld@gmail.com>
Date: Sat, 18 Feb 2017 15:48:27 +0200
Subject: Changed following-info to user-interactions and moved muting there,
 made everything in user-interactions look a bit neater

---
 .../user_card_content/user_card_content.vue        | 30 ++++++++++++----------
 1 file changed, 17 insertions(+), 13 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 2c32406b..0ee1d86f 100644
--- a/src/components/user_card_content/user_card_content.vue
+++ b/src/components/user_card_content/user_card_content.vue
@@ -3,30 +3,34 @@
     <div class="base00-background panel-heading text-center" v-bind:style="style">
       <div class='user-info'>
         <img :src="user.profile_image_url">
-        <div v-if='user.muted' class='muteinfo'>Muted</div>
-        <div class='muteinfo' v-if='isOtherUser'>
-          <button @click="toggleMute">Mute/Unmute</button>
-        </div>
         <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">
+        <div v-if="isOtherUser" class="user-interactions">
+          <div v-if="user.follows_you" class="following base06">
             Follows you!
           </div>
-          <div class="followed">
+          <div class="follow">
             <span v-if="user.following">
-              Following them!
-              <button @click="unfollowUser">
-                Unfollow!
+              <!--Following them!-->
+              <button @click="unfollowUser" class="base06 base01-background base06-border">
+                Unfollow
               </button>
             </span>
-            <span v-if="!user.following" >
-              <button @click="followUser">
-                Follow!
+            <span v-if="!user.following">
+              <button @click="followUser" class="base01 base04-background base01-border">
+                Follow
               </button>
             </span>
           </div>
+          <div class='mute' v-if='isOtherUser'>
+            <span v-if='user.muted'>
+              <button @click="toggleMute" class="base04 base01-background base06-border">Unmute</button>
+            </span>
+            <span v-if='!user.muted'>
+              <button @click="toggleMute" class="base01 base04-background base01-border">Mute</button>
+            </span>
+          </div>
         </div>
       </div>
     </div>
-- 
cgit v1.2.3-70-g09d2


From 9c1093b6ca695d00794c7db08f5ce0568717af59 Mon Sep 17 00:00:00 2001
From: Roger Braun <roger@rogerbraun.net>
Date: Mon, 20 Feb 2017 18:01:45 +0100
Subject: Grab mutes from server on patched servers.

---
 .../user_card_content/user_card_content.vue        |  1 +
 src/modules/users.js                               |  6 +++++
 src/services/api/api.service.js                    | 31 ++++++++++++++++++++--
 .../backend_interactor_service.js                  | 10 ++++++-
 4 files changed, 45 insertions(+), 3 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 0ee1d86f..59cee734 100644
--- a/src/components/user_card_content/user_card_content.vue
+++ b/src/components/user_card_content/user_card_content.vue
@@ -82,6 +82,7 @@
       toggleMute () {
         const store = this.$store
         store.commit('setMuted', {user: this.user, muted: !this.user.muted})
+        store.state.api.backendInteractor.setUserMute(this.user)
       }
     }
   }
diff --git a/src/modules/users.js b/src/modules/users.js
index ae90abbd..31731880 100644
--- a/src/modules/users.js
+++ b/src/modules/users.js
@@ -82,6 +82,12 @@ const users = {
                 // Start getting fresh tweets.
                 store.dispatch('startFetching', 'friends')
 
+                // Get user mutes and follower info
+                store.rootState.api.backendInteractor.fetchMutes().then((mutedUsers) => {
+                  each(mutedUsers, (user) => { user.muted = true })
+                  store.commit('addNewUsers', mutedUsers)
+                })
+
                 // Fetch our friends
                 store.rootState.api.backendInteractor.fetchFriends()
                   .then((friends) => commit('addNewUsers', friends))
diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js
index de89f503..f172f769 100644
--- a/src/services/api/api.service.js
+++ b/src/services/api/api.service.js
@@ -16,6 +16,7 @@ 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/destroy.json'
+const QVITTER_USER_PREF_URL = '/api/qvitter/set_profile_pref.json'
 // const USER_URL = '/api/users/show.json'
 
 const oldfetch = window.fetch
@@ -58,7 +59,7 @@ const fetchFriends = ({credentials}) => {
 const fetchAllFollowing = ({username, credentials}) => {
   const url = `${ALL_FOLLOWING_URL}/${username}.json`
   return fetch(url, { headers: authHeaders(credentials) })
-    .then((data) => data.json().users)
+    .then((data) => data.json())
 }
 
 const fetchMentions = ({username, sinceId = 0, credentials}) => {
@@ -79,6 +80,22 @@ const fetchStatus = ({id, credentials}) => {
     .then((data) => data.json())
 }
 
+const setUserMute = ({id, credentials, muted = true}) => {
+  const form = new FormData()
+
+  const muteInteger = muted ? 1 : 0
+
+  form.append('namespace', 'qvitter')
+  form.append('data', muteInteger)
+  form.append('topic', `mute:${id}`)
+
+  return fetch(QVITTER_USER_PREF_URL, {
+    method: 'POST',
+    headers: authHeaders(credentials),
+    body: form
+  })
+}
+
 const fetchTimeline = ({timeline, credentials, since = false, until = false}) => {
   const timelineUrls = {
     public: PUBLIC_TIMELINE_URL,
@@ -162,6 +179,14 @@ const uploadMedia = ({formData, credentials}) => {
     .then((text) => (new DOMParser()).parseFromString(text, 'application/xml'))
 }
 
+const fetchMutes = ({credentials}) => {
+  const url = '/api/qvitter/mutes.json'
+
+  return fetch(url, {
+    headers: authHeaders(credentials)
+  }).then((data) => data.json())
+}
+
 const apiService = {
   verifyCredentials,
   fetchTimeline,
@@ -177,7 +202,9 @@ const apiService = {
   postStatus,
   deleteStatus,
   uploadMedia,
-  fetchAllFollowing
+  fetchAllFollowing,
+  setUserMute,
+  fetchMutes
 }
 
 export default apiService
diff --git a/src/services/backend_interactor_service/backend_interactor_service.js b/src/services/backend_interactor_service/backend_interactor_service.js
index d335bfb7..d379e602 100644
--- a/src/services/backend_interactor_service/backend_interactor_service.js
+++ b/src/services/backend_interactor_service/backend_interactor_service.js
@@ -34,6 +34,12 @@ const backendInteractorService = (credentials) => {
     return timelineFetcherService.startFetching({timeline, store, credentials})
   }
 
+  const setUserMute = ({id, muted = true}) => {
+    return apiService.setUserMute({id, muted, credentials})
+  }
+
+  const fetchMutes = () => apiService.fetchMutes({credentials})
+
   const backendInteractorServiceInstance = {
     fetchStatus,
     fetchConversation,
@@ -43,7 +49,9 @@ const backendInteractorService = (credentials) => {
     unfollowUser,
     fetchAllFollowing,
     verifyCredentials: apiService.verifyCredentials,
-    startFetching
+    startFetching,
+    setUserMute,
+    fetchMutes
   }
 
   return backendInteractorServiceInstance
-- 
cgit v1.2.3-70-g09d2

