Autocomplete domain mutes from list of known instances

This commit is contained in:
Sergey Suprunenko 2020-05-10 12:54:55 +02:00
parent acbef1ebdc
commit 1007039478
No known key found for this signature in database
GPG key ID: 5DCA7D1BE3914F9C
8 changed files with 79 additions and 22 deletions

View file

@ -13,6 +13,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Add ### Add
- Added private notifications option for push notifications - Added private notifications option for push notifications
- 'Copy link' button for statuses (in the ellipsis menu) - 'Copy link' button for statuses (in the ellipsis menu)
- Autocomplete domains from list of known instances
### Changed ### Changed
- Registration page no longer requires email if the server is configured not to require it - Registration page no longer requires email if the server is configured not to require it

View file

@ -5,9 +5,20 @@ const DomainMuteCard = {
components: { components: {
ProgressButton ProgressButton
}, },
computed: {
user () {
return this.$store.state.users.currentUser
},
muted () {
return this.user.domainMutes.includes(this.domain)
}
},
methods: { methods: {
unmuteDomain () { unmuteDomain () {
return this.$store.dispatch('unmuteDomain', this.domain) return this.$store.dispatch('unmuteDomain', this.domain)
},
muteDomain () {
return this.$store.dispatch('muteDomain', this.domain)
} }
} }
} }

View file

@ -4,6 +4,7 @@
{{ domain }} {{ domain }}
</div> </div>
<ProgressButton <ProgressButton
v-if="muted"
:click="unmuteDomain" :click="unmuteDomain"
class="btn btn-default" class="btn btn-default"
> >
@ -12,6 +13,16 @@
{{ $t('domain_mute_card.unmute_progress') }} {{ $t('domain_mute_card.unmute_progress') }}
</template> </template>
</ProgressButton> </ProgressButton>
<ProgressButton
v-else
:click="muteDomain"
class="btn btn-default"
>
{{ $t('domain_mute_card.mute') }}
<template slot="progress">
{{ $t('domain_mute_card.mute_progress') }}
</template>
</ProgressButton>
</div> </div>
</template> </template>
@ -34,5 +45,9 @@
button { button {
width: 10em; width: 10em;
} }
.autosuggest-results & {
padding-left: 1em;
}
} }
</style> </style>

View file

@ -32,12 +32,12 @@ const DomainMuteList = withSubscription({
const MutesAndBlocks = { const MutesAndBlocks = {
data () { data () {
return { return {
activeTab: 'profile', activeTab: 'profile'
newDomainToMute: ''
} }
}, },
created () { created () {
this.$store.dispatch('fetchTokens') this.$store.dispatch('fetchTokens')
this.$store.dispatch('getKnownDomains')
}, },
components: { components: {
TabSwitcher, TabSwitcher,
@ -51,6 +51,14 @@ const MutesAndBlocks = {
Autosuggest, Autosuggest,
Checkbox Checkbox
}, },
computed: {
knownDomains () {
return this.$store.state.instance.knownDomains
},
user () {
return this.$store.state.users.currentUser
}
},
methods: { methods: {
importFollows (file) { importFollows (file) {
return this.$store.state.api.backendInteractor.importFollows({ file }) return this.$store.state.api.backendInteractor.importFollows({ file })
@ -86,13 +94,13 @@ const MutesAndBlocks = {
filterUnblockedUsers (userIds) { filterUnblockedUsers (userIds) {
return reject(userIds, (userId) => { return reject(userIds, (userId) => {
const relationship = this.$store.getters.relationship(this.userId) const relationship = this.$store.getters.relationship(this.userId)
return relationship.blocking || userId === this.$store.state.users.currentUser.id return relationship.blocking || userId === this.user.id
}) })
}, },
filterUnMutedUsers (userIds) { filterUnMutedUsers (userIds) {
return reject(userIds, (userId) => { return reject(userIds, (userId) => {
const relationship = this.$store.getters.relationship(this.userId) const relationship = this.$store.getters.relationship(this.userId)
return relationship.muting || userId === this.$store.state.users.currentUser.id return relationship.muting || userId === this.user.id
}) })
}, },
queryUserIds (query) { queryUserIds (query) {
@ -111,12 +119,16 @@ const MutesAndBlocks = {
unmuteUsers (ids) { unmuteUsers (ids) {
return this.$store.dispatch('unmuteUsers', ids) return this.$store.dispatch('unmuteUsers', ids)
}, },
filterUnMutedDomains (urls) {
return urls.filter(url => !this.user.domainMutes.includes(url))
},
queryKnownDomains (query) {
return new Promise((resolve, reject) => {
resolve(this.knownDomains.filter(url => url.toLowerCase().includes(query)))
})
},
unmuteDomains (domains) { unmuteDomains (domains) {
return this.$store.dispatch('unmuteDomains', domains) return this.$store.dispatch('unmuteDomains', domains)
},
muteDomain () {
return this.$store.dispatch('muteDomain', this.newDomainToMute)
.then(() => { this.newDomainToMute = '' })
} }
} }
} }

View file

@ -119,21 +119,16 @@
<div :label="$t('settings.domain_mutes')"> <div :label="$t('settings.domain_mutes')">
<div class="domain-mute-form"> <div class="domain-mute-form">
<input <Autosuggest
v-model="newDomainToMute" :filter="filterUnMutedDomains"
:query="queryKnownDomains"
:placeholder="$t('settings.type_domains_to_mute')" :placeholder="$t('settings.type_domains_to_mute')"
type="text"
@keyup.enter="muteDomain"
> >
<ProgressButton <DomainMuteCard
class="btn btn-default domain-mute-button" slot-scope="row"
:click="muteDomain" :domain="row.item"
> />
{{ $t('domain_mute_card.mute') }} </Autosuggest>
<template slot="progress">
{{ $t('domain_mute_card.mute_progress') }}
</template>
</ProgressButton>
</div> </div>
<DomainMuteList <DomainMuteList
:refresh="true" :refresh="true"

View file

@ -401,7 +401,7 @@
"theme_help_v2_1": "You can also override certain component's colors and opacity by toggling the checkbox, use \"Clear all\" button to clear all overrides.", "theme_help_v2_1": "You can also override certain component's colors and opacity by toggling the checkbox, use \"Clear all\" button to clear all overrides.",
"theme_help_v2_2": "Icons underneath some entries are background/text contrast indicators, hover over for detailed info. Please keep in mind that when using transparency contrast indicators show the worst possible case.", "theme_help_v2_2": "Icons underneath some entries are background/text contrast indicators, hover over for detailed info. Please keep in mind that when using transparency contrast indicators show the worst possible case.",
"tooltipRadius": "Tooltips/alerts", "tooltipRadius": "Tooltips/alerts",
"type_domains_to_mute": "Type in domains to mute", "type_domains_to_mute": "Search domains to mute",
"upload_a_photo": "Upload a photo", "upload_a_photo": "Upload a photo",
"user_settings": "User Settings", "user_settings": "User Settings",
"values": { "values": {

View file

@ -1,6 +1,7 @@
import { set } from 'vue' import { set } from 'vue'
import { getPreset, applyTheme } from '../services/style_setter/style_setter.js' import { getPreset, applyTheme } from '../services/style_setter/style_setter.js'
import { CURRENT_VERSION } from '../services/theme_data/theme_data.service.js' import { CURRENT_VERSION } from '../services/theme_data/theme_data.service.js'
import apiService from '../services/api/api.service.js'
import { instanceDefaultProperties } from './config.js' import { instanceDefaultProperties } from './config.js'
const defaultState = { const defaultState = {
@ -48,6 +49,7 @@ const defaultState = {
postFormats: [], postFormats: [],
restrictedNicknames: [], restrictedNicknames: [],
safeDM: true, safeDM: true,
knownDomains: [],
// Feature-set, apparently, not everything here is reported... // Feature-set, apparently, not everything here is reported...
chatAvailable: false, chatAvailable: false,
@ -80,6 +82,9 @@ const instance = {
if (typeof value !== 'undefined') { if (typeof value !== 'undefined') {
set(state, name, value) set(state, name, value)
} }
},
setKnownDomains (state, domains) {
state.knownDomains = domains
} }
}, },
getters: { getters: {
@ -182,6 +187,18 @@ const instance = {
state.emojiFetched = true state.emojiFetched = true
dispatch('getStaticEmoji') dispatch('getStaticEmoji')
} }
},
async getKnownDomains ({ commit, rootState }) {
try {
const result = await apiService.fetchKnownDomains({
credentials: rootState.users.currentUser.credentials
})
commit('setKnownDomains', result)
} catch (e) {
console.warn("Can't load known domains")
console.warn(e)
}
} }
} }
} }

View file

@ -75,6 +75,7 @@ const MASTODON_SEARCH_2 = `/api/v2/search`
const MASTODON_USER_SEARCH_URL = '/api/v1/accounts/search' const MASTODON_USER_SEARCH_URL = '/api/v1/accounts/search'
const MASTODON_DOMAIN_BLOCKS_URL = '/api/v1/domain_blocks' const MASTODON_DOMAIN_BLOCKS_URL = '/api/v1/domain_blocks'
const MASTODON_STREAMING = '/api/v1/streaming' const MASTODON_STREAMING = '/api/v1/streaming'
const MASTODON_KNOWN_DOMAIN_LIST_URL = '/api/v1/instance/peers'
const PLEROMA_EMOJI_REACTIONS_URL = id => `/api/v1/pleroma/statuses/${id}/reactions` const PLEROMA_EMOJI_REACTIONS_URL = id => `/api/v1/pleroma/statuses/${id}/reactions`
const PLEROMA_EMOJI_REACT_URL = (id, emoji) => `/api/v1/pleroma/statuses/${id}/reactions/${emoji}` const PLEROMA_EMOJI_REACT_URL = (id, emoji) => `/api/v1/pleroma/statuses/${id}/reactions/${emoji}`
const PLEROMA_EMOJI_UNREACT_URL = (id, emoji) => `/api/v1/pleroma/statuses/${id}/reactions/${emoji}` const PLEROMA_EMOJI_UNREACT_URL = (id, emoji) => `/api/v1/pleroma/statuses/${id}/reactions/${emoji}`
@ -995,6 +996,10 @@ const search2 = ({ credentials, q, resolve, limit, offset, following }) => {
}) })
} }
const fetchKnownDomains = ({ credentials }) => {
return promisedRequest({ url: MASTODON_KNOWN_DOMAIN_LIST_URL, credentials })
}
const fetchDomainMutes = ({ credentials }) => { const fetchDomainMutes = ({ credentials }) => {
return promisedRequest({ url: MASTODON_DOMAIN_BLOCKS_URL, credentials }) return promisedRequest({ url: MASTODON_DOMAIN_BLOCKS_URL, credentials })
} }
@ -1193,6 +1198,7 @@ const apiService = {
updateNotificationSettings, updateNotificationSettings,
search2, search2,
searchUsers, searchUsers,
fetchKnownDomains,
fetchDomainMutes, fetchDomainMutes,
muteDomain, muteDomain,
unmuteDomain unmuteDomain