]> 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   online: number;
543 }
544
545 export interface CommunityResponse {
546   community: Community;
547 }
548
549 export interface ListCommunitiesForm {
550   sort: string;
551   page?: number;
552   limit?: number;
553   auth?: string;
554 }
555
556 export interface ListCommunitiesResponse {
557   communities: Array<Community>;
558 }
559
560 export interface ListCategoriesResponse {
561   categories: Array<Category>;
562 }
563
564 export interface PostForm {
565   name: string;
566   url?: string;
567   body?: string;
568   community_id: number;
569   updated?: number;
570   edit_id?: number;
571   creator_id: number;
572   removed?: boolean;
573   deleted?: boolean;
574   nsfw: boolean;
575   locked?: boolean;
576   stickied?: boolean;
577   reason?: string;
578   auth: string;
579 }
580
581 export interface PostFormParams {
582   name: string;
583   url?: string;
584   body?: string;
585   community?: string;
586 }
587
588 export interface GetPostForm {
589   id: number;
590   auth?: string;
591 }
592
593 export interface GetPostResponse {
594   post: Post;
595   comments: Array<Comment>;
596   community: Community;
597   moderators: Array<CommunityUser>;
598   admins: Array<UserView>;
599   online: number;
600 }
601
602 export interface SavePostForm {
603   post_id: number;
604   save: boolean;
605   auth?: string;
606 }
607
608 export interface PostResponse {
609   post: Post;
610 }
611
612 export interface CommentForm {
613   content: string;
614   post_id: number;
615   parent_id?: number;
616   edit_id?: number;
617   creator_id: number;
618   removed?: boolean;
619   deleted?: boolean;
620   reason?: string;
621   read?: boolean;
622   auth: string;
623 }
624
625 export interface SaveCommentForm {
626   comment_id: number;
627   save: boolean;
628   auth?: string;
629 }
630
631 export interface CommentResponse {
632   comment: Comment;
633   recipient_ids: Array<number>;
634 }
635
636 export interface CommentLikeForm {
637   comment_id: number;
638   post_id: number;
639   score: number;
640   auth?: string;
641 }
642
643 export interface CommentNode {
644   comment: Comment;
645   children?: Array<CommentNode>;
646 }
647
648 export interface GetPostsForm {
649   type_: string;
650   sort: string;
651   page?: number;
652   limit?: number;
653   community_id?: number;
654   auth?: string;
655 }
656
657 export interface GetPostsResponse {
658   posts: Array<Post>;
659 }
660
661 export interface CreatePostLikeForm {
662   post_id: number;
663   score: number;
664   auth?: string;
665 }
666
667 export interface SiteForm {
668   name: string;
669   description?: string;
670   enable_downvotes: boolean;
671   open_registration: boolean;
672   enable_nsfw: boolean;
673   auth?: string;
674 }
675
676 export interface GetSiteResponse {
677   site: Site;
678   admins: Array<UserView>;
679   banned: Array<UserView>;
680   online: number;
681 }
682
683 export interface SiteResponse {
684   site: Site;
685 }
686
687 export interface BanUserForm {
688   user_id: number;
689   ban: boolean;
690   reason?: string;
691   expires?: number;
692   auth?: string;
693 }
694
695 export interface BanUserResponse {
696   user: UserView;
697   banned: boolean;
698 }
699
700 export interface AddAdminForm {
701   user_id: number;
702   added: boolean;
703   auth?: string;
704 }
705
706 export interface AddAdminResponse {
707   admins: Array<UserView>;
708 }
709
710 export interface SearchForm {
711   q: string;
712   type_: string;
713   community_id?: number;
714   sort: string;
715   page?: number;
716   limit?: number;
717   auth?: string;
718 }
719
720 export interface SearchResponse {
721   type_: string;
722   posts?: Array<Post>;
723   comments?: Array<Comment>;
724   communities: Array<Community>;
725   users: Array<UserView>;
726 }
727
728 export interface DeleteAccountForm {
729   password: string;
730 }
731
732 export interface PasswordResetForm {
733   email: string;
734 }
735
736 // export interface PasswordResetResponse {
737 // }
738
739 export interface PasswordChangeForm {
740   token: string;
741   password: string;
742   password_verify: string;
743 }
744
745 export interface PrivateMessageForm {
746   content: string;
747   recipient_id: number;
748   auth?: string;
749 }
750
751 export interface PrivateMessageFormParams {
752   recipient_id: number;
753 }
754
755 export interface EditPrivateMessageForm {
756   edit_id: number;
757   content?: string;
758   deleted?: boolean;
759   read?: boolean;
760   auth?: string;
761 }
762
763 export interface GetPrivateMessagesForm {
764   unread_only: boolean;
765   page?: number;
766   limit?: number;
767   auth?: string;
768 }
769
770 export interface PrivateMessagesResponse {
771   messages: Array<PrivateMessage>;
772 }
773
774 export interface PrivateMessageResponse {
775   message: PrivateMessage;
776 }
777
778 export interface UserJoinForm {
779   auth: string;
780 }
781
782 export interface UserJoinResponse {
783   user_id: number;
784 }
785
786 export type MessageType =
787   | EditPrivateMessageForm
788   | LoginForm
789   | RegisterForm
790   | CommunityForm
791   | FollowCommunityForm
792   | ListCommunitiesForm
793   | GetFollowedCommunitiesForm
794   | PostForm
795   | GetPostForm
796   | GetPostsForm
797   | GetCommunityForm
798   | CommentForm
799   | CommentLikeForm
800   | SaveCommentForm
801   | CreatePostLikeForm
802   | BanFromCommunityForm
803   | AddAdminForm
804   | AddModToCommunityForm
805   | TransferCommunityForm
806   | TransferSiteForm
807   | SaveCommentForm
808   | BanUserForm
809   | AddAdminForm
810   | GetUserDetailsForm
811   | GetRepliesForm
812   | GetUserMentionsForm
813   | EditUserMentionForm
814   | GetModlogForm
815   | SiteForm
816   | SearchForm
817   | UserSettingsForm
818   | DeleteAccountForm
819   | PasswordResetForm
820   | PasswordChangeForm
821   | PrivateMessageForm
822   | EditPrivateMessageForm
823   | GetPrivateMessagesForm;
824
825 type ResponseType =
826   | SiteResponse
827   | GetFollowedCommunitiesResponse
828   | ListCommunitiesResponse
829   | GetPostsResponse
830   | PostResponse
831   | GetRepliesResponse
832   | GetUserMentionsResponse
833   | ListCategoriesResponse
834   | CommunityResponse
835   | CommentResponse
836   | UserMentionResponse
837   | LoginResponse
838   | GetModlogResponse
839   | SearchResponse
840   | BanFromCommunityResponse
841   | AddModToCommunityResponse
842   | BanUserResponse
843   | AddAdminResponse
844   | PrivateMessageResponse
845   | PrivateMessagesResponse;
846
847 export interface WebSocketResponse {
848   op: UserOperation;
849   data: ResponseType;
850 }
851
852 export interface WebSocketJsonResponse {
853   op?: string;
854   data?: ResponseType;
855   error?: string;
856 }