From a0b3f7606bd528e0ceb1fb45475ef9ea97819c33 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Thu, 19 Aug 2021 20:49:15 -0400 Subject: [PATCH] Adding block person and block community actions (#22) * Adding block person and block community actions * Forgot creator_blocked from views * Adding creator_blocked to PersonMentionView * Moving blocked and follows to MyUserInfo * Change to local_user_view * Add moderates to MyUserInfo * Adding blockcommunityresponse * rename recipient to target --- src/http.ts | 20 ++++++++++++-------- src/interfaces/api/community.ts | 20 +++++++++++--------- src/interfaces/api/person.ts | 16 ++++++++++++++-- src/interfaces/api/site.ts | 18 ++++++++++++++++-- src/interfaces/others.ts | 3 ++- src/interfaces/views.ts | 14 ++++++++++++++ src/websocket.ts | 15 ++++++++++----- 7 files changed, 79 insertions(+), 27 deletions(-) diff --git a/src/http.ts b/src/http.ts index 4026e12..ead965f 100644 --- a/src/http.ts +++ b/src/http.ts @@ -16,6 +16,8 @@ import { AddModToCommunityResponse, BanFromCommunity, BanFromCommunityResponse, + BlockCommunity, + BlockCommunityResponse, CommunityResponse, CreateCommunity, DeleteCommunity, @@ -23,8 +25,6 @@ import { FollowCommunity, GetCommunity, GetCommunityResponse, - GetFollowedCommunities, - GetFollowedCommunitiesResponse, ListCommunities, ListCommunitiesResponse, RemoveCommunity, @@ -93,6 +93,8 @@ import { SaveUserSettings, ChangePassword, PersonMentionResponse, + BlockPerson, + BlockPersonResponse, } from './interfaces/api/person'; import { VERSION } from './interfaces/others'; @@ -174,6 +176,10 @@ export class LemmyHttp { return this.wrapper(HttpType.Post, '/community/follow', form); } + async blockCommunity(form: BlockCommunity): Promise { + return this.wrapper(HttpType.Post, '/community/block', form); + } + async deleteCommunity(form: DeleteCommunity): Promise { return this.wrapper(HttpType.Post, '/community/delete', form); } @@ -338,16 +344,14 @@ export class LemmyHttp { return this.wrapper(HttpType.Get, '/user/replies', form); } - async getFollowedCommunities( - form: GetFollowedCommunities - ): Promise { - return this.wrapper(HttpType.Get, '/user/followed_communities', form); - } - async banPerson(form: BanPerson): Promise { return this.wrapper(HttpType.Post, '/user/ban', form); } + async blockPerson(form: BlockPerson): Promise { + return this.wrapper(HttpType.Post, '/user/block', form); + } + async getCaptcha(): Promise { return this.wrapper(HttpType.Get, '/user/get_captcha', {}); } diff --git a/src/interfaces/api/community.ts b/src/interfaces/api/community.ts index 4371fc1..8959468 100644 --- a/src/interfaces/api/community.ts +++ b/src/interfaces/api/community.ts @@ -1,5 +1,4 @@ import { - CommunityFollowerView, CommunityModeratorView, CommunityView, PersonViewSafe, @@ -105,16 +104,19 @@ export interface FollowCommunity { auth: string; } -export interface GetFollowedCommunities { - auth: string; -} - -export interface GetFollowedCommunitiesResponse { - communities: CommunityFollowerView[]; -} - export interface TransferCommunity { community_id: number; person_id: number; auth: string; } + +export interface BlockCommunity { + community_id: number; + block: boolean; + auth: string; +} + +export interface BlockCommunityResponse { + community_view: CommunityView; + blocked: boolean; +} diff --git a/src/interfaces/api/person.ts b/src/interfaces/api/person.ts index ab35b76..4a58211 100644 --- a/src/interfaces/api/person.ts +++ b/src/interfaces/api/person.ts @@ -6,6 +6,8 @@ import { PrivateMessageView, PersonMentionView, PersonViewSafe, + CommunityBlockView, + PersonBlockView, } from '../views'; export interface Login { @@ -90,10 +92,9 @@ export interface GetPersonDetails { export interface GetPersonDetailsResponse { person_view: PersonViewSafe; - follows: CommunityFollowerView[]; - moderates: CommunityModeratorView[]; comments: CommentView[]; posts: PostView[]; + moderates: CommunityModeratorView[]; } export interface GetRepliesResponse { @@ -230,3 +231,14 @@ export interface GetReportCountResponse { comment_reports: number; post_reports: number; } + +export interface BlockPerson { + person_id: number; + block: boolean; + auth: string; +} + +export interface BlockPersonResponse { + person_view: PersonViewSafe; + blocked: boolean; +} diff --git a/src/interfaces/api/site.ts b/src/interfaces/api/site.ts index 5afc6e5..24f1518 100644 --- a/src/interfaces/api/site.ts +++ b/src/interfaces/api/site.ts @@ -1,4 +1,10 @@ -import { LocalUserSettingsView } from '../views'; +import { + CommunityBlockView, + CommunityFollowerView, + CommunityModeratorView, + LocalUserSettingsView, + PersonBlockView, +} from '../views'; import { CommentView, CommunityView, @@ -101,10 +107,18 @@ export interface GetSiteResponse { banned: PersonViewSafe[]; online: number; version: string; - my_user?: LocalUserSettingsView; // Gives back your local user and settings if logged in + my_user?: MyUserInfo; // Gives back your local user, settings, follows, and blocks if logged in federated_instances?: FederatedInstances; } +export interface MyUserInfo { + local_user_view: LocalUserSettingsView; + follows: CommunityFollowerView[]; + moderates: CommunityModeratorView[]; + community_blocks: CommunityBlockView[]; + person_blocks: PersonBlockView[]; +} + export interface TransferSite { person_id: number; auth: string; diff --git a/src/interfaces/others.ts b/src/interfaces/others.ts index 618df11..014b0ae 100644 --- a/src/interfaces/others.ts +++ b/src/interfaces/others.ts @@ -31,7 +31,6 @@ export enum UserOperation { DeleteCommunity, RemoveCommunity, FollowCommunity, - GetFollowedCommunities, GetPersonDetails, GetReplies, GetPersonMentions, @@ -65,6 +64,8 @@ export enum UserOperation { CommunityJoin, ChangePassword, GetSiteMetadata, + BlockCommunity, + BlockPerson, } export enum SortType { diff --git a/src/interfaces/views.ts b/src/interfaces/views.ts index 39c202e..d18de8f 100644 --- a/src/interfaces/views.ts +++ b/src/interfaces/views.ts @@ -44,6 +44,7 @@ export interface PersonMentionView { creator_banned_from_community: boolean; subscribed: boolean; saved: boolean; + creator_blocked: boolean; my_vote?: number; } @@ -74,6 +75,7 @@ export interface PostView { subscribed: boolean; saved: boolean; read: boolean; + creator_blocked: boolean; my_vote?: number; } @@ -96,6 +98,7 @@ export interface CommentView { creator_banned_from_community: boolean; subscribed: boolean; saved: boolean; + creator_blocked: boolean; my_vote?: number; } @@ -183,6 +186,11 @@ export interface CommunityFollowerView { follower: PersonSafe; } +export interface CommunityBlockView { + person: PersonSafe; + community: CommunitySafe; +} + export interface CommunityModeratorView { community: CommunitySafe; moderator: PersonSafe; @@ -193,8 +201,14 @@ export interface CommunityPersonBanView { person: PersonSafe; } +export interface PersonBlockView { + person: PersonSafe; + target: PersonSafe; +} + export interface CommunityView { community: CommunitySafe; subscribed: boolean; + blocked: boolean; counts: CommunityAggregates; } diff --git a/src/websocket.ts b/src/websocket.ts index d8083d4..f8c02fc 100644 --- a/src/websocket.ts +++ b/src/websocket.ts @@ -11,12 +11,12 @@ import { import { AddModToCommunity, BanFromCommunity, + BlockCommunity, CreateCommunity, DeleteCommunity, EditCommunity, FollowCommunity, GetCommunity, - GetFollowedCommunities, ListCommunities, RemoveCommunity, TransferCommunity, @@ -64,6 +64,7 @@ import { Register, SaveUserSettings, ChangePassword, + BlockPerson, } from './interfaces/api/person'; import { UserJoin, PostJoin, CommunityJoin } from './interfaces/api/websocket'; import { UserOperation } from './interfaces/others'; @@ -122,10 +123,6 @@ export class LemmyWebsocket { return wrapper(UserOperation.ListCommunities, form); } - getFollowedCommunities(form: GetFollowedCommunities) { - return wrapper(UserOperation.GetFollowedCommunities, form); - } - createPost(form: CreatePost) { return wrapper(UserOperation.CreatePost, form); } @@ -317,6 +314,14 @@ export class LemmyWebsocket { saveSiteConfig(form: SaveSiteConfig) { return wrapper(UserOperation.SaveSiteConfig, form); } + + blockPerson(form: BlockPerson) { + return wrapper(UserOperation.BlockPerson, form); + } + + blockCommunity(form: BlockCommunity) { + return wrapper(UserOperation.BlockCommunity, form); + } } function wrapper(op: UserOperation, data: MessageType) {