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