Update API to deal with new person table. Fixes #7

This commit is contained in:
Dessalines 2021-03-12 13:22:16 -05:00
parent e61cb5d7ba
commit a7937e53f2
10 changed files with 150 additions and 151 deletions

View file

@ -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<GetUserDetailsResponse> {
async getPersonDetails(
form: GetPersonDetails
): Promise<GetPersonDetailsResponse> {
return this.wrapper(HttpType.Get, '/user', form);
}
async getUserMentions(
form: GetUserMentions
): Promise<GetUserMentionsResponse> {
async getPersonMentions(
form: GetPersonMentions
): Promise<GetPersonMentionsResponse> {
return this.wrapper(HttpType.Get, '/user/mention', form);
}
async markUserMentionAsRead(
form: MarkUserMentionAsRead
): Promise<UserMentionResponse> {
async markPersonMentionAsRead(
form: MarkPersonMentionAsRead
): Promise<PersonMentionResponse> {
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<BanUserResponse> {
async banPerson(form: BanPerson): Promise<BanPersonResponse> {
return this.wrapper(HttpType.Post, '/user/ban', form);
}
@ -355,7 +357,7 @@ export class LemmyHttp {
return this.wrapper(HttpType.Post, '/user/mark_all_as_read', form);
}
async saveUserSettings(form: SaveUserSettings): Promise<LoginResponse> {
async savePersonSettings(form: SaveUserSettings): Promise<LoginResponse> {
return this.wrapper(HttpType.Put, '/user/save_user_settings', form);
}

View file

@ -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;

View file

@ -2,7 +2,7 @@ import {
CommunityFollowerView,
CommunityModeratorView,
CommunityView,
UserViewSafe,
PersonViewSafe,
} from '../views';
export interface GetCommunity {
@ -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;
}
@ -115,6 +115,6 @@ export interface GetFollowedCommunitiesResponse {
export interface TransferCommunity {
community_id: number;
user_id: number;
person_id: number;
auth: string;
}

View file

@ -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';

View file

@ -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;
local_user_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;
}
/**

View file

@ -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;
}

View file

@ -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,

View file

@ -1,30 +1,8 @@
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;
@ -33,12 +11,24 @@ export interface UserSafeSettings {
show_avatars: boolean;
send_notifications_to_email: boolean;
matrix_user_id?: string;
}
export interface PersonSafe {
id: number;
name: string;
preferred_username?: string;
avatar?: string;
admin: boolean;
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;
}
export interface Site {
@ -106,14 +96,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 +112,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 +120,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 +128,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 +137,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 +147,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 +158,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 +168,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 +177,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 +227,7 @@ export interface Comment {
local: boolean;
}
export interface UserMention {
export interface PersonMention {
id: number;
recipient_id: number;
comment_id: number;

View file

@ -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;
}

View file

@ -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) {