parent
d2187efa1d
commit
d350f57e00
3 changed files with 34 additions and 8 deletions
|
@ -162,7 +162,7 @@ export class CommentNode extends Component<CommentNodeProps, CommentNodeState> {
|
||||||
</>
|
</>
|
||||||
}
|
}
|
||||||
<li className="list-inline-item">
|
<li className="list-inline-item">
|
||||||
<Link className="text-muted" to={`/post/${node.comment.post_id}/comment/${node.comment.id}`} target="_blank">link</Link>
|
<Link className="text-muted" to={`/post/${node.comment.post_id}/comment/${node.comment.id}`}>link</Link>
|
||||||
</li>
|
</li>
|
||||||
{this.props.markable &&
|
{this.props.markable &&
|
||||||
<li className="list-inline-item">
|
<li className="list-inline-item">
|
||||||
|
|
|
@ -12,6 +12,7 @@ interface NavbarState {
|
||||||
expanded: boolean;
|
expanded: boolean;
|
||||||
expandUserDropdown: boolean;
|
expandUserDropdown: boolean;
|
||||||
replies: Array<Comment>,
|
replies: Array<Comment>,
|
||||||
|
fetchCount: number,
|
||||||
unreadCount: number;
|
unreadCount: number;
|
||||||
siteName: string;
|
siteName: string;
|
||||||
}
|
}
|
||||||
|
@ -22,6 +23,7 @@ export class Navbar extends Component<any, NavbarState> {
|
||||||
emptyState: NavbarState = {
|
emptyState: NavbarState = {
|
||||||
isLoggedIn: (UserService.Instance.user !== undefined),
|
isLoggedIn: (UserService.Instance.user !== undefined),
|
||||||
unreadCount: 0,
|
unreadCount: 0,
|
||||||
|
fetchCount: 0,
|
||||||
replies: [],
|
replies: [],
|
||||||
expanded: false,
|
expanded: false,
|
||||||
expandUserDropdown: false,
|
expandUserDropdown: false,
|
||||||
|
@ -158,12 +160,13 @@ export class Navbar extends Component<any, NavbarState> {
|
||||||
return;
|
return;
|
||||||
} else if (op == UserOperation.GetReplies) {
|
} else if (op == UserOperation.GetReplies) {
|
||||||
let res: GetRepliesResponse = msg;
|
let res: GetRepliesResponse = msg;
|
||||||
if (res.replies.length > 0 && this.state.replies.length > 0 &&
|
let unreadReplies = res.replies.filter(r => !r.read);
|
||||||
(JSON.stringify(this.state.replies) !== JSON.stringify(res.replies))) {
|
if (unreadReplies.length > 0 && this.state.fetchCount > 1 &&
|
||||||
this.notify(res.replies);
|
(JSON.stringify(this.state.replies) !== JSON.stringify(unreadReplies))) {
|
||||||
|
this.notify(unreadReplies);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.state.replies = res.replies;
|
this.state.replies = unreadReplies;
|
||||||
this.sendRepliesCount(res);
|
this.sendRepliesCount(res);
|
||||||
} else if (op == UserOperation.GetSite) {
|
} else if (op == UserOperation.GetSite) {
|
||||||
let res: GetSiteResponse = msg;
|
let res: GetSiteResponse = msg;
|
||||||
|
@ -190,6 +193,7 @@ export class Navbar extends Component<any, NavbarState> {
|
||||||
limit: 9999,
|
limit: 9999,
|
||||||
};
|
};
|
||||||
WebSocketService.Instance.getReplies(repliesForm);
|
WebSocketService.Instance.getReplies(repliesForm);
|
||||||
|
this.state.fetchCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -222,7 +226,7 @@ export class Navbar extends Component<any, NavbarState> {
|
||||||
else {
|
else {
|
||||||
var notification = new Notification(`${replies.length} Unread Messages`, {
|
var notification = new Notification(`${replies.length} Unread Messages`, {
|
||||||
icon: `${window.location.protocol}//${window.location.host}/static/assets/apple-touch-icon.png`,
|
icon: `${window.location.protocol}//${window.location.host}/static/assets/apple-touch-icon.png`,
|
||||||
body: recentReply.content
|
body: `${recentReply.creator_name}: ${recentReply.content}`
|
||||||
});
|
});
|
||||||
|
|
||||||
notification.onclick = () => {
|
notification.onclick = () => {
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import { Component, linkEvent } from 'inferno';
|
import { Component, linkEvent } from 'inferno';
|
||||||
import { Subscription } from "rxjs";
|
import { Subscription } from "rxjs";
|
||||||
import { retryWhen, delay, take } from 'rxjs/operators';
|
import { retryWhen, delay, take } from 'rxjs/operators';
|
||||||
import { UserOperation, Community, Post as PostI, GetPostResponse, PostResponse, Comment, CommentResponse, CommentSortType, CreatePostLikeResponse, CommunityUser, CommunityResponse, CommentNode as CommentNodeI, BanFromCommunityResponse, BanUserResponse, AddModToCommunityResponse, AddAdminResponse, UserView } 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 } from '../interfaces';
|
||||||
import { WebSocketService } from '../services';
|
import { WebSocketService, UserService } from '../services';
|
||||||
import { msgOp, hotRank } from '../utils';
|
import { msgOp, hotRank } from '../utils';
|
||||||
import { PostListing } from './post-listing';
|
import { PostListing } from './post-listing';
|
||||||
import { Sidebar } from './sidebar';
|
import { Sidebar } from './sidebar';
|
||||||
|
@ -71,6 +71,27 @@ export class Post extends Component<any, PostState> {
|
||||||
elmnt.scrollIntoView();
|
elmnt.scrollIntoView();
|
||||||
elmnt.classList.add("mark-two");
|
elmnt.classList.add("mark-two");
|
||||||
this.state.scrolled = true;
|
this.state.scrolled = true;
|
||||||
|
this.markScrolledAsRead(this.state.scrolled_comment_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
markScrolledAsRead(commentId: number) {
|
||||||
|
let found = this.state.comments.find(c => c.id == commentId);
|
||||||
|
let parent = this.state.comments.find(c => found.parent_id == c.id);
|
||||||
|
let parent_user_id = parent ? parent.creator_id : this.state.post.creator_id;
|
||||||
|
|
||||||
|
if (UserService.Instance.user && UserService.Instance.user.id == parent_user_id) {
|
||||||
|
|
||||||
|
let form: CommentFormI = {
|
||||||
|
content: found.content,
|
||||||
|
edit_id: found.id,
|
||||||
|
creator_id: found.creator_id,
|
||||||
|
post_id: found.post_id,
|
||||||
|
parent_id: found.parent_id,
|
||||||
|
read: true,
|
||||||
|
auth: null
|
||||||
|
};
|
||||||
|
WebSocketService.Instance.editComment(form);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -248,6 +269,7 @@ export class Post extends Component<any, PostState> {
|
||||||
found.upvotes = res.comment.upvotes;
|
found.upvotes = res.comment.upvotes;
|
||||||
found.downvotes = res.comment.downvotes;
|
found.downvotes = res.comment.downvotes;
|
||||||
found.score = res.comment.score;
|
found.score = res.comment.score;
|
||||||
|
found.read = res.comment.read;
|
||||||
|
|
||||||
this.setState(this.state);
|
this.setState(this.state);
|
||||||
} else if (op == UserOperation.SaveComment) {
|
} else if (op == UserOperation.SaveComment) {
|
||||||
|
|
Reference in a new issue