diff --git a/package.json b/package.json index ee36f87..3e014c6 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "lemmy-js-client", "description": "A javascript / typescript client for Lemmy", - "version": "0.10.0-rc.1", + "version": "0.10.0-rc.10", "author": "Dessalines ", "license": "AGPL-3.0", "main": "./dist/index.js", diff --git a/src/http.ts b/src/http.ts index ede0883..ab942cc 100644 --- a/src/http.ts +++ b/src/http.ts @@ -63,8 +63,8 @@ import { import { AddAdmin, AddAdminResponse, - BanUser, - BanUserResponse, + BanPerson, + BanPersonResponse, CreatePrivateMessage, DeleteAccount, DeletePrivateMessage, @@ -73,15 +73,15 @@ import { GetPrivateMessages, GetReplies, GetRepliesResponse, - GetUserDetails, - GetUserDetailsResponse, - GetUserMentions, - GetUserMentionsResponse, + GetPersonDetails, + GetPersonDetailsResponse, + GetPersonMentions, + GetPersonMentionsResponse, Login, LoginResponse, MarkAllAsRead, MarkPrivateMessageAsRead, - MarkUserMentionAsRead, + MarkPersonMentionAsRead, PasswordChange, PasswordReset, PasswordResetResponse, @@ -89,8 +89,8 @@ import { PrivateMessagesResponse, Register, SaveUserSettings, - UserMentionResponse, -} from './interfaces/api/user'; + PersonMentionResponse, +} from './interfaces/api/person'; enum HttpType { Get = 'GET', @@ -305,19 +305,21 @@ export class LemmyHttp { return this.wrapper(HttpType.Post, '/user/login', form); } - async getUserDetails(form: GetUserDetails): Promise { + async getPersonDetails( + form: GetPersonDetails + ): Promise { return this.wrapper(HttpType.Get, '/user', form); } - async getUserMentions( - form: GetUserMentions - ): Promise { + async getPersonMentions( + form: GetPersonMentions + ): Promise { return this.wrapper(HttpType.Get, '/user/mention', form); } - async markUserMentionAsRead( - form: MarkUserMentionAsRead - ): Promise { + async markPersonMentionAsRead( + form: MarkPersonMentionAsRead + ): Promise { return this.wrapper(HttpType.Post, '/user/mention/mark_as_read', form); } @@ -331,7 +333,7 @@ export class LemmyHttp { return this.wrapper(HttpType.Get, '/user/followed_communities', form); } - async banUser(form: BanUser): Promise { + async banPerson(form: BanPerson): Promise { return this.wrapper(HttpType.Post, '/user/ban', form); } diff --git a/src/interfaces/aggregates.ts b/src/interfaces/aggregates.ts index 01f5af7..43ca451 100644 --- a/src/interfaces/aggregates.ts +++ b/src/interfaces/aggregates.ts @@ -1,6 +1,6 @@ -export interface UserAggregates { +export interface PersonAggregates { id: number; - user_id: number; + person_id: number; post_count: number; post_score: number; comment_count: number; diff --git a/src/interfaces/api/comment.ts b/src/interfaces/api/comment.ts index f4bb64c..078a285 100644 --- a/src/interfaces/api/comment.ts +++ b/src/interfaces/api/comment.ts @@ -73,6 +73,7 @@ export interface GetComments { limit?: number; community_id?: number; community_name?: string; + saved_only: boolean; auth?: string; } diff --git a/src/interfaces/api/community.ts b/src/interfaces/api/community.ts index e0de844..2ed8f66 100644 --- a/src/interfaces/api/community.ts +++ b/src/interfaces/api/community.ts @@ -2,7 +2,7 @@ import { CommunityFollowerView, CommunityModeratorView, CommunityView, - UserViewSafe, + PersonViewSafe, } from '../views'; export interface GetCommunity { @@ -23,7 +23,7 @@ export interface CreateCommunity { description?: string; icon?: string; banner?: string; - nsfw: boolean; + nsfw?: boolean; auth: string; } @@ -45,7 +45,7 @@ export interface ListCommunitiesResponse { export interface BanFromCommunity { community_id: number; - user_id: number; + person_id: number; ban: boolean; remove_data: boolean; // Removes/Restores their comments and posts for that community reason?: string; @@ -54,13 +54,13 @@ export interface BanFromCommunity { } export interface BanFromCommunityResponse { - user_view: UserViewSafe; + person_view: PersonViewSafe; banned: boolean; } export interface AddModToCommunity { community_id: number; - user_id: number; + person_id: number; added: boolean; auth: string; } @@ -78,7 +78,7 @@ export interface EditCommunity { description?: string; icon?: string; banner?: string; - nsfw: boolean; + nsfw?: boolean; auth: string; } @@ -115,6 +115,6 @@ export interface GetFollowedCommunitiesResponse { export interface TransferCommunity { community_id: number; - user_id: number; + person_id: number; auth: string; } diff --git a/src/interfaces/api/index.ts b/src/interfaces/api/index.ts index 673bc8d..08342a9 100644 --- a/src/interfaces/api/index.ts +++ b/src/interfaces/api/index.ts @@ -2,5 +2,5 @@ export * from './comment'; export * from './community'; export * from './post'; export * from './site'; -export * from './user'; +export * from './person'; export * from './websocket'; diff --git a/src/interfaces/api/user.ts b/src/interfaces/api/person.ts similarity index 86% rename from src/interfaces/api/user.ts rename to src/interfaces/api/person.ts index c3c96c3..c42aea9 100644 --- a/src/interfaces/api/user.ts +++ b/src/interfaces/api/person.ts @@ -4,8 +4,8 @@ import { CommunityModeratorView, PostView, PrivateMessageView, - UserMentionView, - UserViewSafe, + PersonMentionView, + PersonViewSafe, } from '../views'; export interface Login { @@ -68,8 +68,8 @@ export interface LoginResponse { /** * `username` can only be used for local users. To get details for a federated user, pass `user_id` instead. */ -export interface GetUserDetails { - user_id?: number; +export interface GetPersonDetails { + person_id?: number; username?: string; sort: string; page?: number; @@ -79,8 +79,8 @@ export interface GetUserDetails { auth?: string; } -export interface GetUserDetailsResponse { - user_view: UserViewSafe; +export interface GetPersonDetailsResponse { + person_view: PersonViewSafe; follows: CommunityFollowerView[]; moderates: CommunityModeratorView[]; comments: CommentView[]; @@ -91,8 +91,8 @@ export interface GetRepliesResponse { replies: CommentView[]; } -export interface GetUserMentionsResponse { - mentions: UserMentionView[]; +export interface GetPersonMentionsResponse { + mentions: PersonMentionView[]; } export interface MarkAllAsRead { @@ -100,17 +100,17 @@ export interface MarkAllAsRead { } export interface AddAdmin { - user_id: number; + person_id: number; added: boolean; auth: string; } export interface AddAdminResponse { - admins: UserViewSafe[]; + admins: PersonViewSafe[]; } -export interface BanUser { - user_id: number; +export interface BanPerson { + person_id: number; ban: boolean; remove_data: boolean; // Removes/Restores their comments, posts, and communities reason?: string; @@ -118,8 +118,8 @@ export interface BanUser { auth: string; } -export interface BanUserResponse { - user_view: UserViewSafe; +export interface BanPersonResponse { + person_view: PersonViewSafe; banned: boolean; } @@ -131,7 +131,7 @@ export interface GetReplies { auth: string; } -export interface GetUserMentions { +export interface GetPersonMentions { sort: string; page?: number; limit?: number; @@ -139,14 +139,14 @@ export interface GetUserMentions { auth: string; } -export interface MarkUserMentionAsRead { - user_mention_id: number; +export interface MarkPersonMentionAsRead { + person_mention_id: number; read: boolean; auth: string; } -export interface UserMentionResponse { - user_mention_view: UserMentionView; +export interface PersonMentionResponse { + person_mention_view: PersonMentionView; } /** diff --git a/src/interfaces/api/post.ts b/src/interfaces/api/post.ts index 11b4b85..48acbef 100644 --- a/src/interfaces/api/post.ts +++ b/src/interfaces/api/post.ts @@ -44,6 +44,7 @@ export interface GetPosts { limit?: number; community_id?: number; community_name?: string; + saved_only: boolean; auth?: string; } diff --git a/src/interfaces/api/site.ts b/src/interfaces/api/site.ts index bf0e654..7f667ef 100644 --- a/src/interfaces/api/site.ts +++ b/src/interfaces/api/site.ts @@ -1,4 +1,4 @@ -import { UserSafeSettings } from '../source'; +import { LocalUserSettingsView } from '../views'; import { CommentView, CommunityView, @@ -13,7 +13,7 @@ import { ModStickyPostView, PostView, SiteView, - UserViewSafe, + PersonViewSafe, } from '../views'; /** @@ -35,11 +35,11 @@ export interface SearchResponse { comments: CommentView[]; posts: PostView[]; communities: CommunityView[]; - users: UserViewSafe[]; + users: PersonViewSafe[]; } export interface GetModlog { - mod_user_id?: number; + mod_person_id?: number; community_id?: number; page?: number; limit?: number; @@ -89,16 +89,16 @@ export interface SiteResponse { export interface GetSiteResponse { site_view?: SiteView; // Because the site might not be set up yet - admins: UserViewSafe[]; - banned: UserViewSafe[]; + admins: PersonViewSafe[]; + banned: PersonViewSafe[]; online: number; version: string; - my_user?: UserSafeSettings; // Gives back your user and settings if logged in + my_user?: LocalUserSettingsView; // Gives back your local user and settings if logged in federated_instances?: FederatedInstances; } export interface TransferSite { - user_id: number; + person_id: number; auth: string; } diff --git a/src/interfaces/others.ts b/src/interfaces/others.ts index 8cf0992..e162928 100644 --- a/src/interfaces/others.ts +++ b/src/interfaces/others.ts @@ -30,10 +30,10 @@ export enum UserOperation { RemoveCommunity, FollowCommunity, GetFollowedCommunities, - GetUserDetails, + GetPersonDetails, GetReplies, - GetUserMentions, - MarkUserMentionAsRead, + GetPersonMentions, + MarkPersonMentionAsRead, GetModlog, BanFromCommunity, AddModToCommunity, @@ -41,7 +41,7 @@ export enum UserOperation { EditSite, GetSite, AddAdmin, - BanUser, + BanPerson, Search, MarkAllAsRead, SaveUserSettings, diff --git a/src/interfaces/source.ts b/src/interfaces/source.ts index 8d50f76..fac4070 100644 --- a/src/interfaces/source.ts +++ b/src/interfaces/source.ts @@ -1,30 +1,7 @@ -export interface UserSafe { +export interface LocalUserSettings { id: number; - name: string; - preferred_username?: string; - avatar?: string; - admin: boolean; - banned: boolean; - published: string; - updated?: string; - matrix_user_id?: string; - actor_id: string; - bio?: string; - local: boolean; - banner?: string; - deleted: boolean; -} - -export interface UserSafeSettings { - id: number; - name: string; - preferred_username?: string; + person_id: number; email?: string; - avatar?: string; - admin: boolean; - banned: boolean; - published: string; - updated?: string; show_nsfw: boolean; theme: string; default_sort_type: number; @@ -32,13 +9,25 @@ export interface UserSafeSettings { lang: string; show_avatars: boolean; send_notifications_to_email: boolean; - matrix_user_id?: string; +} + +export interface PersonSafe { + id: number; + name: string; + preferred_username?: string; + avatar?: string; + banned: boolean; + published: string; + updated?: string; actor_id: string; bio?: string; local: boolean; - last_refreshed_at: string; banner?: string; deleted: boolean; + inbox_url: string; + shared_inbox_url: string; + matrix_user_id?: string; + admin: boolean; } export interface Site { @@ -106,14 +95,14 @@ export interface Post { export interface PasswordResetRequest { id: number; - user_id: number; + local_user_id: number; token_encrypted: string; published: string; } export interface ModRemovePost { id: number; - mod_user_id: number; + mod_person_id: number; post_id: number; reason?: string; removed?: boolean; @@ -122,7 +111,7 @@ export interface ModRemovePost { export interface ModLockPost { id: number; - mod_user_id: number; + mod_person_id: number; post_id: number; locked?: boolean; when_: string; @@ -130,7 +119,7 @@ export interface ModLockPost { export interface ModStickyPost { id: number; - mod_user_id: number; + mod_person_id: number; post_id: number; stickied?: boolean; when_: string; @@ -138,7 +127,7 @@ export interface ModStickyPost { export interface ModRemoveComment { id: number; - mod_user_id: number; + mod_person_id: number; comment_id: number; reason?: string; removed?: boolean; @@ -147,7 +136,7 @@ export interface ModRemoveComment { export interface ModRemoveCommunity { id: number; - mod_user_id: number; + mod_person_id: number; community_id: number; reason?: string; removed?: boolean; @@ -157,8 +146,8 @@ export interface ModRemoveCommunity { export interface ModBanFromCommunity { id: number; - mod_user_id: number; - other_user_id: number; + mod_person_id: number; + other_person_id: number; community_id: number; reason?: string; banned?: boolean; @@ -168,8 +157,8 @@ export interface ModBanFromCommunity { export interface ModBan { id: number; - mod_user_id: number; - other_user_id: number; + mod_person_id: number; + other_person_id: number; reason?: string; banned?: boolean; expires?: string; @@ -178,8 +167,8 @@ export interface ModBan { export interface ModAddCommunity { id: number; - mod_user_id: number; - other_user_id: number; + mod_person_id: number; + other_person_id: number; community_id: number; removed?: boolean; when_: string; @@ -187,8 +176,8 @@ export interface ModAddCommunity { export interface ModAdd { id: number; - mod_user_id: number; - other_user_id: number; + mod_person_id: number; + other_person_id: number; removed?: boolean; when_: string; } @@ -237,7 +226,7 @@ export interface Comment { local: boolean; } -export interface UserMention { +export interface PersonMention { id: number; recipient_id: number; comment_id: number; diff --git a/src/interfaces/views.ts b/src/interfaces/views.ts index f45da9e..5bbf4f3 100644 --- a/src/interfaces/views.ts +++ b/src/interfaces/views.ts @@ -3,7 +3,7 @@ import { CommunityAggregates, PostAggregates, SiteAggregates, - UserAggregates, + PersonAggregates, } from './aggregates'; import { Comment, @@ -22,22 +22,23 @@ import { PostReport, PrivateMessage, Site, - UserMention, - UserSafe, + PersonMention, + PersonSafe, + LocalUserSettings, } from './source'; -export interface UserViewSafe { - user: UserSafe; - counts: UserAggregates; +export interface PersonViewSafe { + person: PersonSafe; + counts: PersonAggregates; } -export interface UserMentionView { - user_mention: UserMention; +export interface PersonMentionView { + person_mention: PersonMention; comment: Comment; - creator: UserSafe; + creator: PersonSafe; post: Post; community: CommunitySafe; - recipient: UserSafe; + recipient: PersonSafe; counts: CommentAggregates; creator_banned_from_community: boolean; subscribed: boolean; @@ -45,21 +46,27 @@ export interface UserMentionView { my_vote?: number; } +export interface LocalUserSettingsView { + local_user: LocalUserSettings; + person: PersonSafe; + counts: PersonAggregates; +} + export interface SiteView { site: Site; - creator: UserSafe; + creator: PersonSafe; counts: SiteAggregates; } export interface PrivateMessageView { private_message: PrivateMessage; - creator: UserSafe; - recipient: UserSafe; + creator: PersonSafe; + recipient: PersonSafe; } export interface PostView { post: Post; - creator: UserSafe; + creator: PersonSafe; community: CommunitySafe; creator_banned_from_community: boolean; counts: PostAggregates; @@ -73,15 +80,15 @@ export interface PostReportView { post_report: PostReport; post: Post; community: CommunitySafe; - creator: UserSafe; - post_creator: UserSafe; - resolver?: UserSafe; + creator: PersonSafe; + post_creator: PersonSafe; + resolver?: PersonSafe; } export interface CommentView { comment: Comment; - creator: UserSafe; - recipient?: UserSafe; + creator: PersonSafe; + recipient?: PersonSafe; post: Post; community: CommunitySafe; counts: CommentAggregates; @@ -96,91 +103,91 @@ export interface CommentReportView { comment: Comment; post: Post; community: CommunitySafe; - creator: UserSafe; - comment_creator: UserSafe; - resolver?: UserSafe; + creator: PersonSafe; + comment_creator: PersonSafe; + resolver?: PersonSafe; } export interface ModAddCommunityView { mod_add_community: ModAddCommunity; - moderator: UserSafe; + moderator: PersonSafe; community: CommunitySafe; - modded_user: UserSafe; + modded_person: PersonSafe; } export interface ModAddView { mod_add: ModAdd; - moderator: UserSafe; - modded_user: UserSafe; + moderator: PersonSafe; + modded_person: PersonSafe; } export interface ModBanFromCommunityView { mod_ban_from_community: ModBanFromCommunity; - moderator: UserSafe; + moderator: PersonSafe; community: CommunitySafe; - banned_user: UserSafe; + banned_person: PersonSafe; } export interface ModBanView { mod_ban: ModBan; - moderator: UserSafe; - banned_user: UserSafe; + moderator: PersonSafe; + banned_person: PersonSafe; } export interface ModLockPostView { mod_lock_post: ModLockPost; - moderator: UserSafe; + moderator: PersonSafe; post: Post; community: CommunitySafe; } export interface ModRemoveCommentView { mod_remove_comment: ModRemoveComment; - moderator: UserSafe; + moderator: PersonSafe; comment: Comment; - commenter: UserSafe; + commenter: PersonSafe; post: Post; community: CommunitySafe; } export interface ModRemoveCommunityView { mod_remove_community: ModRemoveCommunity; - moderator: UserSafe; + moderator: PersonSafe; community: CommunitySafe; } export interface ModRemovePostView { mod_remove_post: ModRemovePost; - moderator: UserSafe; + moderator: PersonSafe; post: Post; community: CommunitySafe; } export interface ModStickyPostView { mod_sticky_post: ModStickyPost; - moderator: UserSafe; + moderator: PersonSafe; post: Post; community: CommunitySafe; } export interface CommunityFollowerView { community: CommunitySafe; - follower: UserSafe; + follower: PersonSafe; } export interface CommunityModeratorView { community: CommunitySafe; - moderator: UserSafe; + moderator: PersonSafe; } -export interface CommunityUserBanView { +export interface CommunityPersonBanView { community: CommunitySafe; - user: UserSafe; + person: PersonSafe; } export interface CommunityView { community: CommunitySafe; - creator: UserSafe; + creator: PersonSafe; subscribed: boolean; counts: CommunityAggregates; } diff --git a/src/websocket.ts b/src/websocket.ts index ffc215a..abaa89f 100644 --- a/src/websocket.ts +++ b/src/websocket.ts @@ -45,24 +45,24 @@ import { } from './interfaces/api/site'; import { AddAdmin, - BanUser, + BanPerson, CreatePrivateMessage, DeleteAccount, DeletePrivateMessage, EditPrivateMessage, GetPrivateMessages, GetReplies, - GetUserDetails, - GetUserMentions, + GetPersonDetails, + GetPersonMentions, Login, MarkAllAsRead, MarkPrivateMessageAsRead, - MarkUserMentionAsRead, + MarkPersonMentionAsRead, PasswordChange, PasswordReset, Register, SaveUserSettings, -} from './interfaces/api/user'; +} from './interfaces/api/person'; import { UserJoin, PostJoin, CommunityJoin } from './interfaces/api/websocket'; import { UserOperation } from './interfaces/others'; @@ -216,28 +216,28 @@ export class LemmyWebsocket { return wrapper(UserOperation.TransferSite, form); } - banUser(form: BanUser) { - return wrapper(UserOperation.BanUser, form); + banPerson(form: BanPerson) { + return wrapper(UserOperation.BanPerson, form); } addAdmin(form: AddAdmin) { return wrapper(UserOperation.AddAdmin, form); } - getUserDetails(form: GetUserDetails) { - return wrapper(UserOperation.GetUserDetails, form); + getPersonDetails(form: GetPersonDetails) { + return wrapper(UserOperation.GetPersonDetails, form); } getReplies(form: GetReplies) { return wrapper(UserOperation.GetReplies, form); } - getUserMentions(form: GetUserMentions) { - return wrapper(UserOperation.GetUserMentions, form); + getPersonMentions(form: GetPersonMentions) { + return wrapper(UserOperation.GetPersonMentions, form); } - markUserMentionAsRead(form: MarkUserMentionAsRead) { - return wrapper(UserOperation.MarkUserMentionAsRead, form); + markPersonMentionAsRead(form: MarkPersonMentionAsRead) { + return wrapper(UserOperation.MarkPersonMentionAsRead, form); } getModlog(form: GetModlog) {