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