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