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