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