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