]> Untitled Git - lemmy.git/blob - ui/src/interfaces.ts
Merge remote-tracking branch 'nutomic/http-api' into dessalines-http-api
[lemmy.git] / ui / src / interfaces.ts
1 export enum UserOperation {
2   Login,
3   Register,
4   CreateCommunity,
5   CreatePost,
6   ListCommunities,
7   ListCategories,
8   GetPost,
9   GetCommunity,
10   CreateComment,
11   EditComment,
12   SaveComment,
13   CreateCommentLike,
14   GetPosts,
15   CreatePostLike,
16   EditPost,
17   SavePost,
18   EditCommunity,
19   FollowCommunity,
20   GetFollowedCommunities,
21   GetUserDetails,
22   GetReplies,
23   GetUserMentions,
24   EditUserMention,
25   GetModlog,
26   BanFromCommunity,
27   AddModToCommunity,
28   CreateSite,
29   EditSite,
30   GetSite,
31   AddAdmin,
32   BanUser,
33   Search,
34   MarkAllAsRead,
35   SaveUserSettings,
36   TransferCommunity,
37   TransferSite,
38   DeleteAccount,
39   PasswordReset,
40   PasswordChange,
41 }
42
43 export enum CommentSortType {
44   Hot,
45   Top,
46   New,
47 }
48
49 export enum ListingType {
50   All,
51   Subscribed,
52   Community,
53 }
54
55 export enum SortType {
56   Hot,
57   New,
58   TopDay,
59   TopWeek,
60   TopMonth,
61   TopYear,
62   TopAll,
63 }
64
65 export enum SearchType {
66   All,
67   Comments,
68   Posts,
69   Communities,
70   Users,
71   Url,
72 }
73
74 export interface User {
75   id: number;
76   iss: string;
77   username: string;
78   show_nsfw: boolean;
79   theme: string;
80   default_sort_type: SortType;
81   default_listing_type: ListingType;
82   lang: string;
83   avatar?: string;
84   show_avatars: boolean;
85 }
86
87 export interface UserView {
88   id: number;
89   name: string;
90   avatar?: string;
91   email?: string;
92   fedi_name: string;
93   published: string;
94   number_of_posts: number;
95   post_score: number;
96   number_of_comments: number;
97   comment_score: number;
98   banned: boolean;
99   show_avatars: boolean;
100   send_notifications_to_email: boolean;
101 }
102
103 export interface CommunityUser {
104   id: number;
105   user_id: number;
106   user_name: string;
107   avatar?: string;
108   community_id: number;
109   community_name: string;
110   published: string;
111 }
112
113 export interface Community {
114   id: number;
115   name: string;
116   title: string;
117   description?: string;
118   category_id: number;
119   creator_id: number;
120   removed: boolean;
121   deleted: boolean;
122   nsfw: boolean;
123   published: string;
124   updated?: string;
125   creator_name: string;
126   creator_avatar?: string;
127   category_name: string;
128   number_of_subscribers: number;
129   number_of_posts: number;
130   number_of_comments: number;
131   user_id?: number;
132   subscribed?: boolean;
133 }
134
135 export interface Post {
136   id: number;
137   name: string;
138   url?: string;
139   body?: string;
140   creator_id: number;
141   community_id: number;
142   removed: boolean;
143   deleted: boolean;
144   locked: boolean;
145   stickied: boolean;
146   nsfw: boolean;
147   banned: boolean;
148   banned_from_community: boolean;
149   published: string;
150   updated?: string;
151   creator_name: string;
152   creator_avatar?: string;
153   community_name: string;
154   community_removed: boolean;
155   community_deleted: boolean;
156   community_nsfw: boolean;
157   number_of_comments: number;
158   score: number;
159   upvotes: number;
160   downvotes: number;
161   hot_rank: number;
162   user_id?: number;
163   my_vote?: number;
164   subscribed?: boolean;
165   read?: boolean;
166   saved?: boolean;
167 }
168
169 export interface Comment {
170   id: number;
171   creator_id: number;
172   post_id: number;
173   parent_id?: number;
174   content: string;
175   removed: boolean;
176   deleted: boolean;
177   read: boolean;
178   published: string;
179   updated?: string;
180   community_id: number;
181   banned: boolean;
182   banned_from_community: boolean;
183   creator_name: string;
184   creator_avatar?: string;
185   score: number;
186   upvotes: number;
187   downvotes: number;
188   user_id?: number;
189   my_vote?: number;
190   saved?: boolean;
191   user_mention_id?: number; // For mention type
192   recipient_id?: number;
193 }
194
195 export interface Category {
196   id: number;
197   name: string;
198 }
199
200 export interface Site {
201   id: number;
202   name: string;
203   description?: string;
204   creator_id: number;
205   published: string;
206   updated?: string;
207   creator_name: string;
208   number_of_users: number;
209   number_of_posts: number;
210   number_of_comments: number;
211   number_of_communities: number;
212   enable_downvotes: boolean;
213   open_registration: boolean;
214   enable_nsfw: boolean;
215 }
216
217 export enum BanType {
218   Community,
219   Site,
220 }
221
222 export interface FollowCommunityForm {
223   community_id: number;
224   follow: boolean;
225   auth?: string;
226 }
227
228 export interface GetFollowedCommunitiesResponse {
229   communities: Array<CommunityUser>;
230 }
231
232 export interface GetUserDetailsForm {
233   user_id?: number;
234   username?: string;
235   sort: string;
236   page?: number;
237   limit?: number;
238   community_id?: number;
239   saved_only: boolean;
240 }
241
242 export interface UserDetailsResponse {
243   user: UserView;
244   follows: Array<CommunityUser>;
245   moderates: Array<CommunityUser>;
246   comments: Array<Comment>;
247   posts: Array<Post>;
248   admins: Array<UserView>;
249 }
250
251 export interface GetRepliesForm {
252   sort: string;
253   page?: number;
254   limit?: number;
255   unread_only: boolean;
256   auth?: string;
257 }
258
259 export interface GetRepliesResponse {
260   replies: Array<Comment>;
261 }
262
263 export interface GetUserMentionsForm {
264   sort: string;
265   page?: number;
266   limit?: number;
267   unread_only: boolean;
268   auth?: string;
269 }
270
271 export interface GetUserMentionsResponse {
272   mentions: Array<Comment>;
273 }
274
275 export interface EditUserMentionForm {
276   user_mention_id: number;
277   read?: boolean;
278   auth?: string;
279 }
280
281 export interface UserMentionResponse {
282   mention: Comment;
283 }
284
285 export interface BanFromCommunityForm {
286   community_id: number;
287   user_id: number;
288   ban: boolean;
289   reason?: string;
290   expires?: number;
291   auth?: string;
292 }
293
294 export interface BanFromCommunityResponse {
295   user: UserView;
296   banned: boolean;
297 }
298
299 export interface AddModToCommunityForm {
300   community_id: number;
301   user_id: number;
302   added: boolean;
303   auth?: string;
304 }
305
306 export interface TransferCommunityForm {
307   community_id: number;
308   user_id: number;
309   auth?: string;
310 }
311
312 export interface TransferSiteForm {
313   user_id: number;
314   auth?: string;
315 }
316
317 export interface AddModToCommunityResponse {
318   moderators: Array<CommunityUser>;
319 }
320
321 export interface GetModlogForm {
322   mod_user_id?: number;
323   community_id?: number;
324   page?: number;
325   limit?: number;
326 }
327
328 export interface GetModlogResponse {
329   removed_posts: Array<ModRemovePost>;
330   locked_posts: Array<ModLockPost>;
331   stickied_posts: Array<ModStickyPost>;
332   removed_comments: Array<ModRemoveComment>;
333   removed_communities: Array<ModRemoveCommunity>;
334   banned_from_community: Array<ModBanFromCommunity>;
335   banned: Array<ModBan>;
336   added_to_community: Array<ModAddCommunity>;
337   added: Array<ModAdd>;
338 }
339
340 export interface ModRemovePost {
341   id: number;
342   mod_user_id: number;
343   post_id: number;
344   reason?: string;
345   removed?: boolean;
346   when_: string;
347   mod_user_name: string;
348   post_name: string;
349   community_id: number;
350   community_name: string;
351 }
352
353 export interface ModLockPost {
354   id: number;
355   mod_user_id: number;
356   post_id: number;
357   locked?: boolean;
358   when_: string;
359   mod_user_name: string;
360   post_name: string;
361   community_id: number;
362   community_name: string;
363 }
364
365 export interface ModStickyPost {
366   id: number;
367   mod_user_id: number;
368   post_id: number;
369   stickied?: boolean;
370   when_: string;
371   mod_user_name: string;
372   post_name: string;
373   community_id: number;
374   community_name: string;
375 }
376
377 export interface ModRemoveComment {
378   id: number;
379   mod_user_id: number;
380   comment_id: number;
381   reason?: string;
382   removed?: boolean;
383   when_: string;
384   mod_user_name: string;
385   comment_user_id: number;
386   comment_user_name: string;
387   comment_content: string;
388   post_id: number;
389   post_name: string;
390   community_id: number;
391   community_name: string;
392 }
393
394 export interface ModRemoveCommunity {
395   id: number;
396   mod_user_id: number;
397   community_id: number;
398   reason?: string;
399   removed?: boolean;
400   expires?: number;
401   when_: string;
402   mod_user_name: string;
403   community_name: string;
404 }
405
406 export interface ModBanFromCommunity {
407   id: number;
408   mod_user_id: number;
409   other_user_id: number;
410   community_id: number;
411   reason?: string;
412   banned?: boolean;
413   expires?: number;
414   when_: string;
415   mod_user_name: string;
416   other_user_name: string;
417   community_name: string;
418 }
419
420 export interface ModBan {
421   id: number;
422   mod_user_id: number;
423   other_user_id: number;
424   reason?: string;
425   banned?: boolean;
426   expires?: number;
427   when_: string;
428   mod_user_name: string;
429   other_user_name: string;
430 }
431
432 export interface ModAddCommunity {
433   id: number;
434   mod_user_id: number;
435   other_user_id: number;
436   community_id: number;
437   removed?: boolean;
438   when_: string;
439   mod_user_name: string;
440   other_user_name: string;
441   community_name: string;
442 }
443
444 export interface ModAdd {
445   id: number;
446   mod_user_id: number;
447   other_user_id: number;
448   removed?: boolean;
449   when_: string;
450   mod_user_name: string;
451   other_user_name: string;
452 }
453
454 export interface LoginForm {
455   username_or_email: string;
456   password: string;
457 }
458
459 export interface RegisterForm {
460   username: string;
461   email?: string;
462   password: string;
463   password_verify: string;
464   admin: boolean;
465   show_nsfw: boolean;
466 }
467
468 export interface LoginResponse {
469   jwt: string;
470 }
471
472 export interface UserSettingsForm {
473   show_nsfw: boolean;
474   theme: string;
475   default_sort_type: SortType;
476   default_listing_type: ListingType;
477   lang: string;
478   avatar?: string;
479   email?: string;
480   new_password?: string;
481   new_password_verify?: string;
482   old_password?: string;
483   show_avatars: boolean;
484   send_notifications_to_email: boolean;
485   auth: string;
486 }
487
488 export interface CommunityForm {
489   name: string;
490   title: string;
491   description?: string;
492   category_id: number;
493   edit_id?: number;
494   removed?: boolean;
495   deleted?: boolean;
496   nsfw: boolean;
497   reason?: string;
498   expires?: number;
499   auth?: string;
500 }
501
502 export interface GetCommunityResponse {
503   community: Community;
504   moderators: Array<CommunityUser>;
505   admins: Array<UserView>;
506 }
507
508 export interface CommunityResponse {
509   community: Community;
510 }
511
512 export interface ListCommunitiesForm {
513   sort: string;
514   page?: number;
515   limit?: number;
516   auth?: string;
517 }
518
519 export interface ListCommunitiesResponse {
520   communities: Array<Community>;
521 }
522
523 export interface ListCategoriesResponse {
524   categories: Array<Category>;
525 }
526
527 export interface PostForm {
528   name: string;
529   url?: string;
530   body?: string;
531   community_id: number;
532   updated?: number;
533   edit_id?: number;
534   creator_id: number;
535   removed?: boolean;
536   deleted?: boolean;
537   nsfw: boolean;
538   locked?: boolean;
539   stickied?: boolean;
540   reason?: string;
541   auth: string;
542 }
543
544 export interface PostFormParams {
545   name: string;
546   url?: string;
547   body?: string;
548   community?: string;
549 }
550
551 export interface GetPostResponse {
552   post: Post;
553   comments: Array<Comment>;
554   community: Community;
555   moderators: Array<CommunityUser>;
556   admins: Array<UserView>;
557 }
558
559 export interface SavePostForm {
560   post_id: number;
561   save: boolean;
562   auth?: string;
563 }
564
565 export interface PostResponse {
566   post: Post;
567 }
568
569 export interface CommentForm {
570   content: string;
571   post_id: number;
572   parent_id?: number;
573   edit_id?: number;
574   creator_id: number;
575   removed?: boolean;
576   deleted?: boolean;
577   reason?: string;
578   read?: boolean;
579   auth: string;
580 }
581
582 export interface SaveCommentForm {
583   comment_id: number;
584   save: boolean;
585   auth?: string;
586 }
587
588 export interface CommentResponse {
589   comment: Comment;
590 }
591
592 export interface CommentLikeForm {
593   comment_id: number;
594   post_id: number;
595   score: number;
596   auth?: string;
597 }
598
599 export interface CommentNode {
600   comment: Comment;
601   children?: Array<CommentNode>;
602 }
603
604 export interface GetPostsForm {
605   type_: string;
606   sort: string;
607   page?: number;
608   limit?: number;
609   community_id?: number;
610   auth?: string;
611 }
612
613 export interface GetPostsResponse {
614   posts: Array<Post>;
615 }
616
617 export interface CreatePostLikeForm {
618   post_id: number;
619   score: number;
620   auth?: string;
621 }
622
623 export interface CreatePostLikeResponse {
624   post: Post;
625 }
626
627 export interface SiteForm {
628   name: string;
629   description?: string;
630   enable_downvotes: boolean;
631   open_registration: boolean;
632   enable_nsfw: boolean;
633   auth?: string;
634 }
635
636 export interface GetSiteResponse {
637   site: Site;
638   admins: Array<UserView>;
639   banned: Array<UserView>;
640   online: number;
641 }
642
643 export interface SiteResponse {
644   site: Site;
645 }
646
647 export interface BanUserForm {
648   user_id: number;
649   ban: boolean;
650   reason?: string;
651   expires?: number;
652   auth?: string;
653 }
654
655 export interface BanUserResponse {
656   user: UserView;
657   banned: boolean;
658 }
659
660 export interface AddAdminForm {
661   user_id: number;
662   added: boolean;
663   auth?: string;
664 }
665
666 export interface AddAdminResponse {
667   admins: Array<UserView>;
668 }
669
670 export interface SearchForm {
671   q: string;
672   type_: string;
673   community_id?: number;
674   sort: string;
675   page?: number;
676   limit?: number;
677 }
678
679 export interface SearchResponse {
680   type_: string;
681   posts?: Array<Post>;
682   comments?: Array<Comment>;
683   communities: Array<Community>;
684   users: Array<UserView>;
685 }
686
687 export interface DeleteAccountForm {
688   password: string;
689 }
690
691 export interface PasswordResetForm {
692   email: string;
693 }
694
695 // export interface PasswordResetResponse {
696 // }
697
698 export interface PasswordChangeForm {
699   token: string;
700   password: string;
701   password_verify: string;
702 }
703
704 type ResponseType =
705   | SiteResponse
706   | GetFollowedCommunitiesResponse
707   | ListCommunitiesResponse
708   | GetPostsResponse
709   | CreatePostLikeResponse
710   | GetRepliesResponse
711   | GetUserMentionsResponse
712   | ListCategoriesResponse
713   | CommunityResponse
714   | CommentResponse
715   | UserMentionResponse
716   | LoginResponse
717   | GetModlogResponse
718   | SearchResponse
719   | BanFromCommunityResponse
720   | AddModToCommunityResponse
721   | BanUserResponse
722   | AddAdminResponse;
723
724 export interface WebSocketResponse {
725   op: UserOperation;
726   data: ResponseType;
727   error?: string;
728 }
729
730 export interface WebSocketJsonResponse {
731   op: string;
732   data: ResponseType;
733   error?: string;
734 }