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