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