]> Untitled Git - lemmy.git/blob - ui/src/interfaces.ts
Merge branch 'dev' 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   creator_name: string;
277   creator_avatar?: string;
278   recipient_name: string;
279   recipient_avatar?: string;
280 }
281
282 export enum BanType {
283   Community,
284   Site,
285 }
286
287 export interface FollowCommunityForm {
288   community_id: number;
289   follow: boolean;
290   auth?: string;
291 }
292
293 export interface GetFollowedCommunitiesForm {
294   auth: string;
295 }
296
297 export interface GetFollowedCommunitiesResponse {
298   communities: Array<CommunityUser>;
299 }
300
301 export interface GetUserDetailsForm {
302   user_id?: number;
303   username?: string;
304   sort: string;
305   page?: number;
306   limit?: number;
307   community_id?: number;
308   saved_only: boolean;
309 }
310
311 export interface UserDetailsResponse {
312   user: UserView;
313   follows: Array<CommunityUser>;
314   moderates: Array<CommunityUser>;
315   comments: Array<Comment>;
316   posts: Array<Post>;
317   admins: Array<UserView>;
318 }
319
320 export interface GetRepliesForm {
321   sort: string;
322   page?: number;
323   limit?: number;
324   unread_only: boolean;
325   auth?: string;
326 }
327
328 export interface GetRepliesResponse {
329   replies: Array<Comment>;
330 }
331
332 export interface GetUserMentionsForm {
333   sort: string;
334   page?: number;
335   limit?: number;
336   unread_only: boolean;
337   auth?: string;
338 }
339
340 export interface GetUserMentionsResponse {
341   mentions: Array<Comment>;
342 }
343
344 export interface EditUserMentionForm {
345   user_mention_id: number;
346   read?: boolean;
347   auth?: string;
348 }
349
350 export interface UserMentionResponse {
351   mention: Comment;
352 }
353
354 export interface BanFromCommunityForm {
355   community_id: number;
356   user_id: number;
357   ban: boolean;
358   reason?: string;
359   expires?: number;
360   auth?: string;
361 }
362
363 export interface BanFromCommunityResponse {
364   user: UserView;
365   banned: boolean;
366 }
367
368 export interface AddModToCommunityForm {
369   community_id: number;
370   user_id: number;
371   added: boolean;
372   auth?: string;
373 }
374
375 export interface TransferCommunityForm {
376   community_id: number;
377   user_id: number;
378   auth?: string;
379 }
380
381 export interface TransferSiteForm {
382   user_id: number;
383   auth?: string;
384 }
385
386 export interface AddModToCommunityResponse {
387   moderators: Array<CommunityUser>;
388 }
389
390 export interface GetModlogForm {
391   mod_user_id?: number;
392   community_id?: number;
393   page?: number;
394   limit?: number;
395 }
396
397 export interface GetModlogResponse {
398   removed_posts: Array<ModRemovePost>;
399   locked_posts: Array<ModLockPost>;
400   stickied_posts: Array<ModStickyPost>;
401   removed_comments: Array<ModRemoveComment>;
402   removed_communities: Array<ModRemoveCommunity>;
403   banned_from_community: Array<ModBanFromCommunity>;
404   banned: Array<ModBan>;
405   added_to_community: Array<ModAddCommunity>;
406   added: Array<ModAdd>;
407 }
408
409 export interface ModRemovePost {
410   id: number;
411   mod_user_id: number;
412   post_id: number;
413   reason?: string;
414   removed?: boolean;
415   when_: string;
416   mod_user_name: string;
417   post_name: string;
418   community_id: number;
419   community_name: string;
420 }
421
422 export interface ModLockPost {
423   id: number;
424   mod_user_id: number;
425   post_id: number;
426   locked?: boolean;
427   when_: string;
428   mod_user_name: string;
429   post_name: string;
430   community_id: number;
431   community_name: string;
432 }
433
434 export interface ModStickyPost {
435   id: number;
436   mod_user_id: number;
437   post_id: number;
438   stickied?: boolean;
439   when_: string;
440   mod_user_name: string;
441   post_name: string;
442   community_id: number;
443   community_name: string;
444 }
445
446 export interface ModRemoveComment {
447   id: number;
448   mod_user_id: number;
449   comment_id: number;
450   reason?: string;
451   removed?: boolean;
452   when_: string;
453   mod_user_name: string;
454   comment_user_id: number;
455   comment_user_name: string;
456   comment_content: string;
457   post_id: number;
458   post_name: string;
459   community_id: number;
460   community_name: string;
461 }
462
463 export interface ModRemoveCommunity {
464   id: number;
465   mod_user_id: number;
466   community_id: number;
467   reason?: string;
468   removed?: boolean;
469   expires?: number;
470   when_: string;
471   mod_user_name: string;
472   community_name: string;
473 }
474
475 export interface ModBanFromCommunity {
476   id: number;
477   mod_user_id: number;
478   other_user_id: number;
479   community_id: number;
480   reason?: string;
481   banned?: boolean;
482   expires?: number;
483   when_: string;
484   mod_user_name: string;
485   other_user_name: string;
486   community_name: string;
487 }
488
489 export interface ModBan {
490   id: number;
491   mod_user_id: number;
492   other_user_id: number;
493   reason?: string;
494   banned?: boolean;
495   expires?: number;
496   when_: string;
497   mod_user_name: string;
498   other_user_name: string;
499 }
500
501 export interface ModAddCommunity {
502   id: number;
503   mod_user_id: number;
504   other_user_id: number;
505   community_id: number;
506   removed?: boolean;
507   when_: string;
508   mod_user_name: string;
509   other_user_name: string;
510   community_name: string;
511 }
512
513 export interface ModAdd {
514   id: number;
515   mod_user_id: number;
516   other_user_id: number;
517   removed?: boolean;
518   when_: string;
519   mod_user_name: string;
520   other_user_name: string;
521 }
522
523 export interface LoginForm {
524   username_or_email: string;
525   password: string;
526 }
527
528 export interface RegisterForm {
529   username: string;
530   email?: string;
531   password: string;
532   password_verify: string;
533   admin: boolean;
534   show_nsfw: boolean;
535 }
536
537 export interface LoginResponse {
538   jwt: string;
539 }
540
541 export interface UserSettingsForm {
542   show_nsfw: boolean;
543   theme: string;
544   default_sort_type: SortType;
545   default_listing_type: ListingType;
546   lang: string;
547   avatar?: string;
548   email?: string;
549   matrix_user_id?: string;
550   new_password?: string;
551   new_password_verify?: string;
552   old_password?: string;
553   show_avatars: boolean;
554   send_notifications_to_email: boolean;
555   auth: string;
556 }
557
558 export interface CommunityForm {
559   name: string;
560   title: string;
561   description?: string;
562   category_id: number;
563   edit_id?: number;
564   removed?: boolean;
565   deleted?: boolean;
566   nsfw: boolean;
567   reason?: string;
568   expires?: number;
569   auth?: string;
570 }
571
572 export interface GetCommunityForm {
573   id?: number;
574   name?: string;
575   auth?: string;
576 }
577
578 export interface GetCommunityResponse {
579   community: Community;
580   moderators: Array<CommunityUser>;
581   admins: Array<UserView>;
582   online: number;
583 }
584
585 export interface CommunityResponse {
586   community: Community;
587 }
588
589 export interface ListCommunitiesForm {
590   sort: string;
591   page?: number;
592   limit?: number;
593   auth?: string;
594 }
595
596 export interface ListCommunitiesResponse {
597   communities: Array<Community>;
598 }
599
600 export interface ListCategoriesResponse {
601   categories: Array<Category>;
602 }
603
604 export interface PostForm {
605   name: string;
606   url?: string;
607   body?: string;
608   community_id: number;
609   updated?: number;
610   edit_id?: number;
611   creator_id: number;
612   removed?: boolean;
613   deleted?: boolean;
614   nsfw: boolean;
615   locked?: boolean;
616   stickied?: boolean;
617   reason?: string;
618   auth: string;
619 }
620
621 export interface PostFormParams {
622   name: string;
623   url?: string;
624   body?: string;
625   community?: string;
626 }
627
628 export interface GetPostForm {
629   id: number;
630   auth?: string;
631 }
632
633 export interface GetPostResponse {
634   post: Post;
635   comments: Array<Comment>;
636   community: Community;
637   moderators: Array<CommunityUser>;
638   admins: Array<UserView>;
639   online: number;
640 }
641
642 export interface SavePostForm {
643   post_id: number;
644   save: boolean;
645   auth?: string;
646 }
647
648 export interface PostResponse {
649   post: Post;
650 }
651
652 export interface CommentForm {
653   content: string;
654   post_id: number;
655   parent_id?: number;
656   edit_id?: number;
657   creator_id: number;
658   removed?: boolean;
659   deleted?: boolean;
660   reason?: string;
661   read?: boolean;
662   auth: string;
663 }
664
665 export interface SaveCommentForm {
666   comment_id: number;
667   save: boolean;
668   auth?: string;
669 }
670
671 export interface CommentResponse {
672   comment: Comment;
673   recipient_ids: Array<number>;
674 }
675
676 export interface CommentLikeForm {
677   comment_id: number;
678   post_id: number;
679   score: number;
680   auth?: string;
681 }
682
683 export interface CommentNode {
684   comment: Comment;
685   children?: Array<CommentNode>;
686 }
687
688 export interface GetPostsForm {
689   type_: string;
690   sort: string;
691   page?: number;
692   limit?: number;
693   community_id?: number;
694   auth?: string;
695 }
696
697 export interface GetPostsResponse {
698   posts: Array<Post>;
699 }
700
701 export interface GetCommentsForm {
702   type_: string;
703   sort: string;
704   page?: number;
705   limit: number;
706   community_id?: number;
707   auth?: string;
708 }
709
710 export interface GetCommentsResponse {
711   comments: Array<Comment>;
712 }
713
714 export interface CreatePostLikeForm {
715   post_id: number;
716   score: number;
717   auth?: string;
718 }
719
720 export interface SiteForm {
721   name: string;
722   description?: string;
723   enable_downvotes: boolean;
724   open_registration: boolean;
725   enable_nsfw: boolean;
726   auth?: string;
727 }
728
729 export interface GetSiteConfig {
730   auth?: string;
731 }
732
733 export interface GetSiteConfigResponse {
734   config_hjson: string;
735 }
736
737 export interface SiteConfigForm {
738   config_hjson: string;
739   auth?: string;
740 }
741
742 export interface GetSiteResponse {
743   site: Site;
744   admins: Array<UserView>;
745   banned: Array<UserView>;
746   online: number;
747 }
748
749 export interface SiteResponse {
750   site: Site;
751 }
752
753 export interface BanUserForm {
754   user_id: number;
755   ban: boolean;
756   reason?: string;
757   expires?: number;
758   auth?: string;
759 }
760
761 export interface BanUserResponse {
762   user: UserView;
763   banned: boolean;
764 }
765
766 export interface AddAdminForm {
767   user_id: number;
768   added: boolean;
769   auth?: string;
770 }
771
772 export interface AddAdminResponse {
773   admins: Array<UserView>;
774 }
775
776 export interface SearchForm {
777   q: string;
778   type_: string;
779   community_id?: number;
780   sort: string;
781   page?: number;
782   limit?: number;
783   auth?: string;
784 }
785
786 export interface SearchResponse {
787   type_: string;
788   posts?: Array<Post>;
789   comments?: Array<Comment>;
790   communities: Array<Community>;
791   users: Array<UserView>;
792 }
793
794 export interface DeleteAccountForm {
795   password: string;
796 }
797
798 export interface PasswordResetForm {
799   email: string;
800 }
801
802 // export interface PasswordResetResponse {
803 // }
804
805 export interface PasswordChangeForm {
806   token: string;
807   password: string;
808   password_verify: string;
809 }
810
811 export interface PrivateMessageForm {
812   content: string;
813   recipient_id: number;
814   auth?: string;
815 }
816
817 export interface PrivateMessageFormParams {
818   recipient_id: number;
819 }
820
821 export interface EditPrivateMessageForm {
822   edit_id: number;
823   content?: string;
824   deleted?: boolean;
825   read?: boolean;
826   auth?: string;
827 }
828
829 export interface GetPrivateMessagesForm {
830   unread_only: boolean;
831   page?: number;
832   limit?: number;
833   auth?: string;
834 }
835
836 export interface PrivateMessagesResponse {
837   messages: Array<PrivateMessage>;
838 }
839
840 export interface PrivateMessageResponse {
841   message: PrivateMessage;
842 }
843
844 export interface UserJoinForm {
845   auth: string;
846 }
847
848 export interface UserJoinResponse {
849   user_id: number;
850 }
851
852 export type MessageType =
853   | EditPrivateMessageForm
854   | LoginForm
855   | RegisterForm
856   | CommunityForm
857   | FollowCommunityForm
858   | ListCommunitiesForm
859   | GetFollowedCommunitiesForm
860   | PostForm
861   | GetPostForm
862   | GetPostsForm
863   | GetCommunityForm
864   | CommentForm
865   | CommentLikeForm
866   | SaveCommentForm
867   | CreatePostLikeForm
868   | BanFromCommunityForm
869   | AddAdminForm
870   | AddModToCommunityForm
871   | TransferCommunityForm
872   | TransferSiteForm
873   | SaveCommentForm
874   | BanUserForm
875   | AddAdminForm
876   | GetUserDetailsForm
877   | GetRepliesForm
878   | GetUserMentionsForm
879   | EditUserMentionForm
880   | GetModlogForm
881   | SiteForm
882   | SearchForm
883   | UserSettingsForm
884   | DeleteAccountForm
885   | PasswordResetForm
886   | PasswordChangeForm
887   | PrivateMessageForm
888   | EditPrivateMessageForm
889   | GetPrivateMessagesForm
890   | SiteConfigForm;
891
892 type ResponseType =
893   | SiteResponse
894   | GetFollowedCommunitiesResponse
895   | ListCommunitiesResponse
896   | GetPostsResponse
897   | PostResponse
898   | GetRepliesResponse
899   | GetUserMentionsResponse
900   | ListCategoriesResponse
901   | CommunityResponse
902   | CommentResponse
903   | UserMentionResponse
904   | LoginResponse
905   | GetModlogResponse
906   | SearchResponse
907   | BanFromCommunityResponse
908   | AddModToCommunityResponse
909   | BanUserResponse
910   | AddAdminResponse
911   | PrivateMessageResponse
912   | PrivateMessagesResponse
913   | GetSiteConfigResponse;
914
915 export interface WebSocketResponse {
916   op: UserOperation;
917   data: ResponseType;
918 }
919
920 export interface WebSocketJsonResponse {
921   op?: string;
922   data?: ResponseType;
923   error?: string;
924   reconnect?: boolean;
925 }