parent
0ceb168044
commit
5bcb509a82
4 changed files with 81 additions and 15 deletions
|
@ -1311,14 +1311,17 @@ impl Perform for EditComment {
|
||||||
return Err(self.error("Not allowed to edit comment."))?
|
return Err(self.error("Not allowed to edit comment."))?
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for a community ban
|
// You are allowed to mark the comment as read even if you're banned.
|
||||||
if CommunityUserBanView::get(&conn, user_id, orig_comment.community_id).is_ok() {
|
if self.read.is_none() {
|
||||||
return Err(self.error("You have been banned from this community"))?
|
// Check for a community ban
|
||||||
}
|
if CommunityUserBanView::get(&conn, user_id, orig_comment.community_id).is_ok() {
|
||||||
|
return Err(self.error("You have been banned from this community"))?
|
||||||
|
}
|
||||||
|
|
||||||
// Check for a site ban
|
// Check for a site ban
|
||||||
if UserView::read(&conn, user_id)?.banned {
|
if UserView::read(&conn, user_id)?.banned {
|
||||||
return Err(self.error("You have been banned from the site"))?
|
return Err(self.error("You have been banned from the site"))?
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let content_slurs_removed = remove_slurs(&self.content.to_owned());
|
let content_slurs_removed = remove_slurs(&self.content.to_owned());
|
||||||
|
|
|
@ -220,10 +220,15 @@ export class CommentNode extends Component<CommentNodeProps, CommentNodeState> {
|
||||||
}
|
}
|
||||||
|
|
||||||
get canMod(): boolean {
|
get canMod(): boolean {
|
||||||
let adminsThenMods = this.props.admins.map(a => a.id)
|
|
||||||
.concat(this.props.moderators.map(m => m.user_id));
|
|
||||||
|
|
||||||
return canMod(UserService.Instance.user, adminsThenMods, this.props.node.comment.creator_id);
|
if (this.props.admins && this.props.moderators) {
|
||||||
|
let adminsThenMods = this.props.admins.map(a => a.id)
|
||||||
|
.concat(this.props.moderators.map(m => m.user_id));
|
||||||
|
|
||||||
|
return canMod(UserService.Instance.user, adminsThenMods, this.props.node.comment.creator_id);
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
get canAdmin(): boolean {
|
get canAdmin(): boolean {
|
||||||
|
|
|
@ -94,7 +94,7 @@ export class Inbox extends Component<any, InboxState> {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
{this.state.replies.map(reply =>
|
{this.state.replies.map(reply =>
|
||||||
<CommentNodes nodes={[{comment: reply}]} noIndent viewOnly markable />
|
<CommentNodes nodes={[{comment: reply}]} noIndent markable />
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
@ -161,6 +161,14 @@ export class Inbox extends Component<any, InboxState> {
|
||||||
} else if (op == UserOperation.EditComment) {
|
} else if (op == UserOperation.EditComment) {
|
||||||
let res: CommentResponse = msg;
|
let res: CommentResponse = msg;
|
||||||
|
|
||||||
|
let found = this.state.replies.find(c => c.id == res.comment.id);
|
||||||
|
found.content = res.comment.content;
|
||||||
|
found.updated = res.comment.updated;
|
||||||
|
found.removed = res.comment.removed;
|
||||||
|
found.upvotes = res.comment.upvotes;
|
||||||
|
found.downvotes = res.comment.downvotes;
|
||||||
|
found.score = res.comment.score;
|
||||||
|
|
||||||
// If youre in the unread view, just remove it from the list
|
// If youre in the unread view, just remove it from the list
|
||||||
if (this.state.unreadType == UnreadType.Unread && res.comment.read) {
|
if (this.state.unreadType == UnreadType.Unread && res.comment.read) {
|
||||||
this.state.replies = this.state.replies.filter(r => r.id !== res.comment.id);
|
this.state.replies = this.state.replies.filter(r => r.id !== res.comment.id);
|
||||||
|
@ -168,8 +176,27 @@ export class Inbox extends Component<any, InboxState> {
|
||||||
let found = this.state.replies.find(c => c.id == res.comment.id);
|
let found = this.state.replies.find(c => c.id == res.comment.id);
|
||||||
found.read = res.comment.read;
|
found.read = res.comment.read;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.sendRepliesCount();
|
this.sendRepliesCount();
|
||||||
|
|
||||||
|
this.setState(this.state);
|
||||||
|
} else if (op == UserOperation.CreateComment) {
|
||||||
|
// let res: CommentResponse = msg;
|
||||||
|
alert('Reply sent');
|
||||||
|
// this.state.replies.unshift(res.comment); // TODO do this right
|
||||||
|
// this.setState(this.state);
|
||||||
|
} else if (op == UserOperation.SaveComment) {
|
||||||
|
let res: CommentResponse = msg;
|
||||||
|
let found = this.state.replies.find(c => c.id == res.comment.id);
|
||||||
|
found.saved = res.comment.saved;
|
||||||
|
this.setState(this.state);
|
||||||
|
} else if (op == UserOperation.CreateCommentLike) {
|
||||||
|
let res: CommentResponse = msg;
|
||||||
|
let found: Comment = this.state.replies.find(c => c.id === res.comment.id);
|
||||||
|
found.score = res.comment.score;
|
||||||
|
found.upvotes = res.comment.upvotes;
|
||||||
|
found.downvotes = res.comment.downvotes;
|
||||||
|
if (res.comment.my_vote !== null)
|
||||||
|
found.my_vote = res.comment.my_vote;
|
||||||
this.setState(this.state);
|
this.setState(this.state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { Component, linkEvent } from 'inferno';
|
||||||
import { Link } from 'inferno-router';
|
import { Link } from 'inferno-router';
|
||||||
import { Subscription } from "rxjs";
|
import { Subscription } from "rxjs";
|
||||||
import { retryWhen, delay, take } from 'rxjs/operators';
|
import { retryWhen, delay, take } from 'rxjs/operators';
|
||||||
import { UserOperation, Post, Comment, CommunityUser, GetUserDetailsForm, SortType, UserDetailsResponse, UserView } from '../interfaces';
|
import { UserOperation, Post, Comment, CommunityUser, GetUserDetailsForm, SortType, UserDetailsResponse, UserView, CommentResponse } from '../interfaces';
|
||||||
import { WebSocketService } from '../services';
|
import { WebSocketService } from '../services';
|
||||||
import { msgOp, fetchLimit } from '../utils';
|
import { msgOp, fetchLimit } from '../utils';
|
||||||
import { PostListing } from './post-listing';
|
import { PostListing } from './post-listing';
|
||||||
|
@ -148,7 +148,7 @@ export class User extends Component<any, UserState> {
|
||||||
<div>
|
<div>
|
||||||
{i.type_ == "posts"
|
{i.type_ == "posts"
|
||||||
? <PostListing post={i.data as Post} showCommunity viewOnly />
|
? <PostListing post={i.data as Post} showCommunity viewOnly />
|
||||||
: <CommentNodes nodes={[{comment: i.data as Comment}]} noIndent viewOnly />
|
: <CommentNodes nodes={[{comment: i.data as Comment}]} noIndent />
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
@ -296,6 +296,37 @@ export class User extends Component<any, UserState> {
|
||||||
this.state.posts = res.posts;
|
this.state.posts = res.posts;
|
||||||
document.title = `/u/${this.state.user.name} - Lemmy`;
|
document.title = `/u/${this.state.user.name} - Lemmy`;
|
||||||
this.setState(this.state);
|
this.setState(this.state);
|
||||||
|
} else if (op == UserOperation.EditComment) {
|
||||||
|
let res: CommentResponse = msg;
|
||||||
|
|
||||||
|
let found = this.state.comments.find(c => c.id == res.comment.id);
|
||||||
|
found.content = res.comment.content;
|
||||||
|
found.updated = res.comment.updated;
|
||||||
|
found.removed = res.comment.removed;
|
||||||
|
found.upvotes = res.comment.upvotes;
|
||||||
|
found.downvotes = res.comment.downvotes;
|
||||||
|
found.score = res.comment.score;
|
||||||
|
|
||||||
|
this.setState(this.state);
|
||||||
|
} else if (op == UserOperation.CreateComment) {
|
||||||
|
// let res: CommentResponse = msg;
|
||||||
|
alert('Reply sent');
|
||||||
|
// this.state.comments.unshift(res.comment); // TODO do this right
|
||||||
|
// this.setState(this.state);
|
||||||
|
} else if (op == UserOperation.SaveComment) {
|
||||||
|
let res: CommentResponse = msg;
|
||||||
|
let found = this.state.comments.find(c => c.id == res.comment.id);
|
||||||
|
found.saved = res.comment.saved;
|
||||||
|
this.setState(this.state);
|
||||||
|
} else if (op == UserOperation.CreateCommentLike) {
|
||||||
|
let res: CommentResponse = msg;
|
||||||
|
let found: Comment = this.state.comments.find(c => c.id === res.comment.id);
|
||||||
|
found.score = res.comment.score;
|
||||||
|
found.upvotes = res.comment.upvotes;
|
||||||
|
found.downvotes = res.comment.downvotes;
|
||||||
|
if (res.comment.my_vote !== null)
|
||||||
|
found.my_vote = res.comment.my_vote;
|
||||||
|
this.setState(this.state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue