Support for searching local posts/users only

This commit is contained in:
itepechi 2023-11-15 07:58:24 +09:00
parent 8398670530
commit c578846b98
8 changed files with 43 additions and 15 deletions

View File

@ -283,6 +283,7 @@ const getNodeInfo = async ({ store }) => {
store.dispatch('setInstanceOption', { name: 'translationEnabled', value: features.includes('akkoma:machine_translation') }) store.dispatch('setInstanceOption', { name: 'translationEnabled', value: features.includes('akkoma:machine_translation') })
store.dispatch('setInstanceOption', { name: 'searchTypeMediaEnabled', value: features.includes('bnakkoma:search_type_media') }) store.dispatch('setInstanceOption', { name: 'searchTypeMediaEnabled', value: features.includes('bnakkoma:search_type_media') })
store.dispatch('setInstanceOption', { name: 'searchOptionFollowingEnabled', value: features.includes('bnakkoma:search_option_following') }) store.dispatch('setInstanceOption', { name: 'searchOptionFollowingEnabled', value: features.includes('bnakkoma:search_option_following') })
store.dispatch('setInstanceOption', { name: 'searchOptionLocalEnabled', value: features.includes('bnakkoma:search_option_local') })
store.dispatch('setInstanceOption', { name: 'opensearchProtocolSupported', value: features.includes('bnakkoma:opensearch_protocol') }) store.dispatch('setInstanceOption', { name: 'opensearchProtocolSupported', value: features.includes('bnakkoma:opensearch_protocol') })
const uploadLimits = metadata.uploadLimits const uploadLimits = metadata.uploadLimits

View File

@ -68,16 +68,9 @@ const Search = {
allStatusesObject[status.id] && !allStatusesObject[status.id].deleted allStatusesObject[status.id] && !allStatusesObject[status.id].deleted
) )
}, },
isLoggedIn () {
return !!this.$store.state.users.currentUser
},
canSearchMediaPosts () { canSearchMediaPosts () {
return this.$store.state.instance.searchTypeMediaEnabled === true return this.$store.state.instance.searchTypeMediaEnabled === true
}, },
canSearchFollowing () {
return this.isLoggedIn &&
this.$store.state.instance.searchOptionFollowingEnabled === true
},
hasAtLeastOneResult () { hasAtLeastOneResult () {
return allSearchTypes return allSearchTypes
.some((searchType) => this.getVisibleLength(searchType) > 0) .some((searchType) => this.getVisibleLength(searchType) > 0)
@ -165,7 +158,8 @@ const Search = {
offset: searchOffset, offset: searchOffset,
'type': searchType, 'type': searchType,
following: following:
'followingOnly' in this.filter && this.filter.followingOnly 'followingOnly' in this.filter && this.filter.followingOnly,
local: 'localOnly' in this.filter && this.filter.localOnly
}) })
// Always append to old results. If new results are empty, this doesn't change anything // Always append to old results. If new results are empty, this doesn't change anything

View File

@ -5,7 +5,6 @@
{{ $t('nav.search') }} {{ $t('nav.search') }}
</div> </div>
<SearchFilters <SearchFilters
v-show="canSearchFollowing"
v-model="filter" v-model="filter"
/> />
</div> </div>

View File

@ -1,5 +1,6 @@
<template> <template>
<Popover <Popover
v-if="showFilters"
trigger="click" trigger="click"
class="SearchFilters" class="SearchFilters"
placement="bottom" placement="bottom"
@ -8,6 +9,7 @@
<template #content> <template #content>
<div class="dropdown-menu"> <div class="dropdown-menu">
<button <button
v-if="canSearchFollowing"
class="button-default dropdown-item" class="button-default dropdown-item"
@click="toggleFilter('followingOnly')" @click="toggleFilter('followingOnly')"
> >
@ -16,6 +18,16 @@
:class="{ 'menu-checkbox-checked': currentFilter.followingOnly }" :class="{ 'menu-checkbox-checked': currentFilter.followingOnly }"
/>{{ $t('lists.following_only') }} />{{ $t('lists.following_only') }}
</button> </button>
<button
v-if="canSearchLocal"
class="button-default dropdown-item"
@click="toggleFilter('localOnly')"
>
<span
class="menu-checkbox"
:class="{ 'menu-checkbox-checked': currentFilter.localOnly }"
/>{{ $t('search.local_only') }}
</button>
</div> </div>
</template> </template>
<template #trigger> <template #trigger>
@ -46,10 +58,26 @@ export default {
data () { data () {
return { return {
currentFilter: { currentFilter: {
followingOnly: false followingOnly: false,
localOnly: false
} }
} }
}, },
computed: {
showFilters () {
return this.canSearchFollowing || this.canSearchLocal
},
isLoggedIn () {
return !!this.$store.state.users.currentUser
},
canSearchFollowing () {
return this.isLoggedIn &&
this.$store.state.instance.searchOptionFollowingEnabled
},
canSearchLocal () {
return this.$store.state.instance.searchOptionLocalEnabled
},
},
created () { created () {
for (const filterName of Object.entries(this.currentFilter)) { for (const filterName of Object.entries(this.currentFilter)) {
if (this.modelValue && filterName in this.modelValue) { if (this.modelValue && filterName in this.modelValue) {

View File

@ -450,7 +450,8 @@
"people_talking": "{count} people talking", "people_talking": "{count} people talking",
"person_talking": "{count} person talking", "person_talking": "{count} person talking",
"no_more_results": "No more results", "no_more_results": "No more results",
"load_more": "Load more results" "load_more": "Load more results",
"local_only": "Limit to Local"
}, },
"selectable_list": { "selectable_list": {
"select_all": "Select all" "select_all": "Select all"

View File

@ -449,7 +449,8 @@
"people_talking": "{count}人が話しています", "people_talking": "{count}人が話しています",
"person_talking": "{count}人が話しています", "person_talking": "{count}人が話しています",
"no_more_results": "すべて表示しました", "no_more_results": "すべて表示しました",
"load_more": "さらに表示" "load_more": "さらに表示",
"local_only": "ローカルのユーザーのみ"
}, },
"selectable_list": { "selectable_list": {
"select_all": "すべて選択" "select_all": "すべて選択"

View File

@ -766,8 +766,8 @@ const statuses = {
rootState.api.backendInteractor.fetchRebloggedByUsers({ id }) rootState.api.backendInteractor.fetchRebloggedByUsers({ id })
.then(rebloggedByUsers => commit('addRepeats', { id, rebloggedByUsers, currentUser: rootState.users.currentUser })) .then(rebloggedByUsers => commit('addRepeats', { id, rebloggedByUsers, currentUser: rootState.users.currentUser }))
}, },
search ({ rootState, dispatch }, { q, resolve, limit, offset, following, type }) { search ({ rootState, dispatch }, { q, resolve, limit, offset, following, local, type }) {
return rootState.api.backendInteractor.search2({ q, resolve, limit, offset, following, type }) return rootState.api.backendInteractor.search2({ q, resolve, limit, offset, following, local, type })
.then((data) => { .then((data) => {
dispatch('addNewUsers', data.accounts) dispatch('addNewUsers', data.accounts)
dispatch('addNewStatuses', { statuses: data.statuses }) dispatch('addNewStatuses', { statuses: data.statuses })

View File

@ -1380,7 +1380,7 @@ const searchUsers = ({ credentials, query }) => {
.then((data) => data.map(parseUser)) .then((data) => data.map(parseUser))
} }
const search2 = ({ credentials, q, resolve, limit, offset, following, type }) => { const search2 = ({ credentials, q, resolve, limit, offset, following, local, type }) => {
let url = MASTODON_SEARCH_2 let url = MASTODON_SEARCH_2
let params = [] let params = []
@ -1404,6 +1404,10 @@ const search2 = ({ credentials, q, resolve, limit, offset, following, type }) =>
params.push(['following', true]) params.push(['following', true])
} }
if (local) {
params.push(['local', true])
}
if (type) { if (type) {
params.push(['type', type]) params.push(['type', type])
} }