Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F85948631
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Authored By
Unknown
Size
14 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/src/components/settings_modal/tabs/security_tab/tokens.js b/src/components/settings_modal/tabs/security_tab/tokens.js
index e066dcc742..f44103f0ad 100644
--- a/src/components/settings_modal/tabs/security_tab/tokens.js
+++ b/src/components/settings_modal/tabs/security_tab/tokens.js
@@ -1,176 +1,177 @@
import { storeToRefs } from 'pinia'
import { computed, defineAsyncComponent, ref } from 'vue'
import { useI18n } from 'vue-i18n'
import Checkbox from 'src/components/checkbox/checkbox.vue'
import Timeago from 'src/components/timeago/timeago.vue'
import { useOAuthTokensStore } from 'src/stores/oauth_tokens.js'
import localeService from 'src/services/locale/locale.service.js'
import wait from 'src/services/wait/wait.js'
import { library } from '@fortawesome/fontawesome-svg-core'
import { faCircleNotch, faTimes } from '@fortawesome/free-solid-svg-icons'
library.add(faCircleNotch, faTimes)
const Tokens = {
components: {
ConfirmModal: defineAsyncComponent(
() => import('src/components/confirm_modal/confirm_modal.vue'),
),
Checkbox,
Timeago,
},
setup() {
const { locale } = useI18n()
// Data
const { tokens, usTokens } = storeToRefs(useOAuthTokensStore())
const { fetchTokens, revokeToken } = useOAuthTokensStore()
fetchTokens()
const noUs = computed(() => usTokens.value.length === 0)
const allTokens = computed(() =>
[...usTokens.value, ...tokens.value].map((t) => ({
...t,
validLocalized: t.validUntil.toLocaleDateString(
- localeService.internalToBrowserLocale(locale),
+ localeService.internalToBrowserLocale(locale.value),
),
})),
)
// Selection
const selected = ref(new Set())
const allSelected = computed(
- () => selected.value.size >= tokens.value.length,
+ () => selected.value.size > 0 && selected.value.size >= tokens.value.length,
)
const someSelected = computed(
() => selected.value.size > 0 && !allSelected.value,
)
const toggleSelect = (id, value) => {
if (value) {
selected.value.add(id)
} else {
selected.value.delete(id)
}
}
const toggleSelectAll = (value) => {
if (value) {
selected.value = new Set(tokens.value.map(({ id }) => id))
} else {
selected.value = new Set()
}
}
// Queue management
const showConfirm = ref(false)
const revokeQueue = ref([])
const revokeSingleToken = (id) => {
revokeQueue.value = [id]
showConfirm.value = true
}
const revokeSelected = () => {
revokeQueue.value = [...selected.value]
showConfirm.value = true
}
// Queue execution
const error = ref(null)
const revokeProgress = ref(false)
const revokeTokens = async () => {
+ if (revokeQueue.value.length === 0) return
showConfirm.value = false
revokeProgress.value = true
try {
const maxAttempts = 3
let attempts = 0
let id = revokeQueue.value.shift()
while (revokeProgress.value) {
try {
attempts++
await revokeToken(id)
attempts = 0
selected.value.delete(id)
id = revokeQueue.value.shift()
} catch (e) {
console.error('Error revoking token:' + e)
const recoverable = (() => {
if (e.statusCode) {
if (e.statusCode >= 400 && e.statusCode < 500) {
// 4xx - "We Messed Up"
if (e.statusCode === 429) {
return true // Throttled / Too Many Requests
} else {
return false
}
} else {
// 5xx - "Server Messed Up", should potentially be recoverable
return true
}
} else {
// Probably recoverable
return true
}
})()
if (attempts > maxAttempts || !recoverable) {
throw e
} else {
await wait(1000)
}
} finally {
if (id !== undefined) {
await wait(250)
} else {
revokeProgress.value = false
}
}
}
} catch (e) {
revokeQueue.value = []
error.value = e
} finally {
revokeProgress.value = false
}
}
const revokeAbort = () => {
revokeQueue.value = []
revokeProgress.value = false
showConfirm.value = false
}
return {
noUs,
allTokens,
selected,
toggleSelect,
toggleSelectAll,
allSelected,
someSelected,
showConfirm,
error,
revokeQueue,
revokeSingleToken,
revokeSelected,
revokeProgress,
revokeTokens,
revokeAbort,
}
},
methods: {
revokeToken(id) {
if (window.confirm(`${this.$i18n.t('settings.revoke_token')}?`)) {
useOAuthTokensStore().revokeToken(id)
}
},
},
}
export default Tokens
diff --git a/src/components/settings_modal/tabs/security_tab/tokens.vue b/src/components/settings_modal/tabs/security_tab/tokens.vue
index df141f653b..5f9140a656 100644
--- a/src/components/settings_modal/tabs/security_tab/tokens.vue
+++ b/src/components/settings_modal/tabs/security_tab/tokens.vue
@@ -1,132 +1,133 @@
<template>
<div class="Tokens setting-section">
<h3>{{ $t('settings.oauth_tokens') }}</h3>
<p class="alerts">
<div
v-if="noUs"
class="alert warning"
>
{{ $t('settings.tokens.no_current_info') }}
<br />
{{ $t('settings.tokens.no_current_consequences') }}
</div>
<div
v-if="error"
class="alert error"
>
{{ $t('settings.tokens.error') }}
<pre>{{ error }}</pre>
<button
:title="$t('general.dismiss')"
class="button-unstyled dismiss"
@click="error = null"
>
<FAIcon
class="fa-scale-110 fa-old-padding"
icon="times"
/>
</button>
</div>
</p>
<div class="table-wrapper">
<table>
<thead>
<tr>
<th class="selection">
<Checkbox
:model-value="allSelected"
:indeterminate="someSelected"
@update:model-value="toggleSelectAll"
:title="$t('selectable_list.select_all')"
/>
</th>
<th>{{ $t('settings.app_name') }}</th>
<th>{{ $t('settings.tokens.last_active') }}</th>
<th>{{ $t('settings.valid_until') }}</th>
<th class="actions">
<button
class="btn button-default"
@click="revokeSelected"
:disabled="!(someSelected || allSelected)"
>
{{ $t('settings.tokens.revoke_selected') }}
</button>
</th>
</tr>
</thead>
<tbody>
<tr
v-for="oauthToken in allTokens"
:key="oauthToken.id"
:class="{ '-us': oauthToken.current }"
>
<td class="selection">
<Checkbox
+ v-if="!oauthToken.current"
:model-value="selected.has(oauthToken.id)"
@update:model-value="e => toggleSelect(oauthToken.id, e)"
:title="$t('selectable_list.select')"
/>
</td>
<td>
{{ oauthToken.appName }} {{ oauthToken.current ? $t('settings.tokens.current') : '' }}
</td>
<td>
<Timeago
v-if="oauthToken.lastActive"
:time="oauthToken.lastActive"
template-key="time.in_past"
:auto-update="60"
/>
</td>
<td>{{ oauthToken.validLocalized }}</td>
<td class="actions">
<button
+ v-if="!oauthToken.current"
class="btn button-default"
@click="revokeSingleToken(oauthToken.id)"
- :class="{ '-danger': oauthToken.current }"
>
{{ $t('settings.revoke_token') }}
</button>
</td>
</tr>
</tbody>
</table>
<div
v-if="revokeProgress"
class="overlay"
>
<FAIcon
class="revoke-progress-spinner"
spin
icon="circle-notch"
/>
<p class="revoke-progress-progress">
<strong>{{ $t('settings.tokens.in_progress') }}</strong>
</p>
<p class="revoke-progress-progress">
{{ $t('settings.tokens.progress_status', { n: revokeQueue.length }) }}
</p>
<button
class="abort-button btn button-default"
@click="revokeAbort"
>
{{ $t('general.abort') }}
</button>
</div>
</div>
<ConfirmModal
v-if="showConfirm"
:title="$t('settings.tokens.confirm_title')"
:confirm-text="$t('settings.revoke_token')"
:cancel-text="$t('general.cancel')"
@accepted="revokeTokens"
@cancelled="revokeAbort"
>
{{ $t('settings.tokens.confirm_content', { n: revokeQueue.length }) }}
</ConfirmModal>
</div>
</template>
<script src="./tokens.js" />
<style src="./tokens.scss" />
diff --git a/src/stores/fetchers/notifications_fetcher.js b/src/stores/fetchers/notifications_fetcher.js
index 26629f02f0..95bcfd9eb1 100644
--- a/src/stores/fetchers/notifications_fetcher.js
+++ b/src/stores/fetchers/notifications_fetcher.js
@@ -1,138 +1,138 @@
import { ref } from 'vue'
import { useInstanceCapabilitiesStore } from 'src/stores/instance_capabilities.js'
import { useInterfaceStore } from 'src/stores/interface.js'
import { useMergedConfigStore } from 'src/stores/merged_config.js'
import { useNotificationsStore } from 'src/stores/notifications.js'
import { fetchTimeline } from 'src/api/timelines.js'
import { promiseInterval } from 'src/services/promise_interval/promise_interval.js'
// For using include_types when fetching notifications.
// Note: chat_mention excluded as pleroma-fe polls them separately
const mastoApiNotificationTypes = new Set([
'mention',
'status',
'favourite',
'reblog',
'follow',
'follow_request',
'move',
'poll',
'pleroma:emoji_reaction',
'pleroma:report',
])
const notificationsFetcher = (credentials) => {
const interval = ref(null)
const loading = ref(false)
const bottomedOut = ref(false)
const fetchNotifications = async ({ args, older }) => {
loading.value = true
try {
const response = await fetchTimeline(args)
const notifications = response.data
if (older && notifications.length === 0) bottomedOut.value = true
useNotificationsStore().addNewNotifications(response, older)
} catch (error) {
if (
error.statusCode === 400 &&
- error.statusText.includes('Invalid value for enum')
+ error.errorData.includes('Invalid value for enum')
) {
- error.statusText
+ error.errorData
.matchAll(/(\w+) - Invalid value for enum./g)
.toArray()
.map((x) => x[1])
.forEach((x) => mastoApiNotificationTypes.delete(x))
// Retry
return await fetchNotifications({ args, older })
}
console.error('Notifications Error', error)
useInterfaceStore().pushGlobalNotice({
level: 'error',
messageKey: 'notifications.error',
messageArgs: [error.message],
timeout: 5000,
})
} finally {
loading.value = false
}
}
const fetchAndUpdate = async ({ older = false, sinceId } = {}) => {
const args = { credentials }
const timelineData = useNotificationsStore()
const hideMutedPosts = useMergedConfigStore().mergedConfig.hideMutedPosts
if (useInstanceCapabilitiesStore().pleromaChatMessagesAvailable) {
mastoApiNotificationTypes.add('pleroma:chat_mention')
}
args.includeTypes = [...mastoApiNotificationTypes]
args.withMuted = !hideMutedPosts
args.timeline = 'notifications'
if (older) {
if (timelineData.minId !== '') {
args.maxId = timelineData.minId
}
return await fetchNotifications({ args, older })
} else {
// fetch new notifications
if (sinceId === undefined && timelineData.maxId !== '') {
args.sinceId = timelineData.maxId
} else if (sinceId !== null) {
args.sinceId = sinceId
}
const result = await fetchNotifications({ args, older })
// If there's any unread notifications, try fetch notifications since
// the newest read notification to check if any of the unread notifs
// have changed their 'seen' state (marked as read in another session), so
// we can update the state in this session to mark them as read as well.
// The normal maxId-check does not tell if older notifications have changed
const notifications = timelineData.data
const readNotifsIds = notifications.filter((n) => n.seen).map((n) => n.id)
const unreadNotifsIds = notifications
.filter((n) => !n.seen)
.map((n) => n.id)
if (readNotifsIds.length > 0 && unreadNotifsIds.length > 0) {
const minId = Math.min(...unreadNotifsIds) // Oldest known unread notification
if (minId !== Infinity) {
args.sinceId = null // Don't use since_id since it sorta conflicts with min_id
args.minId = minId - 1 // go beyond
fetchNotifications({ args, older })
}
}
return result
}
}
const startFetching = () => {
if (interval.value) throw new Error('Interval already exists!')
interval.value = promiseInterval(fetchAndUpdate, 10000)
}
const stopFetching = () => {
interval.value.stop()
interval.value = null
}
return {
loading,
bottomedOut,
startFetching,
stopFetching,
fetchOlder: () => fetchAndUpdate({ older: true }),
}
}
export default notificationsFetcher
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Tue, Nov 17, 8:51 AM (2 h, 33 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1839419
Default Alt Text
(14 KB)
Attached To
Mode
rPUFE pleroma-fe-upstream
Attached
Detach File
Event Timeline