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