From 039a4074006fb91ac9031b41b4e9af4a15766dfa Mon Sep 17 00:00:00 2001
From: Henry Jameson <me@hjkos.com>
Date: Sat, 12 Jan 2019 23:33:45 +0300
Subject: some initial work to make it possible to use "unregistered"
 timelines, i.e. not reserving a timeline by name, instead just passing
 timeline object itself.

---
 src/components/user_profile/user_profile.vue | 1 +
 1 file changed, 1 insertion(+)

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

diff --git a/src/components/user_profile/user_profile.vue b/src/components/user_profile/user_profile.vue
index a46befa5..15f7d44f 100644
--- a/src/components/user_profile/user_profile.vue
+++ b/src/components/user_profile/user_profile.vue
@@ -20,6 +20,7 @@
           <i class="icon-spin3 animate-spin"></i>
         </div>
       </div>
+      <Timeline :label="$t('user_card.favorites')" :embedded="true" :title="$t('user_profile.favorites_title')" :timeline="favorites"/>
     </tab-switcher>
   </div>
   <div v-else class="panel user-profile-placeholder">
-- 
cgit v1.2.3-70-g09d2


From 93cbb58212ebb83cee5bc89f8cef1ebb58969f5c Mon Sep 17 00:00:00 2001
From: Henry Jameson <me@hjkos.com>
Date: Thu, 17 Jan 2019 22:11:51 +0300
Subject: fix login and favorites tab...

---
 src/components/user_profile/user_profile.js        | 13 +++++
 src/components/user_profile/user_profile.vue       |  2 +-
 src/modules/users.js                               | 61 +++++++++++-----------
 src/services/api/api.service.js                    | 12 +++++
 .../entity_normalizer/entity_normalizer.service.js |  8 +++
 5 files changed, 64 insertions(+), 32 deletions(-)

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

diff --git a/src/components/user_profile/user_profile.js b/src/components/user_profile/user_profile.js
index 7f17ef69..c9197a1c 100644
--- a/src/components/user_profile/user_profile.js
+++ b/src/components/user_profile/user_profile.js
@@ -5,13 +5,16 @@ import Timeline from '../timeline/timeline.vue'
 const UserProfile = {
   created () {
     this.$store.commit('clearTimeline', { timeline: 'user' })
+    this.$store.commit('clearTimeline', { timeline: 'favorites' })
     this.$store.dispatch('startFetching', ['user', this.fetchBy])
+    this.$store.dispatch('startFetching', ['favorites', this.fetchBy])
     if (!this.user.id) {
       this.$store.dispatch('fetchUser', this.fetchBy)
     }
   },
   destroyed () {
     this.$store.dispatch('stopFetching', 'user')
+    this.$store.dispatch('stopFetching', 'favorites')
   },
   computed: {
     timeline () {
@@ -26,6 +29,9 @@ const UserProfile = {
     userName () {
       return this.$route.params.name || this.user.screen_name
     },
+    isUs () {
+      return this.userId === this.$store.state.users.currentUser.id
+    },
     friends () {
       return this.user.friends
     },
@@ -65,21 +71,28 @@ const UserProfile = {
     }
   },
   watch: {
+    // TODO get rid of this copypasta
     userName () {
       if (this.isExternal) {
         return
       }
       this.$store.dispatch('stopFetching', 'user')
+      this.$store.dispatch('stopFetching', 'favorites')
       this.$store.commit('clearTimeline', { timeline: 'user' })
+      this.$store.commit('clearTimeline', { timeline: 'favorites' })
       this.$store.dispatch('startFetching', ['user', this.fetchBy])
+      this.$store.dispatch('startFetching', ['favorites', this.fetchBy])
     },
     userId () {
       if (!this.isExternal) {
         return
       }
       this.$store.dispatch('stopFetching', 'user')
+      this.$store.dispatch('stopFetching', 'favorites')
       this.$store.commit('clearTimeline', { timeline: 'user' })
+      this.$store.commit('clearTimeline', { timeline: 'favorites' })
       this.$store.dispatch('startFetching', ['user', this.fetchBy])
+      this.$store.dispatch('startFetching', ['favorites', this.fetchBy])
     },
     user () {
       if (this.user.id && !this.user.followers) {
diff --git a/src/components/user_profile/user_profile.vue b/src/components/user_profile/user_profile.vue
index 265fc65b..e53727ff 100644
--- a/src/components/user_profile/user_profile.vue
+++ b/src/components/user_profile/user_profile.vue
@@ -20,7 +20,7 @@
           <i class="icon-spin3 animate-spin"></i>
         </div>
       </div>
-      <Timeline :label="$t('user_card.favorites')" :embedded="true" :title="$t('user_profile.favorites_title')" :timeline="favorites"/>
+      <Timeline v-if="isUs" :label="$t('user_card.favorites')" :embedded="true" :title="$t('user_profile.favorites_title')" :timeline="favorites"/>
     </tab-switcher>
   </div>
   <div v-else class="panel user-profile-placeholder">
diff --git a/src/modules/users.js b/src/modules/users.js
index 33c02a07..c4d479f9 100644
--- a/src/modules/users.js
+++ b/src/modules/users.js
@@ -207,39 +207,38 @@ const users = {
         const commit = store.commit
         commit('beginLogin')
         store.rootState.api.backendInteractor.verifyCredentials(accessToken)
-          .then((response) => {
-            if (response.ok) {
-              response.json()
-                .then((user) => {
-                  // user.credentials = userCredentials
-                  user.credentials = accessToken
-                  commit('setCurrentUser', user)
-                  commit('addNewUsers', [user])
+          .then((data) => {
+            if (!data.error) {
+              const { user } = data
+              // user.credentials = userCredentials
+              user.credentials = accessToken
+              commit('setCurrentUser', user)
+              commit('addNewUsers', [user])
 
-                  getNotificationPermission()
-                    .then(permission => commit('setNotificationPermission', permission))
+              getNotificationPermission()
+                .then(permission => commit('setNotificationPermission', permission))
 
-                  // Set our new backend interactor
-                  commit('setBackendInteractor', backendInteractorService(accessToken))
+              // Set our new backend interactor
+              commit('setBackendInteractor', backendInteractorService(accessToken))
 
-                  if (user.token) {
-                    store.dispatch('initializeSocket', user.token)
-                  }
+              if (user.token) {
+                store.dispatch('initializeSocket', user.token)
+              }
 
-                  // Start getting fresh tweets.
-                  store.dispatch('startFetching', 'friends')
+              // 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)
-                  })
+              // 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({ id: user.id })
-                    .then((friends) => commit('addNewUsers', friends))
-                })
+              // Fetch our friends
+              store.rootState.api.backendInteractor.fetchFriends({ id: user.id })
+                .then((friends) => commit('addNewUsers', friends))
             } else {
+              const response = data.error
               // Authentication failed
               commit('endLogin')
               if (response.status === 401) {
@@ -251,11 +250,11 @@ const users = {
             commit('endLogin')
             resolve()
           })
-          .catch((error) => {
-            console.log(error)
-            commit('endLogin')
-            reject('Failed to connect to server, try again')
-          })
+        .catch((error) => {
+          console.log(error)
+          commit('endLogin')
+          reject('Failed to connect to server, try again')
+        })
       })
     }
   }
diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js
index 0e267276..c45f8572 100644
--- a/src/services/api/api.service.js
+++ b/src/services/api/api.service.js
@@ -366,6 +366,18 @@ const verifyCredentials = (user) => {
     method: 'POST',
     headers: authHeaders(user)
   })
+    .then((response) => {
+      if (response.ok) {
+        return response.json()
+      } else {
+        return {
+          error: response
+        }
+      }
+    })
+    .then((data) => ({
+      user: parseUser(data)
+    }))
 }
 
 const favorite = ({ id, credentials }) => {
diff --git a/src/services/entity_normalizer/entity_normalizer.service.js b/src/services/entity_normalizer/entity_normalizer.service.js
index ca0f36db..fa35bba3 100644
--- a/src/services/entity_normalizer/entity_normalizer.service.js
+++ b/src/services/entity_normalizer/entity_normalizer.service.js
@@ -80,6 +80,14 @@ export const parseUser = (data) => {
 
     output.statusnet_profile_url = data.statusnet_profile_url
     output.is_local = data.is_local
+
+    // QVITTER ONLY FOR NOW
+    // Really only applies to logged in user, really.. I THINK
+    output.rights = data.rights
+    output.no_rich_text = data.no_rich_text
+    output.default_scope = data.default_scope
+    output.hide_network = data.hide_network
+    output.background_image = data.background_image
   }
 
   output.created_at = new Date(data.created_at)
-- 
cgit v1.2.3-70-g09d2


From 6e219c2961ddd205d618f2775076c25f49c63ca2 Mon Sep 17 00:00:00 2001
From: Henry Jameson <me@hjkos.com>
Date: Thu, 17 Jan 2019 22:25:50 +0300
Subject: add support for tab-switcher to automatically switch to first tab if
 asked index is invalid

---
 src/components/tab_switcher/tab_switcher.jsx | 45 ++++++++++++++++++----------
 src/components/user_profile/user_profile.vue |  2 +-
 2 files changed, 30 insertions(+), 17 deletions(-)

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

diff --git a/src/components/tab_switcher/tab_switcher.jsx b/src/components/tab_switcher/tab_switcher.jsx
index 2f362c4d..175ae777 100644
--- a/src/components/tab_switcher/tab_switcher.jsx
+++ b/src/components/tab_switcher/tab_switcher.jsx
@@ -1,23 +1,32 @@
 import Vue from 'vue'
 
+
 import './tab_switcher.scss'
 
 export default Vue.component('tab-switcher', {
   name: 'TabSwitcher',
   data () {
     return {
-      active: 0
+      active: this.$slots.default.findIndex(_ => _.tag)
     }
   },
   methods: {
-    activateTab(index) {
-      return () => this.active = index;
+    activateTab (index) {
+      return () => {
+        this.active = index
+      }
+    }
+  },
+  beforeUpdate () {
+    const currentSlot = this.$slots.default[this.active]
+    if (!currentSlot.tag) {
+      this.active = this.$slots.default.findIndex(_ => _.tag)
     }
   },
-  render(h) {
+  render (h) {
     const tabs = this.$slots.default
-          .filter(slot => slot.data)
           .map((slot, index) => {
+            if (!slot.tag) return
             const classesTab = ['tab']
             const classesWrapper = ['tab-wrapper']
 
@@ -25,28 +34,32 @@ export default Vue.component('tab-switcher', {
               classesTab.push('active')
               classesWrapper.push('active')
             }
+
             return (
               <div class={ classesWrapper.join(' ')}>
-                <button onClick={this.activateTab(index)} class={ classesTab.join(' ') }>{slot.data.attrs.label}</button>
+              <button onClick={this.activateTab(index)} class={ classesTab.join(' ') }>{slot.data.attrs.label}</button>
               </div>
             )
-          });
-    const contents = this.$slots.default.filter(_=>_.data).map(( slot, index ) => {
+          })
+
+    const contents = this.$slots.default.map((slot, index) => {
+      if (!slot.tag) return
       const active = index === this.active
       return (
         <div class={active ? 'active' : 'hidden'}>
-          {slot}
+        {slot}
         </div>
       )
-    });
+    })
+
     return (
       <div class="tab-switcher">
-        <div class="tabs">
-          {tabs}
-        </div>
-        <div class="contents">
-          {contents}
-        </div>
+      <div class="tabs">
+      {tabs}
+      </div>
+      <div class="contents">
+      {contents}
+      </div>
       </div>
     )
   }
diff --git a/src/components/user_profile/user_profile.vue b/src/components/user_profile/user_profile.vue
index e53727ff..d64ce277 100644
--- a/src/components/user_profile/user_profile.vue
+++ b/src/components/user_profile/user_profile.vue
@@ -20,7 +20,7 @@
           <i class="icon-spin3 animate-spin"></i>
         </div>
       </div>
-      <Timeline v-if="isUs" :label="$t('user_card.favorites')" :embedded="true" :title="$t('user_profile.favorites_title')" :timeline="favorites"/>
+      <Timeline v-if="isUs" :label="$t('user_card.favorites')" :embedded="true" :title="$t('user_profile.favorites_title')" timeline-name="favorites" :timeline="favorites"/>
     </tab-switcher>
   </div>
   <div v-else class="panel user-profile-placeholder">
-- 
cgit v1.2.3-70-g09d2

