]> Untitled Git - lemmy.git/blob - ui/src/interfaces.ts
Starting to work on 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 }
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 GetFollowedCommunitiesResponse {
253   communities: Array<CommunityUser>;
254 }
255
256 export interface GetUserDetailsForm {
257   user_id?: number;
258   username?: string;
259   sort: string;
260   page?: number;
261   limit?: number;
262   community_id?: number;
263   saved_only: boolean;
264 }
265
266 export interface UserDetailsResponse {
267   user: UserView;
268   follows: Array<CommunityUser>;
269   moderates: Array<CommunityUser>;
270   comments: Array<Comment>;
271   posts: Array<Post>;
272   admins: Array<UserView>;
273 }
274
275 export interface GetRepliesForm {
276   sort: string;
277   page?: number;
278   limit?: number;
279   unread_only: boolean;
280   auth?: string;
281 }
282
283 export interface GetRepliesResponse {
284   replies: Array<Comment>;
285 }
286
287 export interface GetUserMentionsForm {
288   sort: string;
289   page?: number;
290   limit?: number;
291   unread_only: boolean;
292   auth?: string;
293 }
294
295 export interface GetUserMentionsResponse {
296   mentions: Array<Comment>;
297 }
298
299 export interface EditUserMentionForm {
300   user_mention_id: number;
301   read?: boolean;
302   auth?: string;
303 }
304
305 export interface UserMentionResponse {
306   mention: Comment;
307 }
308
309 export interface BanFromCommunityForm {
310   community_id: number;
311   user_id: number;
312   ban: boolean;
313   reason?: string;
314   expires?: number;
315   auth?: string;
316 }
317
318 export interface BanFromCommunityResponse {
319   user: UserView;
320   banned: boolean;
321 }
322
323 export interface AddModToCommunityForm {
324   community_id: number;
325   user_id: number;
326   added: boolean;
327   auth?: string;
328 }
329
330 export interface TransferCommunityForm {
331   community_id: number;
332   user_id: number;
333   auth?: string;
334 }
335
336 export interface TransferSiteForm {
337   user_id: number;
338   auth?: string;
339 }
340
341 export interface AddModToCommunityResponse {
342   moderators: Array<CommunityUser>;
343 }
344
345 export interface GetModlogForm {
346   mod_user_id?: number;
347   community_id?: number;
348   page?: number;
349   limit?: number;
350 }
351
352 export interface GetModlogResponse {
353   removed_posts: Array<ModRemovePost>;
354   locked_posts: Array<ModLockPost>;
355   stickied_posts: Array<ModStickyPost>;
356   removed_comments: Array<ModRemoveComment>;
357   removed_communities: Array<ModRemoveCommunity>;
358   banned_from_community: Array<ModBanFromCommunity>;
359   banned: Array<ModBan>;
360   added_to_community: Array<ModAddCommunity>;
361   added: Array<ModAdd>;
362 }
363
364 export interface ModRemovePost {
365   id: number;
366   mod_user_id: number;
367   post_id: number;
368   reason?: string;
369   removed?: boolean;
370   when_: string;
371   mod_user_name: string;
372   post_name: string;
373   community_id: number;
374   community_name: string;
375 }
376
377 export interface ModLockPost {
378   id: number;
379   mod_user_id: number;
380   post_id: number;
381   locked?: boolean;
382   when_: string;
383   mod_user_name: string;
384   post_name: string;
385   community_id: number;
386   community_name: string;
387 }
388
389 export interface ModStickyPost {
390   id: number;
391   mod_user_id: number;
392   post_id: number;
393   stickied?: boolean;
394   when_: string;
395   mod_user_name: string;
396   post_name: string;
397   community_id: number;
398   community_name: string;
399 }
400
401 export interface ModRemoveComment {
402   id: number;
403   mod_user_id: number;
404   comment_id: number;
405   reason?: string;
406   removed?: boolean;
407   when_: string;
408   mod_user_name: string;
409   comment_user_id: number;
410   comment_user_name: string;
411   comment_content: string;
412   post_id: number;
413   post_name: string;
414   community_id: number;
415   community_name: string;
416 }
417
418 export interface ModRemoveCommunity {
419   id: number;
420   mod_user_id: number;
421   community_id: number;
422   reason?: string;
423   removed?: boolean;
424   expires?: number;
425   when_: string;
426   mod_user_name: string;
427   community_name: string;
428 }
429
430 export interface ModBanFromCommunity {
431   id: number;
432   mod_user_id: number;
433   other_user_id: number;
434   community_id: number;
435   reason?: string;
436   banned?: boolean;
437   expires?: number;
438   when_: string;
439   mod_user_name: string;
440   other_user_name: string;
441   community_name: string;
442 }
443
444 export interface ModBan {
445   id: number;
446   mod_user_id: number;
447   other_user_id: number;
448   reason?: string;
449   banned?: boolean;
450   expires?: number;
451   when_: string;
452   mod_user_name: string;
453   other_user_name: string;
454 }
455
456 export interface ModAddCommunity {
457   id: number;
458   mod_user_id: number;
459   other_user_id: number;
460   community_id: number;
461   removed?: boolean;
462   when_: string;
463   mod_user_name: string;
464   other_user_name: string;
465   community_name: string;
466 }
467
468 export interface ModAdd {
469   id: number;
470   mod_user_id: number;
471   other_user_id: number;
472   removed?: boolean;
473   when_: string;
474   mod_user_name: string;
475   other_user_name: string;
476 }
477
478 export interface LoginForm {
479   username_or_email: string;
480   password: string;
481 }
482
483 export interface RegisterForm {
484   username: string;
485   email?: string;
486   password: string;
487   password_verify: string;
488   admin: boolean;
489   show_nsfw: boolean;
490 }
491
492 export interface LoginResponse {
493   jwt: string;
494 }
495
496 export interface UserSettingsForm {
497   show_nsfw: boolean;
498   theme: string;
499   default_sort_type: SortType;
500   default_listing_type: ListingType;
501   lang: string;
502   avatar?: string;
503   email?: string;
504   matrix_user_id?: string;
505   new_password?: string;
506   new_password_verify?: string;
507   old_password?: string;
508   show_avatars: boolean;
509   send_notifications_to_email: boolean;
510   auth: string;
511 }
512
513 export interface CommunityForm {
514   name: string;
515   title: string;
516   description?: string;
517   category_id: number;
518   edit_id?: number;
519   removed?: boolean;
520   deleted?: boolean;
521   nsfw: boolean;
522   reason?: string;
523   expires?: number;
524   auth?: string;
525 }
526
527 export interface GetCommunityResponse {
528   community: Community;
529   moderators: Array<CommunityUser>;
530   admins: Array<UserView>;
531 }
532
533 export interface CommunityResponse {
534   community: Community;
535 }
536
537 export interface ListCommunitiesForm {
538   sort: string;
539   page?: number;
540   limit?: number;
541   auth?: string;
542 }
543
544 export interface ListCommunitiesResponse {
545   communities: Array<Community>;
546 }
547
548 export interface ListCategoriesResponse {
549   categories: Array<Category>;
550 }
551
552 export interface PostForm {
553   name: string;
554   url?: string;
555   body?: string;
556   community_id: number;
557   updated?: number;
558   edit_id?: number;
559   creator_id: number;
560   removed?: boolean;
561   deleted?: boolean;
562   nsfw: boolean;
563   locked?: boolean;
564   stickied?: boolean;
565   reason?: string;
566   auth: string;
567 }
568
569 export interface PostFormParams {
570   name: string;
571   url?: string;
572   body?: string;
573   community?: string;
574 }
575
576 export interface GetPostResponse {
577   post: Post;
578   comments: Array<Comment>;
579   community: Community;
580   moderators: Array<CommunityUser>;
581   admins: Array<UserView>;
582 }
583
584 export interface SavePostForm {
585   post_id: number;
586   save: boolean;
587   auth?: string;
588 }
589
590 export interface PostResponse {
591   post: Post;
592 }
593
594 export interface CommentForm {
595   content: string;
596   post_id: number;
597   parent_id?: number;
598   edit_id?: number;
599   creator_id: number;
600   removed?: boolean;
601   deleted?: boolean;
602   reason?: string;
603   read?: boolean;
604   auth: string;
605 }
606
607 export interface SaveCommentForm {
608   comment_id: number;
609   save: boolean;
610   auth?: string;
611 }
612
613 export interface CommentResponse {
614   comment: Comment;
615 }
616
617 export interface CommentLikeForm {
618   comment_id: number;
619   post_id: number;
620   score: number;
621   auth?: string;
622 }
623
624 export interface CommentNode {
625   comment: Comment;
626   children?: Array<CommentNode>;
627 }
628
629 export interface GetPostsForm {
630   type_: string;
631   sort: string;
632   page?: number;
633   limit?: number;
634   community_id?: number;
635   auth?: string;
636 }
637
638 export interface GetPostsResponse {
639   posts: Array<Post>;
640 }
641
642 export interface CreatePostLikeForm {
643   post_id: number;
644   score: number;
645   auth?: string;
646 }
647
648 export interface CreatePostLikeResponse {
649   post: Post;
650 }
651
652 export interface SiteForm {
653   name: string;
654   description?: string;
655   enable_downvotes: boolean;
656   open_registration: boolean;
657   enable_nsfw: boolean;
658   auth?: string;
659 }
660
661 export interface GetSiteResponse {
662   site: Site;
663   admins: Array<UserView>;
664   banned: Array<UserView>;
665   online: number;
666 }
667
668 export interface SiteResponse {
669   site: Site;
670 }
671
672 export interface BanUserForm {
673   user_id: number;
674   ban: boolean;
675   reason?: string;
676   expires?: number;
677   auth?: string;
678 }
679
680 export interface BanUserResponse {
681   user: UserView;
682   banned: boolean;
683 }
684
685 export interface AddAdminForm {
686   user_id: number;
687   added: boolean;
688   auth?: string;
689 }
690
691 export interface AddAdminResponse {
692   admins: Array<UserView>;
693 }
694
695 export interface SearchForm {
696   q: string;
697   type_: string;
698   community_id?: number;
699   sort: string;
700   page?: number;
701   limit?: number;
702   auth?: string;
703 }
704
705 export interface SearchResponse {
706   type_: string;
707   posts?: Array<Post>;
708   comments?: Array<Comment>;
709   communities: Array<Community>;
710   users: Array<UserView>;
711 }
712
713 export interface DeleteAccountForm {
714   password: string;
715 }
716
717 export interface PasswordResetForm {
718   email: string;
719 }
720
721 // export interface PasswordResetResponse {
722 // }
723
724 export interface PasswordChangeForm {
725   token: string;
726   password: string;
727   password_verify: string;
728 }
729
730 export interface PrivateMessageForm {
731   content: string;
732   recipient_id: number;
733   auth?: string;
734 }
735
736 export interface PrivateMessageFormParams {
737   recipient_id: number;
738 }
739
740 export interface EditPrivateMessageForm {
741   edit_id: number;
742   content?: string;
743   deleted?: boolean;
744   read?: boolean;
745   auth?: string;
746 }
747
748 export interface GetPrivateMessagesForm {
749   unread_only: boolean;
750   page?: number;
751   limit?: number;
752   auth?: string;
753 }
754
755 export interface PrivateMessagesResponse {
756   messages: Array<PrivateMessage>;
757 }
758
759 export interface PrivateMessageResponse {
760   message: PrivateMessage;
761 }
762
763 type ResponseType =
764   | SiteResponse
765   | GetFollowedCommunitiesResponse
766   | ListCommunitiesResponse
767   | GetPostsResponse
768   | CreatePostLikeResponse
769   | GetRepliesResponse
770   | GetUserMentionsResponse
771   | ListCategoriesResponse
772   | CommunityResponse
773   | CommentResponse
774   | UserMentionResponse
775   | LoginResponse
776   | GetModlogResponse
777   | SearchResponse
778   | BanFromCommunityResponse
779   | AddModToCommunityResponse
780   | BanUserResponse
781   | AddAdminResponse
782   | PrivateMessageResponse
783   | PrivateMessagesResponse;
784
785 export interface WebSocketResponse {
786   op: UserOperation;
787   data: ResponseType;
788 }
789
790 export interface WebSocketJsonResponse {
791   op?: string;
792   data?: ResponseType;
793   error?: string;
794 }