]> Untitled Git - lemmy.git/blob - ui/src/interfaces.ts
Merge branch 'StaticallyTypedRice-webclient' of https://github.com/StaticallyTypedRic...
[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   CreatePrivateMessage,
42   EditPrivateMessage,
43   GetPrivateMessages,
44   UserJoin,
45 }
46
47 export enum CommentSortType {
48   Hot,
49   Top,
50   New,
51   Old,
52 }
53
54 export enum ListingType {
55   All,
56   Subscribed,
57   Community,
58 }
59
60 export enum SortType {
61   Hot,
62   New,
63   TopDay,
64   TopWeek,
65   TopMonth,
66   TopYear,
67   TopAll,
68 }
69
70 export enum SearchType {
71   All,
72   Comments,
73   Posts,
74   Communities,
75   Users,
76   Url,
77 }
78
79 export interface User {
80   id: number;
81   iss: string;
82   username: string;
83   show_nsfw: boolean;
84   theme: string;
85   default_sort_type: SortType;
86   default_listing_type: ListingType;
87   lang: string;
88   avatar?: string;
89   show_avatars: boolean;
90 }
91
92 export interface UserView {
93   id: number;
94   name: string;
95   avatar?: string;
96   email?: string;
97   matrix_user_id?: string;
98   fedi_name: string;
99   published: string;
100   number_of_posts: number;
101   post_score: number;
102   number_of_comments: number;
103   comment_score: number;
104   banned: boolean;
105   show_avatars: boolean;
106   send_notifications_to_email: boolean;
107 }
108
109 export interface CommunityUser {
110   id: number;
111   user_id: number;
112   user_name: string;
113   avatar?: string;
114   community_id: number;
115   community_name: string;
116   published: string;
117 }
118
119 export interface Community {
120   id: number;
121   name: string;
122   title: string;
123   description?: string;
124   category_id: number;
125   creator_id: number;
126   removed: boolean;
127   deleted: boolean;
128   nsfw: boolean;
129   published: string;
130   updated?: string;
131   creator_name: string;
132   creator_avatar?: string;
133   category_name: string;
134   number_of_subscribers: number;
135   number_of_posts: number;
136   number_of_comments: number;
137   user_id?: number;
138   subscribed?: boolean;
139 }
140
141 export interface Post {
142   id: number;
143   name: string;
144   url?: string;
145   body?: string;
146   creator_id: number;
147   community_id: number;
148   removed: boolean;
149   deleted: boolean;
150   locked: boolean;
151   stickied: boolean;
152   nsfw: boolean;
153   banned: boolean;
154   banned_from_community: boolean;
155   published: string;
156   updated?: string;
157   creator_name: string;
158   creator_avatar?: string;
159   community_name: string;
160   community_removed: boolean;
161   community_deleted: boolean;
162   community_nsfw: boolean;
163   number_of_comments: number;
164   score: number;
165   upvotes: number;
166   downvotes: number;
167   hot_rank: number;
168   user_id?: number;
169   my_vote?: number;
170   subscribed?: boolean;
171   read?: boolean;
172   saved?: boolean;
173   upvoteLoading?: boolean;
174   downvoteLoading?: boolean;
175   duplicates?: Array<Post>;
176 }
177
178 export interface Comment {
179   id: number;
180   creator_id: number;
181   post_id: number;
182   parent_id?: number;
183   content: string;
184   removed: boolean;
185   deleted: boolean;
186   read: boolean;
187   published: string;
188   updated?: string;
189   community_id: number;
190   banned: boolean;
191   banned_from_community: boolean;
192   creator_name: string;
193   creator_avatar?: string;
194   score: number;
195   upvotes: number;
196   downvotes: number;
197   user_id?: number;
198   my_vote?: number;
199   saved?: boolean;
200   user_mention_id?: number; // For mention type
201   recipient_id?: number;
202   upvoteLoading?: boolean;
203   downvoteLoading?: boolean;
204 }
205
206 export interface Category {
207   id: number;
208   name: string;
209 }
210
211 export interface Site {
212   id: number;
213   name: string;
214   description?: string;
215   creator_id: number;
216   published: string;
217   updated?: string;
218   creator_name: string;
219   number_of_users: number;
220   number_of_posts: number;
221   number_of_comments: number;
222   number_of_communities: number;
223   enable_downvotes: boolean;
224   open_registration: boolean;
225   enable_nsfw: boolean;
226 }
227
228 export interface PrivateMessage {
229   id: number;
230   creator_id: number;
231   recipient_id: number;
232   content: string;
233   deleted: boolean;
234   read: boolean;
235   published: string;
236   updated?: string;
237   creator_name: string;
238   creator_avatar?: string;
239   recipient_name: string;
240   recipient_avatar?: string;
241 }
242
243 export enum BanType {
244   Community,
245   Site,
246 }
247
248 export interface FollowCommunityForm {
249   community_id: number;
250   follow: boolean;
251   auth?: string;
252 }
253
254 export interface GetFollowedCommunitiesForm {
255   auth: string;
256 }
257
258 export interface GetFollowedCommunitiesResponse {
259   communities: Array<CommunityUser>;
260 }
261
262 export interface GetUserDetailsForm {
263   user_id?: number;
264   username?: string;
265   sort: string;
266   page?: number;
267   limit?: number;
268   community_id?: number;
269   saved_only: boolean;
270 }
271
272 export interface UserDetailsResponse {
273   user: UserView;
274   follows: Array<CommunityUser>;
275   moderates: Array<CommunityUser>;
276   comments: Array<Comment>;
277   posts: Array<Post>;
278   admins: Array<UserView>;
279 }
280
281 export interface GetRepliesForm {
282   sort: string;
283   page?: number;
284   limit?: number;
285   unread_only: boolean;
286   auth?: string;
287 }
288
289 export interface GetRepliesResponse {
290   replies: Array<Comment>;
291 }
292
293 export interface GetUserMentionsForm {
294   sort: string;
295   page?: number;
296   limit?: number;
297   unread_only: boolean;
298   auth?: string;
299 }
300
301 export interface GetUserMentionsResponse {
302   mentions: Array<Comment>;
303 }
304
305 export interface EditUserMentionForm {
306   user_mention_id: number;
307   read?: boolean;
308   auth?: string;
309 }
310
311 export interface UserMentionResponse {
312   mention: Comment;
313 }
314
315 export interface BanFromCommunityForm {
316   community_id: number;
317   user_id: number;
318   ban: boolean;
319   reason?: string;
320   expires?: number;
321   auth?: string;
322 }
323
324 export interface BanFromCommunityResponse {
325   user: UserView;
326   banned: boolean;
327 }
328
329 export interface AddModToCommunityForm {
330   community_id: number;
331   user_id: number;
332   added: boolean;
333   auth?: string;
334 }
335
336 export interface TransferCommunityForm {
337   community_id: number;
338   user_id: number;
339   auth?: string;
340 }
341
342 export interface TransferSiteForm {
343   user_id: number;
344   auth?: string;
345 }
346
347 export interface AddModToCommunityResponse {
348   moderators: Array<CommunityUser>;
349 }
350
351 export interface GetModlogForm {
352   mod_user_id?: number;
353   community_id?: number;
354   page?: number;
355   limit?: number;
356 }
357
358 export interface GetModlogResponse {
359   removed_posts: Array<ModRemovePost>;
360   locked_posts: Array<ModLockPost>;
361   stickied_posts: Array<ModStickyPost>;
362   removed_comments: Array<ModRemoveComment>;
363   removed_communities: Array<ModRemoveCommunity>;
364   banned_from_community: Array<ModBanFromCommunity>;
365   banned: Array<ModBan>;
366   added_to_community: Array<ModAddCommunity>;
367   added: Array<ModAdd>;
368 }
369
370 export interface ModRemovePost {
371   id: number;
372   mod_user_id: number;
373   post_id: number;
374   reason?: string;
375   removed?: boolean;
376   when_: string;
377   mod_user_name: string;
378   post_name: string;
379   community_id: number;
380   community_name: string;
381 }
382
383 export interface ModLockPost {
384   id: number;
385   mod_user_id: number;
386   post_id: number;
387   locked?: boolean;
388   when_: string;
389   mod_user_name: string;
390   post_name: string;
391   community_id: number;
392   community_name: string;
393 }
394
395 export interface ModStickyPost {
396   id: number;
397   mod_user_id: number;
398   post_id: number;
399   stickied?: boolean;
400   when_: string;
401   mod_user_name: string;
402   post_name: string;
403   community_id: number;
404   community_name: string;
405 }
406
407 export interface ModRemoveComment {
408   id: number;
409   mod_user_id: number;
410   comment_id: number;
411   reason?: string;
412   removed?: boolean;
413   when_: string;
414   mod_user_name: string;
415   comment_user_id: number;
416   comment_user_name: string;
417   comment_content: string;
418   post_id: number;
419   post_name: string;
420   community_id: number;
421   community_name: string;
422 }
423
424 export interface ModRemoveCommunity {
425   id: number;
426   mod_user_id: number;
427   community_id: number;
428   reason?: string;
429   removed?: boolean;
430   expires?: number;
431   when_: string;
432   mod_user_name: string;
433   community_name: string;
434 }
435
436 export interface ModBanFromCommunity {
437   id: number;
438   mod_user_id: number;
439   other_user_id: number;
440   community_id: number;
441   reason?: string;
442   banned?: boolean;
443   expires?: number;
444   when_: string;
445   mod_user_name: string;
446   other_user_name: string;
447   community_name: string;
448 }
449
450 export interface ModBan {
451   id: number;
452   mod_user_id: number;
453   other_user_id: number;
454   reason?: string;
455   banned?: boolean;
456   expires?: number;
457   when_: string;
458   mod_user_name: string;
459   other_user_name: string;
460 }
461
462 export interface ModAddCommunity {
463   id: number;
464   mod_user_id: number;
465   other_user_id: number;
466   community_id: number;
467   removed?: boolean;
468   when_: string;
469   mod_user_name: string;
470   other_user_name: string;
471   community_name: string;
472 }
473
474 export interface ModAdd {
475   id: number;
476   mod_user_id: number;
477   other_user_id: number;
478   removed?: boolean;
479   when_: string;
480   mod_user_name: string;
481   other_user_name: string;
482 }
483
484 export interface LoginForm {
485   username_or_email: string;
486   password: string;
487 }
488
489 export interface RegisterForm {
490   username: string;
491   email?: string;
492   password: string;
493   password_verify: string;
494   admin: boolean;
495   show_nsfw: boolean;
496 }
497
498 export interface LoginResponse {
499   jwt: string;
500 }
501
502 export interface UserSettingsForm {
503   show_nsfw: boolean;
504   theme: string;
505   default_sort_type: SortType;
506   default_listing_type: ListingType;
507   lang: string;
508   avatar?: string;
509   email?: string;
510   matrix_user_id?: string;
511   new_password?: string;
512   new_password_verify?: string;
513   old_password?: string;
514   show_avatars: boolean;
515   send_notifications_to_email: boolean;
516   auth: string;
517 }
518
519 export interface CommunityForm {
520   name: string;
521   title: string;
522   description?: string;
523   category_id: number;
524   edit_id?: number;
525   removed?: boolean;
526   deleted?: boolean;
527   nsfw: boolean;
528   reason?: string;
529   expires?: number;
530   auth?: string;
531 }
532
533 export interface GetCommunityForm {
534   id?: number;
535   name?: string;
536   auth?: string;
537 }
538
539 export interface GetCommunityResponse {
540   community: Community;
541   moderators: Array<CommunityUser>;
542   admins: Array<UserView>;
543   online: number;
544 }
545
546 export interface CommunityResponse {
547   community: Community;
548 }
549
550 export interface ListCommunitiesForm {
551   sort: string;
552   page?: number;
553   limit?: number;
554   auth?: string;
555 }
556
557 export interface ListCommunitiesResponse {
558   communities: Array<Community>;
559 }
560
561 export interface ListCategoriesResponse {
562   categories: Array<Category>;
563 }
564
565 export interface PostForm {
566   name: string;
567   url?: string;
568   body?: string;
569   community_id: number;
570   updated?: number;
571   edit_id?: number;
572   creator_id: number;
573   removed?: boolean;
574   deleted?: boolean;
575   nsfw: boolean;
576   locked?: boolean;
577   stickied?: boolean;
578   reason?: string;
579   auth: string;
580 }
581
582 export interface PostFormParams {
583   name: string;
584   url?: string;
585   body?: string;
586   community?: string;
587 }
588
589 export interface GetPostForm {
590   id: number;
591   auth?: string;
592 }
593
594 export interface GetPostResponse {
595   post: Post;
596   comments: Array<Comment>;
597   community: Community;
598   moderators: Array<CommunityUser>;
599   admins: Array<UserView>;
600   online: number;
601 }
602
603 export interface SavePostForm {
604   post_id: number;
605   save: boolean;
606   auth?: string;
607 }
608
609 export interface PostResponse {
610   post: Post;
611 }
612
613 export interface CommentForm {
614   content: string;
615   post_id: number;
616   parent_id?: number;
617   edit_id?: number;
618   creator_id: number;
619   removed?: boolean;
620   deleted?: boolean;
621   reason?: string;
622   read?: boolean;
623   auth: string;
624 }
625
626 export interface SaveCommentForm {
627   comment_id: number;
628   save: boolean;
629   auth?: string;
630 }
631
632 export interface CommentResponse {
633   comment: Comment;
634   recipient_ids: Array<number>;
635 }
636
637 export interface CommentLikeForm {
638   comment_id: number;
639   post_id: number;
640   score: number;
641   auth?: string;
642 }
643
644 export interface CommentNode {
645   comment: Comment;
646   children?: Array<CommentNode>;
647 }
648
649 export interface GetPostsForm {
650   type_: string;
651   sort: string;
652   page?: number;
653   limit?: number;
654   community_id?: number;
655   auth?: string;
656 }
657
658 export interface GetPostsResponse {
659   posts: Array<Post>;
660 }
661
662 export interface CreatePostLikeForm {
663   post_id: number;
664   score: number;
665   auth?: string;
666 }
667
668 export interface SiteForm {
669   name: string;
670   description?: string;
671   enable_downvotes: boolean;
672   open_registration: boolean;
673   enable_nsfw: boolean;
674   auth?: string;
675 }
676
677 export interface GetSiteResponse {
678   site: Site;
679   admins: Array<UserView>;
680   banned: Array<UserView>;
681   online: number;
682 }
683
684 export interface SiteResponse {
685   site: Site;
686 }
687
688 export interface BanUserForm {
689   user_id: number;
690   ban: boolean;
691   reason?: string;
692   expires?: number;
693   auth?: string;
694 }
695
696 export interface BanUserResponse {
697   user: UserView;
698   banned: boolean;
699 }
700
701 export interface AddAdminForm {
702   user_id: number;
703   added: boolean;
704   auth?: string;
705 }
706
707 export interface AddAdminResponse {
708   admins: Array<UserView>;
709 }
710
711 export interface SearchForm {
712   q: string;
713   type_: string;
714   community_id?: number;
715   sort: string;
716   page?: number;
717   limit?: number;
718   auth?: string;
719 }
720
721 export interface SearchResponse {
722   type_: string;
723   posts?: Array<Post>;
724   comments?: Array<Comment>;
725   communities: Array<Community>;
726   users: Array<UserView>;
727 }
728
729 export interface DeleteAccountForm {
730   password: string;
731 }
732
733 export interface PasswordResetForm {
734   email: string;
735 }
736
737 // export interface PasswordResetResponse {
738 // }
739
740 export interface PasswordChangeForm {
741   token: string;
742   password: string;
743   password_verify: string;
744 }
745
746 export interface PrivateMessageForm {
747   content: string;
748   recipient_id: number;
749   auth?: string;
750 }
751
752 export interface PrivateMessageFormParams {
753   recipient_id: number;
754 }
755
756 export interface EditPrivateMessageForm {
757   edit_id: number;
758   content?: string;
759   deleted?: boolean;
760   read?: boolean;
761   auth?: string;
762 }
763
764 export interface GetPrivateMessagesForm {
765   unread_only: boolean;
766   page?: number;
767   limit?: number;
768   auth?: string;
769 }
770
771 export interface PrivateMessagesResponse {
772   messages: Array<PrivateMessage>;
773 }
774
775 export interface PrivateMessageResponse {
776   message: PrivateMessage;
777 }
778
779 export interface UserJoinForm {
780   auth: string;
781 }
782
783 export interface UserJoinResponse {
784   user_id: number;
785 }
786
787 export type MessageType =
788   | EditPrivateMessageForm
789   | LoginForm
790   | RegisterForm
791   | CommunityForm
792   | FollowCommunityForm
793   | ListCommunitiesForm
794   | GetFollowedCommunitiesForm
795   | PostForm
796   | GetPostForm
797   | GetPostsForm
798   | GetCommunityForm
799   | CommentForm
800   | CommentLikeForm
801   | SaveCommentForm
802   | CreatePostLikeForm
803   | BanFromCommunityForm
804   | AddAdminForm
805   | AddModToCommunityForm
806   | TransferCommunityForm
807   | TransferSiteForm
808   | SaveCommentForm
809   | BanUserForm
810   | AddAdminForm
811   | GetUserDetailsForm
812   | GetRepliesForm
813   | GetUserMentionsForm
814   | EditUserMentionForm
815   | GetModlogForm
816   | SiteForm
817   | SearchForm
818   | UserSettingsForm
819   | DeleteAccountForm
820   | PasswordResetForm
821   | PasswordChangeForm
822   | PrivateMessageForm
823   | EditPrivateMessageForm
824   | GetPrivateMessagesForm;
825
826 type ResponseType =
827   | SiteResponse
828   | GetFollowedCommunitiesResponse
829   | ListCommunitiesResponse
830   | GetPostsResponse
831   | PostResponse
832   | GetRepliesResponse
833   | GetUserMentionsResponse
834   | ListCategoriesResponse
835   | CommunityResponse
836   | CommentResponse
837   | UserMentionResponse
838   | LoginResponse
839   | GetModlogResponse
840   | SearchResponse
841   | BanFromCommunityResponse
842   | AddModToCommunityResponse
843   | BanUserResponse
844   | AddAdminResponse
845   | PrivateMessageResponse
846   | PrivateMessagesResponse;
847
848 export interface WebSocketResponse {
849   op: UserOperation;
850   data: ResponseType;
851 }
852
853 export interface WebSocketJsonResponse {
854   op?: string;
855   data?: ResponseType;
856   error?: string;
857 }