From 963a0035e5e3f35ee790aeb3db64cb8dd32a84a4 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Sat, 18 Feb 2017 20:42:00 +0100 Subject: Make page title dynamic, better notification handling. --- src/modules/config.js | 7 +++++-- src/modules/statuses.js | 7 ++++++- 2 files changed, 11 insertions(+), 3 deletions(-) (limited to 'src/modules') diff --git a/src/modules/config.js b/src/modules/config.js index 4365d554..8d850f2a 100644 --- a/src/modules/config.js +++ b/src/modules/config.js @@ -13,11 +13,14 @@ const config = { } }, actions: { - setOption ({ commit }, { name, value }) { + setPageTitle ({state}, option = '') { + document.title = `${state.name} ${option}` + }, + setOption ({ commit, dispatch }, { name, value }) { commit('setOption', {name, value}) switch (name) { case 'name': - document.title = value + dispatch('setPageTitle') break case 'theme': const fullPath = `/static/css/${value}` diff --git a/src/modules/statuses.js b/src/modules/statuses.js index 871172b5..0967f77a 100644 --- a/src/modules/statuses.js +++ b/src/modules/statuses.js @@ -173,7 +173,7 @@ const addNewStatuses = (state, { statuses, showImmediately = false, timeline, us } const addNotification = ({type, status, action}) => { - state.notifications.push({type, status, action}) + state.notifications.push({type, status, action, seen: false}) } const favoriteStatus = (favorite) => { @@ -276,6 +276,11 @@ export const mutations = { setNsfw (state, { id, nsfw }) { const newStatus = find(state.allStatuses, { id }) newStatus.nsfw = nsfw + }, + markNotificationsAsSeen (state, notifications) { + each(notifications, (notification) => { + notification.seen = true + }) } } -- cgit v1.2.3-70-g09d2 From 209e8614b09ab7f24262d86de0924bd2e0dd96ec Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Sat, 18 Feb 2017 20:56:03 +0100 Subject: Don't add notifications twice + persiste them. --- src/main.js | 2 +- src/modules/statuses.js | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'src/modules') diff --git a/src/main.js b/src/main.js index 4b367db9..841e61a7 100644 --- a/src/main.js +++ b/src/main.js @@ -29,7 +29,7 @@ Vue.use(VueTimeago, { }) const persistedStateOptions = { - paths: ['users.users'] + paths: ['users.users', 'statuses.notifications'] } const store = new Vuex.Store({ diff --git a/src/modules/statuses.js b/src/modules/statuses.js index 0967f77a..491d0024 100644 --- a/src/modules/statuses.js +++ b/src/modules/statuses.js @@ -173,7 +173,10 @@ const addNewStatuses = (state, { statuses, showImmediately = false, timeline, us } const addNotification = ({type, status, action}) => { - state.notifications.push({type, status, action, seen: false}) + // Only add a new notification if we don't have one for the same action + if (!find(state.notifications, (oldNotification) => oldNotification.action.id === action.id)) { + state.notifications.push({type, status, action, seen: false}) + } } const favoriteStatus = (favorite) => { -- cgit v1.2.3-70-g09d2 From b5d7a179c4a07abc79e7f0c26fb7f6ca19c4d7d3 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Sat, 18 Feb 2017 21:43:26 +0100 Subject: Reverse title and notification count. --- src/modules/config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/modules') diff --git a/src/modules/config.js b/src/modules/config.js index 8d850f2a..a1276519 100644 --- a/src/modules/config.js +++ b/src/modules/config.js @@ -14,7 +14,7 @@ const config = { }, actions: { setPageTitle ({state}, option = '') { - document.title = `${state.name} ${option}` + document.title = `${option} ${state.name}` }, setOption ({ commit, dispatch }, { name, value }) { commit('setOption', {name, value}) -- cgit v1.2.3-70-g09d2 From 9c1093b6ca695d00794c7db08f5ce0568717af59 Mon Sep 17 00:00:00 2001 From: Roger Braun 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/modules') 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