-import { myAuthRequired } from "@utils/app";
+import { myAuth, myAuthRequired } from "@utils/app";
import { canShare, share } from "@utils/browser";
import { getExternalHost, getHttpBase } from "@utils/env";
import {
FeaturePost,
Language,
LockPost,
+ MarkPostAsRead,
PersonView,
PostView,
PurgePerson,
onAddModToCommunity(form: AddModToCommunity): void;
onAddAdmin(form: AddAdmin): void;
onTransferCommunity(form: TransferCommunity): void;
+ onMarkPostAsRead(form: MarkPostAsRead): void;
}
export class PostListing extends Component<PostListingProps, PostListingState> {
const url = post.url;
const thumbnail = post.thumbnail_url;
- if (url && isImage(url)) {
- if (url.includes("pictrs")) {
- return url;
- } else if (thumbnail) {
- return thumbnail;
- } else {
- return url;
- }
- } else if (thumbnail) {
+ if (thumbnail) {
return thumbnail;
+ } else if (url && isImage(url)) {
+ return url;
} else {
return undefined;
}
href={url}
rel={relTags}
title={url}
+ target={this.linkTarget}
>
{this.imgThumb(this.imageSrc)}
<Icon
data-tippy-content={I18NextService.i18n.t("expand_here")}
onClick={linkEvent(this, this.handleImageExpandClick)}
aria-label={I18NextService.i18n.t("expand_here")}
+ target={this.linkTarget}
>
<div className="thumbnail rounded bg-light d-flex justify-content-center">
<Icon icon="play" classes="d-flex align-items-center" />
);
} else {
return (
- <a className="text-body" href={url} title={url} rel={relTags}>
+ <a
+ className="text-body"
+ href={url}
+ title={url}
+ rel={relTags}
+ target={this.linkTarget}
+ >
<div className="thumbnail rounded bg-light d-flex justify-content-center">
<Icon icon="external-link" classes="d-flex align-items-center" />
</div>
className="text-body"
to={`/post/${post.id}`}
title={I18NextService.i18n.t("comments")}
+ target={this.linkTarget}
>
<div className="thumbnail rounded bg-light d-flex justify-content-center">
<Icon icon="message-square" classes="d-flex align-items-center" />
<span className="mx-1 badge text-bg-light">
{
this.props.allLanguages.find(
- lang => lang.id === post_view.post.language_id
+ lang => lang.id === post_view.post.language_id,
)?.name
}
</span>
<small
className="unselectable pointer ms-2 text-muted fst-italic"
data-tippy-content={I18NextService.i18n.t(
- "featured_in_community"
+ "featured_in_community",
)}
aria-label={I18NextService.i18n.t("featured_in_community")}
>
);
}
+ public get linkTarget(): string {
+ return UserService.Instance.myUserInfo?.local_user_view.local_user
+ .open_links_in_new_tab
+ ? "_blank"
+ : // _self is the default target on links when the field is not specified
+ "_self";
+ }
+
get commentsButton() {
const post_view = this.postView;
const title = I18NextService.i18n.t("number_of_comments", {
title={title}
to={`/post/${post_view.post.id}?scrollToComments=true`}
data-tippy-content={title}
+ target={this.linkTarget}
>
<Icon icon="message-square" classes="me-1" inline />
{post_view.counts.comments}
get unreadCount(): number | undefined {
const pv = this.postView;
- return pv.unread_comments == pv.counts.comments || pv.unread_comments == 0
+ return pv.unread_comments === pv.counts.comments || pv.unread_comments === 0
? undefined
: pv.unread_comments;
}
className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
onClick={linkEvent(
this,
- !removed ? this.handleModRemoveShow : this.handleModRemoveSubmit
+ !removed ? this.handleModRemoveShow : this.handleModRemoveSubmit,
)}
>
{/* TODO: Find an icon for this. */}
removeAndBanDialogs() {
const post = this.postView;
const purgeTypeText =
- this.state.purgeType == PurgeType.Post
+ this.state.purgeType === PurgeType.Post
? I18NextService.i18n.t("purge_post")
: `${I18NextService.i18n.t("purge")} ${post.creator.name}`;
return (
className="btn btn-link btn-animate text-muted py-0 d-inline-block"
onClick={linkEvent(
this,
- this.handleCancelShowConfirmTransferCommunity
+ this.handleCancelShowConfirmTransferCommunity,
)}
aria-label={I18NextService.i18n.t("no")}
>
private get myPost(): boolean {
return (
- this.postView.creator.id ==
+ this.postView.creator.id ===
UserService.Instance.myUserInfo?.local_user_view.person.id
);
}
const ban = !i.props.post_view.creator_banned_from_community;
// If its an unban, restore all their data
- if (ban == false) {
+ if (ban === false) {
i.setState({ removeData: false });
}
const person_id = i.props.post_view.creator.id;
const reason = i.state.banReason;
const expires = futureDaysToUnixTime(i.state.banExpireDays);
- if (i.state.banType == BanType.Community) {
+ if (i.state.banType === BanType.Community) {
const community_id = i.postView.community.id;
i.props.onBanPersonFromCommunity({
community_id,
event.preventDefault();
i.setState({ imageExpanded: !i.state.imageExpanded });
setupTippy();
+
+ const auth = myAuth();
+ if (auth && !i.props.post_view.read) {
+ i.props.onMarkPostAsRead({
+ post_id: i.props.post_view.post.id,
+ read: true,
+ auth: auth,
+ });
+ }
}
handleViewSource(i: PostListing) {
this.props.moderators,
this.props.admins,
undefined,
- true
+ true,
);
}
return canMod(
this.postView.creator.id,
this.props.moderators,
- this.props.admins
+ this.props.admins,
);
}