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