summaryrefslogtreecommitdiffstats
path: root/ui/src
diff options
context:
space:
mode:
authorDessalines <tyhou13@gmx.com>2019-08-23 19:40:41 -0700
committerDessalines <tyhou13@gmx.com>2019-08-23 19:40:41 -0700
commit3561ef93a08742c74f36609754b87f2cd4a84e1c (patch)
treed6a1a5a6823bfee68a3e6bbbea9031f597bdb79b /ui/src
parentd5b9ba724dbab8ac1b17ca52d3f85309e5f22497 (diff)
Adding Community and Site transfer
- Fixes #139
Diffstat (limited to 'ui/src')
-rw-r--r--ui/src/components/comment-node.tsx45
-rw-r--r--ui/src/components/post.tsx13
-rw-r--r--ui/src/interfaces.ts13
-rw-r--r--ui/src/services/WebSocketService.ts12
-rw-r--r--ui/src/translations/en.ts2
5 files changed, 81 insertions, 4 deletions
diff --git a/ui/src/components/comment-node.tsx b/ui/src/components/comment-node.tsx
index 610252ea..f518da90 100644
--- a/ui/src/components/comment-node.tsx
+++ b/ui/src/components/comment-node.tsx
@@ -1,6 +1,6 @@
import { Component, linkEvent } from 'inferno';
import { Link } from 'inferno-router';
-import { CommentNode as CommentNodeI, CommentLikeForm, CommentForm as CommentFormI, SaveCommentForm, BanFromCommunityForm, BanUserForm, CommunityUser, UserView, AddModToCommunityForm, AddAdminForm } from '../interfaces';
+import { CommentNode as CommentNodeI, CommentLikeForm, CommentForm as CommentFormI, SaveCommentForm, BanFromCommunityForm, BanUserForm, CommunityUser, UserView, AddModToCommunityForm, AddAdminForm, TransferCommunityForm, TransferSiteForm } from '../interfaces';
import { WebSocketService, UserService } from '../services';
import { mdToHtml, getUnixTime, canMod, isMod } from '../utils';
import * as moment from 'moment';
@@ -148,6 +148,12 @@ export class CommentNode extends Component<CommentNodeProps, CommentNodeState> {
}
</>
}
+ {/* Community creators can transfer community to another mod */}
+ {this.amCommunityCreator && this.isMod &&
+ <li className="list-inline-item">
+ <span class="pointer" onClick={linkEvent(this, this.handleTransferCommunity)}><T i18nKey="transfer_community">#</T></span>
+ </li>
+ }
{/* Admins can ban from all, and appoint other admins */}
{this.canAdmin &&
<>
@@ -166,6 +172,12 @@ export class CommentNode extends Component<CommentNodeProps, CommentNodeState> {
}
</>
}
+ {/* Site Creator can transfer to another admin */}
+ {this.amSiteCreator && this.isAdmin &&
+ <li className="list-inline-item">
+ <span class="pointer" onClick={linkEvent(this, this.handleTransferSite)}><T i18nKey="transfer_site">#</T></span>
+ </li>
+ }
</>
}
<li className="list-inline-item">
@@ -251,6 +263,20 @@ export class CommentNode extends Component<CommentNodeProps, CommentNodeState> {
return this.props.admins && canMod(UserService.Instance.user, this.props.admins.map(a => a.id), this.props.node.comment.creator_id);
}
+ get amCommunityCreator(): boolean {
+ return this.props.moderators &&
+ UserService.Instance.user &&
+ (this.props.node.comment.creator_id != UserService.Instance.user.id) &&
+ (UserService.Instance.user.id == this.props.moderators[0].user_id);
+ }
+
+ get amSiteCreator(): boolean {
+ return this.props.admins &&
+ UserService.Instance.user &&
+ (this.props.node.comment.creator_id != UserService.Instance.user.id) &&
+ (UserService.Instance.user.id == this.props.admins[0].id);
+ }
+
handleReplyClick(i: CommentNode) {
i.state.showReply = true;
i.setState(i.state);
@@ -431,6 +457,23 @@ export class CommentNode extends Component<CommentNodeProps, CommentNodeState> {
i.setState(i.state);
}
+ handleTransferCommunity(i: CommentNode) {
+ let form: TransferCommunityForm = {
+ community_id: i.props.node.comment.community_id,
+ user_id: i.props.node.comment.creator_id,
+ };
+ WebSocketService.Instance.transferCommunity(form);
+ i.setState(i.state);
+ }
+
+ handleTransferSite(i: CommentNode) {
+ let form: TransferSiteForm = {
+ user_id: i.props.node.comment.creator_id,
+ };
+ WebSocketService.Instance.transferSite(form);
+ i.setState(i.state);
+ }
+
get isCommentNew(): boolean {
let now = moment.utc().subtract(10, 'minutes');
let then = moment.utc(this.props.node.comment.published);
diff --git a/ui/src/components/post.tsx b/ui/src/components/post.tsx
index ab82ca4f..a6df4105 100644
--- a/ui/src/components/post.tsx
+++ b/ui/src/components/post.tsx
@@ -1,7 +1,7 @@
import { Component, linkEvent } from 'inferno';
import { Subscription } from "rxjs";
import { retryWhen, delay, take } from 'rxjs/operators';
-import { UserOperation, Community, Post as PostI, GetPostResponse, PostResponse, Comment, CommentForm as CommentFormI, CommentResponse, CommentSortType, CreatePostLikeResponse, CommunityUser, CommunityResponse, CommentNode as CommentNodeI, BanFromCommunityResponse, BanUserResponse, AddModToCommunityResponse, AddAdminResponse, UserView, SearchType, SortType, SearchForm, SearchResponse } from '../interfaces';
+import { UserOperation, Community, Post as PostI, GetPostResponse, PostResponse, Comment, CommentForm as CommentFormI, CommentResponse, CommentSortType, CreatePostLikeResponse, CommunityUser, CommunityResponse, CommentNode as CommentNodeI, BanFromCommunityResponse, BanUserResponse, AddModToCommunityResponse, AddAdminResponse, UserView, SearchType, SortType, SearchForm, SearchResponse, GetSiteResponse, GetCommunityResponse } from '../interfaces';
import { WebSocketService, UserService } from '../services';
import { msgOp, hotRank } from '../utils';
import { PostListing } from './post-listing';
@@ -370,6 +370,17 @@ export class Post extends Component<any, PostState> {
let res: SearchResponse = msg;
this.state.crossPosts = res.posts.filter(p => p.id != this.state.post.id);
this.setState(this.state);
+ } else if (op == UserOperation.TransferSite) {
+ let res: GetSiteResponse = msg;
+
+ this.state.admins = res.admins;
+ this.setState(this.state);
+ } else if (op == UserOperation.TransferCommunity) {
+ let res: GetCommunityResponse = msg;
+ this.state.community = res.community;
+ this.state.moderators = res.moderators;
+ this.state.admins = res.admins;
+ this.setState(this.state);
}
}
diff --git a/ui/src/interfaces.ts b/ui/src/interfaces.ts
index 0a3daf66..251b64a0 100644
--- a/ui/src/interfaces.ts
+++ b/ui/src/interfaces.ts
@@ -1,5 +1,5 @@
export enum UserOperation {
- Login, Register, CreateCommunity, CreatePost, ListCommunities, ListCategories, GetPost, GetCommunity, CreateComment, EditComment, SaveComment, CreateCommentLike, GetPosts, CreatePostLike, EditPost, SavePost, EditCommunity, FollowCommunity, GetFollowedCommunities, GetUserDetails, GetReplies, GetModlog, BanFromCommunity, AddModToCommunity, CreateSite, EditSite, GetSite, AddAdmin, BanUser, Search, MarkAllAsRead, SaveUserSettings
+ Login, Register, CreateCommunity, CreatePost, ListCommunities, ListCategories, GetPost, GetCommunity, CreateComment, EditComment, SaveComment, CreateCommentLike, GetPosts, CreatePostLike, EditPost, SavePost, EditCommunity, FollowCommunity, GetFollowedCommunities, GetUserDetails, GetReplies, GetModlog, BanFromCommunity, AddModToCommunity, CreateSite, EditSite, GetSite, AddAdmin, BanUser, Search, MarkAllAsRead, SaveUserSettings, TransferCommunity, TransferSite
}
export enum CommentSortType {
@@ -202,6 +202,17 @@ export interface AddModToCommunityForm {
auth?: string;
}
+export interface TransferCommunityForm {
+ community_id: number;
+ user_id: number;
+ auth?: string;
+}
+
+export interface TransferSiteForm {
+ user_id: number;
+ auth?: string;
+}
+
export interface AddModToCommunityResponse {
op: string;
moderators: Array<CommunityUser>;
diff --git a/ui/src/services/WebSocketService.ts b/ui/src/services/WebSocketService.ts
index c34b6b3c..f67dbf6d 100644
--- a/ui/src/services/WebSocketService.ts
+++ b/ui/src/services/WebSocketService.ts
@@ -1,5 +1,5 @@
import { wsUri } from '../env';
-import { LoginForm, RegisterForm, UserOperation, CommunityForm, PostForm, SavePostForm, CommentForm, SaveCommentForm, CommentLikeForm, GetPostsForm, CreatePostLikeForm, FollowCommunityForm, GetUserDetailsForm, ListCommunitiesForm, GetModlogForm, BanFromCommunityForm, AddModToCommunityForm, AddAdminForm, BanUserForm, SiteForm, Site, UserView, GetRepliesForm, SearchForm, UserSettingsForm } from '../interfaces';
+import { LoginForm, RegisterForm, UserOperation, CommunityForm, PostForm, SavePostForm, CommentForm, SaveCommentForm, CommentLikeForm, GetPostsForm, CreatePostLikeForm, FollowCommunityForm, GetUserDetailsForm, ListCommunitiesForm, GetModlogForm, BanFromCommunityForm, AddModToCommunityForm, TransferCommunityForm, AddAdminForm, TransferSiteForm, BanUserForm, SiteForm, Site, UserView, GetRepliesForm, SearchForm, UserSettingsForm } from '../interfaces';
import { webSocket } from 'rxjs/webSocket';
import { Subject } from 'rxjs';
import { retryWhen, delay, take } from 'rxjs/operators';
@@ -136,6 +136,16 @@ export class WebSocketService {
this.subject.next(this.wsSendWrapper(UserOperation.AddModToCommunity, form));
}
+ public transferCommunity(form: TransferCommunityForm) {
+ this.setAuth(form);
+ this.subject.next(this.wsSendWrapper(UserOperation.TransferCommunity, form));
+ }
+
+ public transferSite(form: TransferSiteForm) {
+ this.setAuth(form);
+ this.subject.next(this.wsSendWrapper(UserOperation.TransferSite, form));
+ }
+
public banUser(form: BanUserForm) {
this.setAuth(form);
this.subject.next(this.wsSendWrapper(UserOperation.BanUser, form));
diff --git a/ui/src/translations/en.ts b/ui/src/translations/en.ts
index ff38a84b..c854ea7b 100644
--- a/ui/src/translations/en.ts
+++ b/ui/src/translations/en.ts
@@ -130,6 +130,8 @@ export const en = {
joined: 'Joined',
by: 'by',
to: 'to',
+ transfer_community: 'transfer community',
+ transfer_site: 'transfer site',
powered_by: 'Powered by',
landing_0: 'Lemmy is a <1>link aggregator</1> / reddit alternative, intended to work in the <2>fediverse</2>.<3></3>It\'s self-hostable, has live-updating comment threads, and is tiny (<4>~80kB</4>). Federation into the ActivityPub network is on the roadmap. <5></5>This is a <6>very early beta version</6>, and a lot of features are currently broken or missing. <7></7>Suggest new features or report bugs <8>here.</8><9></9>Made with <10>Rust</10>, <11>Actix</11>, <12>Inferno</12>, <13>Typescript</13>.',
not_logged_in: 'Not logged in.',