2019-04-17 19:40:41 +00:00
|
|
|
import { Component, linkEvent } from 'inferno';
|
2019-04-15 23:12:06 +00:00
|
|
|
import { Link } from 'inferno-router';
|
2019-10-19 00:20:27 +00:00
|
|
|
import { Subscription } from 'rxjs';
|
2019-04-15 23:12:06 +00:00
|
|
|
import { retryWhen, delay, take } from 'rxjs/operators';
|
2019-10-19 00:20:27 +00:00
|
|
|
import {
|
|
|
|
UserOperation,
|
|
|
|
GetModlogForm,
|
|
|
|
GetModlogResponse,
|
|
|
|
ModRemovePost,
|
|
|
|
ModLockPost,
|
|
|
|
ModStickyPost,
|
|
|
|
ModRemoveComment,
|
|
|
|
ModRemoveCommunity,
|
|
|
|
ModBanFromCommunity,
|
|
|
|
ModBan,
|
|
|
|
ModAddCommunity,
|
|
|
|
ModAdd,
|
|
|
|
} from '../interfaces';
|
2019-04-15 23:12:06 +00:00
|
|
|
import { WebSocketService } from '../services';
|
2020-01-24 00:17:42 +00:00
|
|
|
import { wsJsonToRes, addTypeInfo, fetchLimit, toast } from '../utils';
|
2019-04-15 23:12:06 +00:00
|
|
|
import { MomentTime } from './moment-time';
|
2020-01-23 03:29:11 +00:00
|
|
|
import moment from 'moment';
|
2019-09-09 06:14:13 +00:00
|
|
|
import { i18n } from '../i18next';
|
2019-04-15 23:12:06 +00:00
|
|
|
|
|
|
|
interface ModlogState {
|
2019-10-19 00:20:27 +00:00
|
|
|
combined: Array<{
|
|
|
|
type_: string;
|
|
|
|
data:
|
|
|
|
| ModRemovePost
|
|
|
|
| ModLockPost
|
|
|
|
| ModStickyPost
|
|
|
|
| ModRemoveCommunity
|
|
|
|
| ModAdd
|
|
|
|
| ModBan;
|
|
|
|
}>;
|
|
|
|
communityId?: number;
|
|
|
|
communityName?: string;
|
2019-04-17 19:40:41 +00:00
|
|
|
page: number;
|
2019-04-15 23:12:06 +00:00
|
|
|
loading: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
export class Modlog extends Component<any, ModlogState> {
|
|
|
|
private subscription: Subscription;
|
|
|
|
private emptyState: ModlogState = {
|
2019-04-16 23:04:23 +00:00
|
|
|
combined: [],
|
2019-04-17 19:40:41 +00:00
|
|
|
page: 1,
|
2019-04-16 23:04:23 +00:00
|
|
|
loading: true,
|
2019-10-19 00:20:27 +00:00
|
|
|
};
|
2019-04-15 23:12:06 +00:00
|
|
|
|
|
|
|
constructor(props: any, context: any) {
|
|
|
|
super(props, context);
|
2019-04-16 23:04:23 +00:00
|
|
|
|
2019-04-15 23:12:06 +00:00
|
|
|
this.state = this.emptyState;
|
2019-10-19 00:20:27 +00:00
|
|
|
this.state.communityId = this.props.match.params.community_id
|
|
|
|
? Number(this.props.match.params.community_id)
|
|
|
|
: undefined;
|
2019-04-15 23:12:06 +00:00
|
|
|
this.subscription = WebSocketService.Instance.subject
|
2020-01-23 03:29:11 +00:00
|
|
|
.pipe(retryWhen(errors => errors.pipe(delay(3000), take(10))))
|
2019-10-19 00:20:27 +00:00
|
|
|
.subscribe(
|
|
|
|
msg => this.parseMessage(msg),
|
|
|
|
err => console.error(err),
|
2019-04-15 23:12:06 +00:00
|
|
|
() => console.log('complete')
|
2019-10-19 00:20:27 +00:00
|
|
|
);
|
2019-04-15 23:12:06 +00:00
|
|
|
|
2019-04-17 19:40:41 +00:00
|
|
|
this.refetch();
|
2019-04-15 23:12:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
this.subscription.unsubscribe();
|
|
|
|
}
|
|
|
|
|
2019-04-22 16:24:13 +00:00
|
|
|
componentDidMount() {
|
2019-06-03 01:35:46 +00:00
|
|
|
document.title = `Modlog - ${WebSocketService.Instance.site.name}`;
|
2019-04-22 16:24:13 +00:00
|
|
|
}
|
|
|
|
|
2019-04-16 23:04:23 +00:00
|
|
|
setCombined(res: GetModlogResponse) {
|
2019-10-19 00:20:27 +00:00
|
|
|
let removed_posts = addTypeInfo(res.removed_posts, 'removed_posts');
|
|
|
|
let locked_posts = addTypeInfo(res.locked_posts, 'locked_posts');
|
|
|
|
let stickied_posts = addTypeInfo(res.stickied_posts, 'stickied_posts');
|
|
|
|
let removed_comments = addTypeInfo(
|
|
|
|
res.removed_comments,
|
|
|
|
'removed_comments'
|
|
|
|
);
|
|
|
|
let removed_communities = addTypeInfo(
|
|
|
|
res.removed_communities,
|
|
|
|
'removed_communities'
|
|
|
|
);
|
|
|
|
let banned_from_community = addTypeInfo(
|
|
|
|
res.banned_from_community,
|
|
|
|
'banned_from_community'
|
|
|
|
);
|
|
|
|
let added_to_community = addTypeInfo(
|
|
|
|
res.added_to_community,
|
|
|
|
'added_to_community'
|
|
|
|
);
|
|
|
|
let added = addTypeInfo(res.added, 'added');
|
|
|
|
let banned = addTypeInfo(res.banned, 'banned');
|
2019-04-17 19:40:41 +00:00
|
|
|
this.state.combined = [];
|
2019-04-16 23:04:23 +00:00
|
|
|
|
|
|
|
this.state.combined.push(...removed_posts);
|
|
|
|
this.state.combined.push(...locked_posts);
|
2019-09-09 06:14:13 +00:00
|
|
|
this.state.combined.push(...stickied_posts);
|
2019-04-16 23:04:23 +00:00
|
|
|
this.state.combined.push(...removed_comments);
|
|
|
|
this.state.combined.push(...removed_communities);
|
|
|
|
this.state.combined.push(...banned_from_community);
|
|
|
|
this.state.combined.push(...added_to_community);
|
2019-04-20 04:06:25 +00:00
|
|
|
this.state.combined.push(...added);
|
|
|
|
this.state.combined.push(...banned);
|
2019-04-16 23:04:23 +00:00
|
|
|
|
|
|
|
if (this.state.communityId && this.state.combined.length > 0) {
|
2019-10-19 00:20:27 +00:00
|
|
|
this.state.communityName = (this.state.combined[0]
|
|
|
|
.data as ModRemovePost).community_name;
|
2019-04-16 23:04:23 +00:00
|
|
|
}
|
2019-04-15 23:12:06 +00:00
|
|
|
|
|
|
|
// Sort them by time
|
2019-10-19 00:20:27 +00:00
|
|
|
this.state.combined.sort((a, b) =>
|
|
|
|
b.data.when_.localeCompare(a.data.when_)
|
|
|
|
);
|
2019-04-15 23:12:06 +00:00
|
|
|
|
2019-04-16 23:04:23 +00:00
|
|
|
this.setState(this.state);
|
|
|
|
}
|
2019-04-15 23:12:06 +00:00
|
|
|
|
2019-04-16 23:04:23 +00:00
|
|
|
combined() {
|
2019-04-15 23:12:06 +00:00
|
|
|
return (
|
|
|
|
<tbody>
|
2019-10-19 00:20:27 +00:00
|
|
|
{this.state.combined.map(i => (
|
2019-04-15 23:12:06 +00:00
|
|
|
<tr>
|
|
|
|
<td>
|
2019-10-19 00:20:27 +00:00
|
|
|
<MomentTime data={i.data} />
|
|
|
|
</td>
|
|
|
|
<td>
|
|
|
|
<Link to={`/u/${i.data.mod_user_name}`}>
|
|
|
|
{i.data.mod_user_name}
|
|
|
|
</Link>
|
|
|
|
</td>
|
|
|
|
<td>
|
|
|
|
{i.type_ == 'removed_posts' && (
|
2019-04-15 23:12:06 +00:00
|
|
|
<>
|
2019-10-19 00:20:27 +00:00
|
|
|
{(i.data as ModRemovePost).removed ? 'Removed' : 'Restored'}
|
|
|
|
<span>
|
|
|
|
{' '}
|
|
|
|
Post{' '}
|
|
|
|
<Link to={`/post/${(i.data as ModRemovePost).post_id}`}>
|
|
|
|
{(i.data as ModRemovePost).post_name}
|
|
|
|
</Link>
|
|
|
|
</span>
|
|
|
|
<div>
|
|
|
|
{(i.data as ModRemovePost).reason &&
|
|
|
|
` reason: ${(i.data as ModRemovePost).reason}`}
|
|
|
|
</div>
|
2019-04-15 23:12:06 +00:00
|
|
|
</>
|
2019-10-19 00:20:27 +00:00
|
|
|
)}
|
|
|
|
{i.type_ == 'locked_posts' && (
|
2019-04-15 23:12:06 +00:00
|
|
|
<>
|
2019-10-19 00:20:27 +00:00
|
|
|
{(i.data as ModLockPost).locked ? 'Locked' : 'Unlocked'}
|
|
|
|
<span>
|
|
|
|
{' '}
|
|
|
|
Post{' '}
|
|
|
|
<Link to={`/post/${(i.data as ModLockPost).post_id}`}>
|
|
|
|
{(i.data as ModLockPost).post_name}
|
|
|
|
</Link>
|
|
|
|
</span>
|
2019-04-15 23:12:06 +00:00
|
|
|
</>
|
2019-10-19 00:20:27 +00:00
|
|
|
)}
|
|
|
|
{i.type_ == 'stickied_posts' && (
|
2019-09-09 06:14:13 +00:00
|
|
|
<>
|
2019-10-19 00:20:27 +00:00
|
|
|
{(i.data as ModStickyPost).stickied
|
|
|
|
? 'Stickied'
|
|
|
|
: 'Unstickied'}
|
|
|
|
<span>
|
|
|
|
{' '}
|
|
|
|
Post{' '}
|
|
|
|
<Link to={`/post/${(i.data as ModStickyPost).post_id}`}>
|
|
|
|
{(i.data as ModStickyPost).post_name}
|
|
|
|
</Link>
|
|
|
|
</span>
|
2019-09-09 06:14:13 +00:00
|
|
|
</>
|
2019-10-19 00:20:27 +00:00
|
|
|
)}
|
|
|
|
{i.type_ == 'removed_comments' && (
|
2019-04-15 23:12:06 +00:00
|
|
|
<>
|
2019-10-19 00:20:27 +00:00
|
|
|
{(i.data as ModRemoveComment).removed
|
|
|
|
? 'Removed'
|
|
|
|
: 'Restored'}
|
|
|
|
<span>
|
|
|
|
{' '}
|
|
|
|
Comment{' '}
|
|
|
|
<Link
|
|
|
|
to={`/post/${
|
|
|
|
(i.data as ModRemoveComment).post_id
|
|
|
|
}/comment/${(i.data as ModRemoveComment).comment_id}`}
|
|
|
|
>
|
|
|
|
{(i.data as ModRemoveComment).comment_content}
|
|
|
|
</Link>
|
|
|
|
</span>
|
|
|
|
<span>
|
|
|
|
{' '}
|
|
|
|
by{' '}
|
|
|
|
<Link
|
|
|
|
to={`/u/${
|
|
|
|
(i.data as ModRemoveComment).comment_user_name
|
|
|
|
}`}
|
|
|
|
>
|
|
|
|
{(i.data as ModRemoveComment).comment_user_name}
|
|
|
|
</Link>
|
|
|
|
</span>
|
|
|
|
<div>
|
|
|
|
{(i.data as ModRemoveComment).reason &&
|
|
|
|
` reason: ${(i.data as ModRemoveComment).reason}`}
|
|
|
|
</div>
|
2019-04-15 23:12:06 +00:00
|
|
|
</>
|
2019-10-19 00:20:27 +00:00
|
|
|
)}
|
|
|
|
{i.type_ == 'removed_communities' && (
|
2019-04-15 23:12:06 +00:00
|
|
|
<>
|
2019-10-19 00:20:27 +00:00
|
|
|
{(i.data as ModRemoveCommunity).removed
|
|
|
|
? 'Removed'
|
|
|
|
: 'Restored'}
|
|
|
|
<span>
|
|
|
|
{' '}
|
|
|
|
Community{' '}
|
|
|
|
<Link
|
|
|
|
to={`/c/${(i.data as ModRemoveCommunity).community_name}`}
|
|
|
|
>
|
|
|
|
{(i.data as ModRemoveCommunity).community_name}
|
|
|
|
</Link>
|
|
|
|
</span>
|
|
|
|
<div>
|
|
|
|
{(i.data as ModRemoveCommunity).reason &&
|
|
|
|
` reason: ${(i.data as ModRemoveCommunity).reason}`}
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
{(i.data as ModRemoveCommunity).expires &&
|
|
|
|
` expires: ${moment
|
|
|
|
.utc((i.data as ModRemoveCommunity).expires)
|
|
|
|
.fromNow()}`}
|
|
|
|
</div>
|
2019-04-15 23:12:06 +00:00
|
|
|
</>
|
2019-10-19 00:20:27 +00:00
|
|
|
)}
|
|
|
|
{i.type_ == 'banned_from_community' && (
|
2019-04-15 23:12:06 +00:00
|
|
|
<>
|
2019-10-19 00:20:27 +00:00
|
|
|
<span>
|
|
|
|
{(i.data as ModBanFromCommunity).banned
|
|
|
|
? 'Banned '
|
|
|
|
: 'Unbanned '}{' '}
|
|
|
|
</span>
|
|
|
|
<span>
|
|
|
|
<Link
|
|
|
|
to={`/u/${
|
|
|
|
(i.data as ModBanFromCommunity).other_user_name
|
|
|
|
}`}
|
|
|
|
>
|
|
|
|
{(i.data as ModBanFromCommunity).other_user_name}
|
|
|
|
</Link>
|
|
|
|
</span>
|
2019-04-20 04:06:25 +00:00
|
|
|
<span> from the community </span>
|
2019-10-19 00:20:27 +00:00
|
|
|
<span>
|
|
|
|
<Link
|
|
|
|
to={`/c/${
|
|
|
|
(i.data as ModBanFromCommunity).community_name
|
|
|
|
}`}
|
|
|
|
>
|
|
|
|
{(i.data as ModBanFromCommunity).community_name}
|
|
|
|
</Link>
|
|
|
|
</span>
|
|
|
|
<div>
|
|
|
|
{(i.data as ModBanFromCommunity).reason &&
|
|
|
|
` reason: ${(i.data as ModBanFromCommunity).reason}`}
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
{(i.data as ModBanFromCommunity).expires &&
|
|
|
|
` expires: ${moment
|
|
|
|
.utc((i.data as ModBanFromCommunity).expires)
|
|
|
|
.fromNow()}`}
|
|
|
|
</div>
|
2019-04-15 23:12:06 +00:00
|
|
|
</>
|
2019-10-19 00:20:27 +00:00
|
|
|
)}
|
|
|
|
{i.type_ == 'added_to_community' && (
|
2019-04-15 23:12:06 +00:00
|
|
|
<>
|
2019-10-19 00:20:27 +00:00
|
|
|
<span>
|
|
|
|
{(i.data as ModAddCommunity).removed
|
|
|
|
? 'Removed '
|
|
|
|
: 'Appointed '}{' '}
|
|
|
|
</span>
|
|
|
|
<span>
|
|
|
|
<Link
|
|
|
|
to={`/u/${(i.data as ModAddCommunity).other_user_name}`}
|
|
|
|
>
|
|
|
|
{(i.data as ModAddCommunity).other_user_name}
|
|
|
|
</Link>
|
|
|
|
</span>
|
2019-04-15 23:12:06 +00:00
|
|
|
<span> as a mod to the community </span>
|
2019-10-19 00:20:27 +00:00
|
|
|
<span>
|
|
|
|
<Link
|
|
|
|
to={`/c/${(i.data as ModAddCommunity).community_name}`}
|
|
|
|
>
|
|
|
|
{(i.data as ModAddCommunity).community_name}
|
|
|
|
</Link>
|
|
|
|
</span>
|
2019-04-20 04:06:25 +00:00
|
|
|
</>
|
2019-10-19 00:20:27 +00:00
|
|
|
)}
|
|
|
|
{i.type_ == 'banned' && (
|
2019-04-20 04:06:25 +00:00
|
|
|
<>
|
2019-10-19 00:20:27 +00:00
|
|
|
<span>
|
|
|
|
{(i.data as ModBan).banned ? 'Banned ' : 'Unbanned '}{' '}
|
|
|
|
</span>
|
|
|
|
<span>
|
|
|
|
<Link to={`/u/${(i.data as ModBan).other_user_name}`}>
|
|
|
|
{(i.data as ModBan).other_user_name}
|
|
|
|
</Link>
|
|
|
|
</span>
|
|
|
|
<div>
|
|
|
|
{(i.data as ModBan).reason &&
|
|
|
|
` reason: ${(i.data as ModBan).reason}`}
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
{(i.data as ModBan).expires &&
|
|
|
|
` expires: ${moment
|
|
|
|
.utc((i.data as ModBan).expires)
|
|
|
|
.fromNow()}`}
|
|
|
|
</div>
|
2019-04-20 04:06:25 +00:00
|
|
|
</>
|
2019-10-19 00:20:27 +00:00
|
|
|
)}
|
|
|
|
{i.type_ == 'added' && (
|
2019-04-20 04:06:25 +00:00
|
|
|
<>
|
2019-10-19 00:20:27 +00:00
|
|
|
<span>
|
|
|
|
{(i.data as ModAdd).removed ? 'Removed ' : 'Appointed '}{' '}
|
|
|
|
</span>
|
|
|
|
<span>
|
|
|
|
<Link to={`/u/${(i.data as ModAdd).other_user_name}`}>
|
|
|
|
{(i.data as ModAdd).other_user_name}
|
|
|
|
</Link>
|
|
|
|
</span>
|
2019-04-20 04:06:25 +00:00
|
|
|
<span> as an admin </span>
|
2019-04-15 23:12:06 +00:00
|
|
|
</>
|
2019-10-19 00:20:27 +00:00
|
|
|
)}
|
2019-04-15 23:12:06 +00:00
|
|
|
</td>
|
|
|
|
</tr>
|
2019-10-19 00:20:27 +00:00
|
|
|
))}
|
2019-04-15 23:12:06 +00:00
|
|
|
</tbody>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<div class="container">
|
2019-10-19 00:20:27 +00:00
|
|
|
{this.state.loading ? (
|
2020-01-31 20:52:27 +00:00
|
|
|
<h5 class="text-center">
|
2019-10-19 00:20:27 +00:00
|
|
|
<svg class="icon icon-spinner spin">
|
|
|
|
<use xlinkHref="#icon-spinner"></use>
|
|
|
|
</svg>
|
2019-04-20 04:06:25 +00:00
|
|
|
</h5>
|
2019-10-19 00:20:27 +00:00
|
|
|
) : (
|
|
|
|
<div>
|
|
|
|
<h5>
|
|
|
|
{this.state.communityName && (
|
|
|
|
<Link
|
|
|
|
className="text-white"
|
|
|
|
to={`/c/${this.state.communityName}`}
|
|
|
|
>
|
|
|
|
/c/{this.state.communityName}{' '}
|
|
|
|
</Link>
|
|
|
|
)}
|
2020-01-31 20:52:27 +00:00
|
|
|
<span>{ i18n.t('modlog') }</span>
|
2019-10-19 00:20:27 +00:00
|
|
|
</h5>
|
|
|
|
<div class="table-responsive">
|
|
|
|
<table id="modlog_table" class="table table-sm table-hover">
|
|
|
|
<thead class="pointer">
|
|
|
|
<tr>
|
2020-01-31 20:52:27 +00:00
|
|
|
<th> { i18n.t('time')}</th>
|
|
|
|
<th>{ i18n.t('mod')}</th>
|
|
|
|
<th>{ i18n.t('action')}</th>
|
2019-10-19 00:20:27 +00:00
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
{this.combined()}
|
|
|
|
</table>
|
|
|
|
{this.paginator()}
|
|
|
|
</div>
|
2019-04-15 23:12:06 +00:00
|
|
|
</div>
|
2019-10-19 00:20:27 +00:00
|
|
|
)}
|
2019-04-15 23:12:06 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-04-17 19:40:41 +00:00
|
|
|
paginator() {
|
|
|
|
return (
|
|
|
|
<div class="mt-2">
|
2019-10-19 00:20:27 +00:00
|
|
|
{this.state.page > 1 && (
|
|
|
|
<button
|
|
|
|
class="btn btn-sm btn-secondary mr-1"
|
|
|
|
onClick={linkEvent(this, this.prevPage)}
|
|
|
|
>
|
2020-01-31 20:52:27 +00:00
|
|
|
{ i18n.t('prev') }
|
2019-10-19 00:20:27 +00:00
|
|
|
</button>
|
|
|
|
)}
|
|
|
|
<button
|
|
|
|
class="btn btn-sm btn-secondary"
|
|
|
|
onClick={linkEvent(this, this.nextPage)}
|
|
|
|
>
|
2020-01-31 20:52:27 +00:00
|
|
|
{ i18n.t('next') }
|
2019-10-19 00:20:27 +00:00
|
|
|
</button>
|
2019-04-17 19:40:41 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-10-19 00:20:27 +00:00
|
|
|
nextPage(i: Modlog) {
|
2019-04-17 19:40:41 +00:00
|
|
|
i.state.page++;
|
|
|
|
i.setState(i.state);
|
|
|
|
i.refetch();
|
|
|
|
}
|
|
|
|
|
2019-10-19 00:20:27 +00:00
|
|
|
prevPage(i: Modlog) {
|
2019-04-17 19:40:41 +00:00
|
|
|
i.state.page--;
|
|
|
|
i.setState(i.state);
|
|
|
|
i.refetch();
|
|
|
|
}
|
2019-04-20 04:06:25 +00:00
|
|
|
|
2019-10-19 00:20:27 +00:00
|
|
|
refetch() {
|
2019-04-17 19:40:41 +00:00
|
|
|
let modlogForm: GetModlogForm = {
|
|
|
|
community_id: this.state.communityId,
|
|
|
|
page: this.state.page,
|
|
|
|
limit: fetchLimit,
|
|
|
|
};
|
|
|
|
WebSocketService.Instance.getModlog(modlogForm);
|
|
|
|
}
|
|
|
|
|
2020-01-19 05:38:45 +00:00
|
|
|
parseMessage(msg: WebSocketJsonResponse) {
|
2019-04-15 23:12:06 +00:00
|
|
|
console.log(msg);
|
2020-01-19 04:54:10 +00:00
|
|
|
let res = wsJsonToRes(msg);
|
2020-01-25 14:58:53 +00:00
|
|
|
if (msg.error) {
|
2020-01-23 03:29:11 +00:00
|
|
|
toast(i18n.t(msg.error), 'danger');
|
2019-04-15 23:12:06 +00:00
|
|
|
return;
|
2020-01-19 04:54:10 +00:00
|
|
|
} else if (res.op == UserOperation.GetModlog) {
|
|
|
|
let data = res.data as GetModlogResponse;
|
2019-04-15 23:12:06 +00:00
|
|
|
this.state.loading = false;
|
2019-10-19 00:20:27 +00:00
|
|
|
window.scrollTo(0, 0);
|
2020-01-19 04:54:10 +00:00
|
|
|
this.setCombined(data);
|
2019-10-19 00:20:27 +00:00
|
|
|
}
|
2019-04-15 23:12:06 +00:00
|
|
|
}
|
|
|
|
}
|