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