Merge branch '482-wish-collection-filters-should-include-the-local-instance-in-trusted-instances' into 'master'

Resolve "🎁 Wish: Collection filters should include the local instance in "Trusted Instances""

Closes #482

See merge request les/gancio!65
This commit is contained in:
les 2024-11-12 13:10:25 +00:00
commit 1aca85bdfc
4 changed files with 42 additions and 7 deletions

View file

@ -42,7 +42,7 @@ v-container
template(v-slot:append-outer v-if='!collection.id')
v-btn(text @click='saveCollection' color='primary' :loading='loading'
:disabled='!valid || loading || !!collection.id') {{ $t('common.save') }}
h3(v-else class='text-h5' v-text='collection.name')
h3(v-else class='text-h6' v-text='collection.name')
v-row
v-col(cols=6)
@ -61,13 +61,13 @@ v-container
:label="$t('common.trusted_instances')")
template(v-slot:item="{ item }")
v-list-item-avatar
v-img(:src='item?.object?.icon?.url ?? `${item.url}/favicon.ico`')
v-img(:src="$format.actor(item, 'icon')")
v-list-item-content
v-list-item-title {{ item?.object?.name }}
v-list-item-subtitle @{{ item?.object?.preferredUsername }}@{{ item?.instanceDomain }}
v-list-item-title {{ $format.actor(item, 'title')}}
v-list-item-subtitle {{ $format.actor(item, 'label') }}
template(v-slot:selection="{ item, on, attrs, selected, parent }")
v-chip(v-bind="attrs" close :close-icon='mdiCloseCircle' @click:close='parent.selectItem(item)'
:input-value="selected" label small) @{{ item?.object?.preferredUsername }}@{{ item?.instanceDomain }}
:input-value="selected" label small) {{$format.actor(item, 'label')}}
v-col(cols=6)
v-autocomplete(v-model='filterPlaces'
@ -127,7 +127,7 @@ v-container
template(v-slot:item.places='{ item }')
v-chip.ma-1(small label v-for='place in item.places' v-text='place.name' :key='place.id' )
template(v-slot:item.actors='{ item }')
v-chip.ma-1(small label v-for='actor in item.actors' :key='actor.ap_id' ) @{{ actor.name }}@{{ actor?.domain }}
v-chip.ma-1(small label v-for='actor in item.actors' :key='actor.ap_id' ) {{ $format.actor(actor, 'filter') }}
v-card-actions
@ -205,6 +205,9 @@ export default {
async fetch() {
this.collections = await this.$axios.$get('/collections?withFilters=true')
this.actors = await this.$axios.$get('/instances/trusted')
// add local instance
this.actors.unshift({ ap_id: null })
},
computed: {
...mapState(['settings']),

View file

@ -46,6 +46,7 @@ module.exports = {
'@/plugins/validators', // inject validators
'@/plugins/api', // api helpers
'@/plugins/i18n',
'@/plugins/formatter',
{ src: '@/plugins/v-calendar', ssr: false } // v-calendar
],

26
plugins/formatter.js Normal file
View file

@ -0,0 +1,26 @@
export default ({ app, store }, inject) => {
const formatter = {
actor (actor, context='label') {
if (context === 'title') {
if (actor?.ap_id) {
return actor?.object?.name
} else {
return 'Local Instance'
}
} else if (context === 'label' || context === 'filter') {
if (actor?.ap_id) {
return `@${actor?.object?.preferredUsername ?? actor?.name}@${actor?.instanceDomain ?? actor?.domain}`
} else {
return `@${store?.state?.settings?.instance_name}@${store?.state?.settings?.hostname}`
}
} else if (context === 'icon') {
if (actor?.ap_id) {
return actor?.object?.icon?.url ?? `${item.url}/favicon.ico`
} else {
return store.state.settings.baseurl + '/logo.png'
}
}
}
}
inject('format', formatter)
}

View file

@ -154,7 +154,12 @@ const collectionController = {
}
if (f.actors && f.actors.length) {
tmpConditions.push({ apUserApId: f.actors.map(a => a.ap_id)})
// search for local instance
if (f.actors.find(a => a.ap_id === null)) {
tmpConditions.push({ [Op.or]: [{ apUserApId: f.actors.map(a => a.ap_id).filter(a => a)}, { apUserApId: null }]})
} else {
tmpConditions.push({ apUserApId: f.actors.map(a => a.ap_id) })
}
}
if (!tmpConditions.length) return