mirror of
https://github.com/superseriousbusiness/gotosocial
synced 2025-06-05 21:59:39 +02:00
[feature] Allow users to set default interaction policies per status visibility (#3108)
* [feature] Allow users to set default interaction policies * use vars for default policies * avoid some code repetition * unfuck form binding * avoid bonkers loop * beep boop * put policyValsToAPIPolicyVals in separate function * don't bother with slices.Grow * oops
This commit is contained in:
@ -141,6 +141,7 @@ export const gtsApi = createApi({
|
||||
"InstanceRules",
|
||||
"HTTPHeaderAllows",
|
||||
"HTTPHeaderBlocks",
|
||||
"DefaultInteractionPolicies",
|
||||
],
|
||||
endpoints: (build) => ({
|
||||
instanceV1: build.query<InstanceV1, void>({
|
||||
|
@ -25,6 +25,7 @@ import type {
|
||||
} from "../../types/migration";
|
||||
import type { Theme } from "../../types/theme";
|
||||
import { User } from "../../types/user";
|
||||
import { DefaultInteractionPolicies, UpdateDefaultInteractionPolicies } from "../../types/interaction";
|
||||
|
||||
const extended = gtsApi.injectEndpoints({
|
||||
endpoints: (build) => ({
|
||||
@ -38,9 +39,11 @@ const extended = gtsApi.injectEndpoints({
|
||||
}),
|
||||
...replaceCacheOnMutation("verifyCredentials")
|
||||
}),
|
||||
|
||||
user: build.query<User, void>({
|
||||
query: () => ({url: `/api/v1/user`})
|
||||
}),
|
||||
|
||||
passwordChange: build.mutation({
|
||||
query: (data) => ({
|
||||
method: "POST",
|
||||
@ -48,6 +51,7 @@ const extended = gtsApi.injectEndpoints({
|
||||
body: data
|
||||
})
|
||||
}),
|
||||
|
||||
emailChange: build.mutation<User, { password: string, new_email: string }>({
|
||||
query: (data) => ({
|
||||
method: "POST",
|
||||
@ -56,6 +60,7 @@ const extended = gtsApi.injectEndpoints({
|
||||
}),
|
||||
...replaceCacheOnMutation("user")
|
||||
}),
|
||||
|
||||
aliasAccount: build.mutation<any, UpdateAliasesFormData>({
|
||||
async queryFn(formData, _api, _extraOpts, fetchWithBQ) {
|
||||
// Pull entries out from the hooked form.
|
||||
@ -73,6 +78,7 @@ const extended = gtsApi.injectEndpoints({
|
||||
});
|
||||
}
|
||||
}),
|
||||
|
||||
moveAccount: build.mutation<any, MoveAccountFormData>({
|
||||
query: (data) => ({
|
||||
method: "POST",
|
||||
@ -80,11 +86,37 @@ const extended = gtsApi.injectEndpoints({
|
||||
body: data
|
||||
})
|
||||
}),
|
||||
|
||||
accountThemes: build.query<Theme[], void>({
|
||||
query: () => ({
|
||||
url: `/api/v1/accounts/themes`
|
||||
})
|
||||
})
|
||||
}),
|
||||
|
||||
defaultInteractionPolicies: build.query<DefaultInteractionPolicies, void>({
|
||||
query: () => ({
|
||||
url: `/api/v1/interaction_policies/defaults`
|
||||
}),
|
||||
providesTags: ["DefaultInteractionPolicies"]
|
||||
}),
|
||||
|
||||
updateDefaultInteractionPolicies: build.mutation<DefaultInteractionPolicies, UpdateDefaultInteractionPolicies>({
|
||||
query: (data) => ({
|
||||
method: "PATCH",
|
||||
url: `/api/v1/interaction_policies/defaults`,
|
||||
body: data,
|
||||
}),
|
||||
...replaceCacheOnMutation("defaultInteractionPolicies")
|
||||
}),
|
||||
|
||||
resetDefaultInteractionPolicies: build.mutation<DefaultInteractionPolicies, void>({
|
||||
query: () => ({
|
||||
method: "PATCH",
|
||||
url: `/api/v1/interaction_policies/defaults`,
|
||||
body: {},
|
||||
}),
|
||||
invalidatesTags: ["DefaultInteractionPolicies"]
|
||||
}),
|
||||
})
|
||||
});
|
||||
|
||||
@ -96,4 +128,7 @@ export const {
|
||||
useAliasAccountMutation,
|
||||
useMoveAccountMutation,
|
||||
useAccountThemesQuery,
|
||||
useDefaultInteractionPoliciesQuery,
|
||||
useUpdateDefaultInteractionPoliciesMutation,
|
||||
useResetDefaultInteractionPoliciesMutation,
|
||||
} = extended;
|
||||
|
@ -64,6 +64,17 @@ export interface Account {
|
||||
enable_rss: boolean,
|
||||
role: any,
|
||||
suspended?: boolean,
|
||||
source?: AccountSource;
|
||||
}
|
||||
|
||||
export interface AccountSource {
|
||||
fields: any[];
|
||||
follow_requests_count: number;
|
||||
language: string;
|
||||
note: string;
|
||||
privacy: string;
|
||||
sensitive: boolean;
|
||||
status_content_type: string;
|
||||
}
|
||||
|
||||
export interface SearchAccountParams {
|
||||
|
63
web/source/settings/lib/types/interaction.ts
Normal file
63
web/source/settings/lib/types/interaction.ts
Normal file
@ -0,0 +1,63 @@
|
||||
/*
|
||||
GoToSocial
|
||||
Copyright (C) GoToSocial Authors admin@gotosocial.org
|
||||
SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
export interface DefaultInteractionPolicies {
|
||||
direct: InteractionPolicy;
|
||||
private: InteractionPolicy;
|
||||
unlisted: InteractionPolicy;
|
||||
public: InteractionPolicy;
|
||||
}
|
||||
|
||||
export interface UpdateDefaultInteractionPolicies {
|
||||
direct: InteractionPolicy | null;
|
||||
private: InteractionPolicy | null;
|
||||
unlisted: InteractionPolicy | null;
|
||||
public: InteractionPolicy | null;
|
||||
}
|
||||
|
||||
export interface InteractionPolicy {
|
||||
can_favourite: InteractionPolicyEntry;
|
||||
can_reply: InteractionPolicyEntry;
|
||||
can_reblog: InteractionPolicyEntry;
|
||||
}
|
||||
|
||||
export interface InteractionPolicyEntry {
|
||||
always: InteractionPolicyValue[];
|
||||
with_approval: InteractionPolicyValue[];
|
||||
}
|
||||
|
||||
export type InteractionPolicyValue = string;
|
||||
|
||||
const PolicyValuePublic: InteractionPolicyValue = "public";
|
||||
const PolicyValueFollowers: InteractionPolicyValue = "followers";
|
||||
const PolicyValueFollowing: InteractionPolicyValue = "following";
|
||||
const PolicyValueMutuals: InteractionPolicyValue = "mutuals";
|
||||
const PolicyValueMentioned: InteractionPolicyValue = "mentioned";
|
||||
const PolicyValueAuthor: InteractionPolicyValue = "author";
|
||||
const PolicyValueMe: InteractionPolicyValue = "me";
|
||||
|
||||
export {
|
||||
PolicyValuePublic,
|
||||
PolicyValueFollowers,
|
||||
PolicyValueFollowing,
|
||||
PolicyValueMutuals,
|
||||
PolicyValueMentioned,
|
||||
PolicyValueAuthor,
|
||||
PolicyValueMe,
|
||||
};
|
Reference in New Issue
Block a user