diff options
| -rw-r--r-- | src/boot/after_store.js | 3 | ||||
| -rw-r--r-- | src/components/user_card_content/user_card_content.vue | 145 | ||||
| -rw-r--r-- | src/lib/push_notifications_plugin.js | 22 | ||||
| -rw-r--r-- | src/main.js | 25 | ||||
| -rw-r--r-- | src/modules/instance.js | 1 | ||||
| -rw-r--r-- | src/modules/statuses.js | 2 | ||||
| -rw-r--r-- | src/modules/users.js | 21 | ||||
| -rw-r--r-- | src/services/api/api.service.js | 3 | ||||
| -rw-r--r-- | src/services/push/push.js | 14 | ||||
| -rw-r--r-- | src/services/status_poster/status_poster.service.js | 2 | ||||
| -rw-r--r-- | static/config.json | 3 |
11 files changed, 151 insertions, 90 deletions
diff --git a/src/boot/after_store.js b/src/boot/after_store.js index e716082a..08c00c64 100644 --- a/src/boot/after_store.js +++ b/src/boot/after_store.js @@ -72,6 +72,7 @@ const afterStoreSetup = ({ store, i18n }) => { var scopeCopy = (config.scopeCopy) var subjectLineBehavior = (config.subjectLineBehavior) var alwaysShowSubjectInput = (config.alwaysShowSubjectInput) + var noAttachmentLinks = (config.noAttachmentLinks) store.dispatch('setInstanceOption', { name: 'theme', value: theme }) store.dispatch('setInstanceOption', { name: 'background', value: background }) @@ -90,6 +91,8 @@ const afterStoreSetup = ({ store, i18n }) => { store.dispatch('setInstanceOption', { name: 'scopeCopy', value: scopeCopy }) store.dispatch('setInstanceOption', { name: 'subjectLineBehavior', value: subjectLineBehavior }) store.dispatch('setInstanceOption', { name: 'alwaysShowSubjectInput', value: alwaysShowSubjectInput }) + store.dispatch('setInstanceOption', { name: 'noAttachmentLinks', value: noAttachmentLinks }) + if (chatDisabled) { store.dispatch('disableChat') } diff --git a/src/components/user_card_content/user_card_content.vue b/src/components/user_card_content/user_card_content.vue index c5222519..c76c41a9 100644 --- a/src/components/user_card_content/user_card_content.vue +++ b/src/components/user_card_content/user_card_content.vue @@ -2,22 +2,25 @@ <div id="heading" class="profile-panel-background" :style="headingStyle"> <div class="panel-heading text-center"> <div class='user-info'> - <router-link @click.native="activatePanel && activatePanel('timeline')" :to="{ name: 'user-settings' }" style="float: right; margin-top:16px;" v-if="!isOtherUser"> - <i class="button-icon icon-cog usersettings" :title="$t('tool_tip.user_settings')"></i> - </router-link> - <a :href="user.statusnet_profile_url" target="_blank" class="floater" v-if="isOtherUser"> - <i class="icon-link-ext usersettings"></i> - </a> <div class='container'> <router-link @click.native="activatePanel && activatePanel('timeline')" :to="userProfileLink(user)"> <StillImage class="avatar" :class='{ "better-shadow": betterShadow }' :src="user.profile_image_url_original"/> </router-link> <div class="name-and-screen-name"> - <div :title="user.name" class='user-name' v-if="user.name_html" v-html="user.name_html"></div> - <div :title="user.name" class='user-name' v-else>{{user.name}}</div> + <div class="top-line"> + <div :title="user.name" class='user-name' v-if="user.name_html" v-html="user.name_html"></div> + <div :title="user.name" class='user-name' v-else>{{user.name}}</div> + <router-link @click.native="activatePanel && activatePanel('timeline')" :to="{ name: 'user-settings' }" v-if="!isOtherUser"> + <i class="button-icon icon-cog usersettings" :title="$t('tool_tip.user_settings')"></i> + </router-link> + <a :href="user.statusnet_profile_url" target="_blank" v-if="isOtherUser"> + <i class="icon-link-ext usersettings"></i> + </a> + </div> + <router-link @click.native="activatePanel && activatePanel('timeline')" class='user-screen-name' :to="userProfileLink(user)"> - <span>@{{user.screen_name}}</span><span v-if="user.locked"><i class="icon icon-lock"></i></span> - <span v-if="!hideUserStatsLocal" class="dailyAvg">{{dailyAvg}} {{ $t('user_card.per_day') }}</span> + <span class="handle">@{{user.screen_name}}</span><span v-if="user.locked"><i class="icon icon-lock"></i></span> + <span v-if="!hideUserStatsLocal && !hideBio" class="dailyAvg">{{dailyAvg}} {{ $t('user_card.per_day') }}</span> </router-link> </div> </div> @@ -25,7 +28,7 @@ <div v-if="user.follows_you && loggedIn && isOtherUser" class="following"> {{ $t('user_card.follows_you') }} </div> - <div class="floater" v-if="isOtherUser && (loggedIn || !switcher)"> + <div class="highlighter" v-if="isOtherUser && (loggedIn || !switcher)"> <!-- id's need to be unique, otherwise vue confuses which user-card checkbox belongs to --> <input class="userHighlightText" type="text" :id="'userHighlightColorTx'+user.id" v-if="userHighlightType !== 'disabled'" v-model="userHighlightColor"/> <input class="userHighlightCl" type="color" :id="'userHighlightColor'+user.id" v-if="userHighlightType !== 'disabled'" v-model="userHighlightColor"/> @@ -139,7 +142,7 @@ border-bottom-right-radius: 0; .panel-heading { - padding: 0.6em 0em; + padding: .6em 0; text-align: center; box-shadow: none; } @@ -158,10 +161,10 @@ .user-info { color: $fallback--lightText; color: var(--lightText, $fallback--lightText); - padding: 0 16px; + padding: 0 26px; .container { - padding: 16px 10px 6px 10px; + padding: 16px 0 6px; display: flex; max-height: 56px; @@ -218,11 +221,15 @@ vertical-align: middle; object-fit: contain } + .top-line { + display: flex; + } } .user-name{ text-overflow: ellipsis; overflow: hidden; + flex: 1 0 auto; } .user-screen-name { @@ -232,27 +239,73 @@ font-weight: light; font-size: 15px; padding-right: 0.1em; + width: 100%; + display: flex; + + .dailyAvg { + min-width: 1px; + flex: 0 0 auto; + } + + .handle { + min-width: 1px; + flex: 0 1 auto; + text-overflow: ellipsis; + overflow: hidden; + } } .user-meta { - margin-bottom: .4em; + margin-bottom: .15em; + display: flex; + align-items: baseline; + font-size: 14px; + line-height: 22px; + flex-wrap: wrap; .following { - font-size: 14px; - flex: 0 0 100%; + flex: 1 0 auto; margin: 0; - padding-left: 16px; + margin-bottom: .25em; text-align: left; - float: left; - } - .floater { - margin: 0; } - &::after { - display: block; - content: ''; - clear: both; + .highlighter { + flex: 0 1 auto; + display: flex; + flex-wrap: wrap; + margin-right: -.5em; + align-self: start; + + .userHighlightCl { + padding: 2px 10px; + flex: 1 0 auto; + } + + .userHighlightSel, + .userHighlightSel.select { + padding-top: 0; + padding-bottom: 0; + flex: 1 0 auto; + } + .userHighlightSel.select i { + line-height: 22px; + } + + .userHighlightText { + width: 70px; + flex: 1 0 auto; + } + + .userHighlightCl, + .userHighlightText, + .userHighlightSel, + .userHighlightSel.select { + height: 22px; + vertical-align: top; + margin-right: .5em; + margin-bottom: .25em; + } } } .user-interactions { @@ -260,8 +313,13 @@ flex-flow: row wrap; justify-content: space-between; + margin-right: -.75em; + div { - flex: 1; + flex: 1 0 0; + margin-right: .75em; + margin-bottom: .6em; + white-space: nowrap; } .mute { @@ -280,8 +338,9 @@ } button { - width: 92%; + width: 100%; height: 100%; + margin: 0; } .remote-button { @@ -304,10 +363,11 @@ justify-content: space-between; color: $fallback--lightText; color: var(--lightText, $fallback--lightText); + flex-wrap: wrap; } .user-count { - flex: 1; + flex: 1 0 auto; padding: .5em 0 .5em 0; margin: 0 .5em; @@ -327,32 +387,5 @@ color: #CCC; } .floater { - float: right; - margin-top: 16px; - - .userHighlightCl { - padding: 2px 10px; - } - .userHighlightSel, - .userHighlightSel.select { - padding-top: 0; - padding-bottom: 0; - } - .userHighlightSel.select i { - line-height: 22px; - } - - .userHighlightText { - width: 70px; - } - - .userHighlightCl, - .userHighlightText, - .userHighlightSel, - .userHighlightSel.select { - height: 22px; - vertical-align: top; - margin-right: 0 - } } </style> diff --git a/src/lib/push_notifications_plugin.js b/src/lib/push_notifications_plugin.js new file mode 100644 index 00000000..f75bb823 --- /dev/null +++ b/src/lib/push_notifications_plugin.js @@ -0,0 +1,22 @@ +export default (store) => { + store.subscribe((mutation, state) => { + const vapidPublicKey = state.instance.vapidPublicKey + const webPushNotification = state.config.webPushNotifications + const permission = state.interface.notificationPermission === 'granted' + const user = state.users.currentUser + + const isUserMutation = mutation.type === 'setCurrentUser' + const isVapidMutation = mutation.type === 'setInstanceOption' && mutation.payload.name === 'vapidPublicKey' + const isPermMutation = mutation.type === 'setNotificationPermission' && mutation.payload === 'granted' + const isUserConfigMutation = mutation.type === 'setOption' && mutation.payload.name === 'webPushNotifications' + const isVisibilityMutation = mutation.type === 'setOption' && mutation.payload.name === 'notificationVisibility' + + if (isUserMutation || isVapidMutation || isPermMutation || isUserConfigMutation || isVisibilityMutation) { + if (user && vapidPublicKey && permission && webPushNotification) { + return store.dispatch('registerPushNotifications') + } else if (isUserConfigMutation && !webPushNotification) { + return store.dispatch('unregisterPushNotifications') + } + } + }) +} diff --git a/src/main.js b/src/main.js index c22a762e..f87ef9da 100644 --- a/src/main.js +++ b/src/main.js @@ -15,6 +15,7 @@ import VueTimeago from 'vue-timeago' import VueI18n from 'vue-i18n' import createPersistedState from './lib/persisted_state.js' +import pushNotifications from './lib/push_notifications_plugin.js' import messages from './i18n/messages.js' @@ -51,28 +52,6 @@ const persistedStateOptions = { ] } -const registerPushNotifications = store => { - store.subscribe((mutation, state) => { - const vapidPublicKey = state.instance.vapidPublicKey - const webPushNotification = state.config.webPushNotifications - const permission = state.interface.notificationPermission === 'granted' - const user = state.users.currentUser - - const isUserMutation = mutation.type === 'setCurrentUser' - const isVapidMutation = mutation.type === 'setInstanceOption' && mutation.payload.name === 'vapidPublicKey' - const isPermMutation = mutation.type === 'setNotificationPermission' && mutation.payload === 'granted' - const isUserConfigMutation = mutation.type === 'setOption' && mutation.payload.name === 'webPushNotifications' - - if (isUserMutation || isVapidMutation || isPermMutation || isUserConfigMutation) { - if (user && vapidPublicKey && permission && webPushNotification) { - return store.dispatch('registerPushNotifications') - } else if (isUserConfigMutation && !webPushNotification) { - return store.dispatch('unregisterPushNotifications') - } - } - }) -} - createPersistedState(persistedStateOptions).then((persistedState) => { const store = new Vuex.Store({ modules: { @@ -85,7 +64,7 @@ createPersistedState(persistedStateOptions).then((persistedState) => { chat: chatModule, oauth: oauthModule }, - plugins: [persistedState, registerPushNotifications], + plugins: [persistedState, pushNotifications], strict: false // Socket modifies itself, let's ignore this for now. // strict: process.env.NODE_ENV !== 'production' }) diff --git a/src/modules/instance.js b/src/modules/instance.js index 093bfd0f..4ad41873 100644 --- a/src/modules/instance.js +++ b/src/modules/instance.js @@ -27,6 +27,7 @@ const defaultState = { loginMethod: 'password', nsfwCensorImage: undefined, vapidPublicKey: undefined, + noAttachmentLinks: false, // Nasty stuff pleromaBackend: true, diff --git a/src/modules/statuses.js b/src/modules/statuses.js index 8c2d36bc..dccccf72 100644 --- a/src/modules/statuses.js +++ b/src/modules/statuses.js @@ -27,6 +27,7 @@ export const defaultState = { maxId: 0, minId: Number.POSITIVE_INFINITY, data: [], + idStore: {}, error: false }, favorites: new Set(), @@ -307,6 +308,7 @@ const addNewNotifications = (state, { dispatch, notifications, older, visibleNot } state.notifications.data.push(result) + state.notifications.idStore[notification.id] = result if ('Notification' in window && window.Notification.permission === 'granted') { const title = action.user.name diff --git a/src/modules/users.js b/src/modules/users.js index f2b59aaa..2f05ed3f 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -66,6 +66,9 @@ export const mutations = { setUserForStatus (state, status) { status.user = state.usersObject[status.user.id] }, + setUserForNotification (state, notification) { + notification.action.user = state.usersObject[notification.action.user.id] + }, setColor (state, { user: { id }, highlighted }) { const user = state.usersObject[id] set(user, 'highlight', highlighted) @@ -113,8 +116,9 @@ const users = { const token = store.state.currentUser.credentials const vapidPublicKey = store.rootState.instance.vapidPublicKey const isEnabled = store.rootState.config.webPushNotifications + const notificationVisibility = store.rootState.config.notificationVisibility - registerPushNotifications(isEnabled, vapidPublicKey, token) + registerPushNotifications(isEnabled, vapidPublicKey, token, notificationVisibility) }, unregisterPushNotifications (store) { const token = store.state.currentUser.credentials @@ -136,6 +140,21 @@ const users = { store.commit('setUserForStatus', status) }) }, + addNewNotifications (store, { notifications }) { + const users = compact(map(notifications, 'from_profile')) + const notificationIds = compact(notifications.map(_ => String(_.id))) + store.commit('addNewUsers', users) + + const notificationsObject = store.rootState.statuses.notifications.idStore + const relevantNotifications = Object.entries(notificationsObject) + .filter(([k, val]) => notificationIds.includes(k)) + .map(([k, val]) => val) + + // Reconnect users to notifications + each(relevantNotifications, (notification) => { + store.commit('setUserForNotification', notification) + }) + }, async signUp (store, userInfo) { store.commit('signUpPending') diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js index 182f9126..4ee95bd1 100644 --- a/src/services/api/api.service.js +++ b/src/services/api/api.service.js @@ -370,12 +370,13 @@ const unretweet = ({ id, credentials }) => { }) } -const postStatus = ({credentials, status, spoilerText, visibility, sensitive, mediaIds, inReplyToStatusId, contentType}) => { +const postStatus = ({credentials, status, spoilerText, visibility, sensitive, mediaIds, inReplyToStatusId, contentType, noAttachmentLinks}) => { const idsText = mediaIds.join(',') const form = new FormData() form.append('status', status) form.append('source', 'Pleroma FE') + if (noAttachmentLinks) form.append('no_attachment_links', noAttachmentLinks) if (spoilerText) form.append('spoiler_text', spoilerText) if (visibility) form.append('visibility', visibility) if (sensitive) form.append('sensitive', sensitive) diff --git a/src/services/push/push.js b/src/services/push/push.js index bf0c9680..1b189a29 100644 --- a/src/services/push/push.js +++ b/src/services/push/push.js @@ -51,7 +51,7 @@ function deleteSubscriptionFromBackEnd (token) { }) } -function sendSubscriptionToBackEnd (subscription, token) { +function sendSubscriptionToBackEnd (subscription, token, notificationVisibility) { return window.fetch('/api/v1/push/subscription/', { method: 'POST', headers: { @@ -62,10 +62,10 @@ function sendSubscriptionToBackEnd (subscription, token) { subscription, data: { alerts: { - follow: true, - favourite: true, - mention: true, - reblog: true + follow: notificationVisibility.follows, + favourite: notificationVisibility.likes, + mention: notificationVisibility.mentions, + reblog: notificationVisibility.repeats } } }) @@ -78,11 +78,11 @@ function sendSubscriptionToBackEnd (subscription, token) { }) } -export function registerPushNotifications (isEnabled, vapidPublicKey, token) { +export function registerPushNotifications (isEnabled, vapidPublicKey, token, notificationVisibility) { if (isPushSupported()) { getOrCreateServiceWorker() .then((registration) => subscribePush(registration, isEnabled, vapidPublicKey)) - .then((subscription) => sendSubscriptionToBackEnd(subscription, token)) + .then((subscription) => sendSubscriptionToBackEnd(subscription, token, notificationVisibility)) .catch((e) => console.warn(`Failed to setup Web Push Notifications: ${e.message}`)) } } diff --git a/src/services/status_poster/status_poster.service.js b/src/services/status_poster/status_poster.service.js index 7f8b0fc0..1e20d336 100644 --- a/src/services/status_poster/status_poster.service.js +++ b/src/services/status_poster/status_poster.service.js @@ -4,7 +4,7 @@ import apiService from '../api/api.service.js' const postStatus = ({ store, status, spoilerText, visibility, sensitive, media = [], inReplyToStatusId = undefined, contentType = 'text/plain' }) => { const mediaIds = map(media, 'id') - return apiService.postStatus({credentials: store.state.users.currentUser.credentials, status, spoilerText, visibility, sensitive, mediaIds, inReplyToStatusId, contentType}) + return apiService.postStatus({credentials: store.state.users.currentUser.credentials, status, spoilerText, visibility, sensitive, mediaIds, inReplyToStatusId, contentType, noAttachmentLinks: store.state.instance.noAttachmentLinks}) .then((data) => data.json()) .then((data) => { if (!data.error) { diff --git a/static/config.json b/static/config.json index 7c62eafa..9ad6e6ab 100644 --- a/static/config.json +++ b/static/config.json @@ -17,5 +17,6 @@ "hidePostStats": false, "hideUserStats": false, "loginMethod": "password", - "webPushNotifications": false + "webPushNotifications": false, + "noAttachmentLinks": false } |
