2021-02-22 02:39:04 +00:00
|
|
|
import { Component } from "inferno";
|
2021-09-18 14:27:49 +00:00
|
|
|
import { T } from "inferno-i18next-dess";
|
2021-02-22 02:39:04 +00:00
|
|
|
import { Link } from "inferno-router";
|
2023-06-14 12:20:40 +00:00
|
|
|
import {
|
|
|
|
AddAdmin,
|
|
|
|
AddModToCommunity,
|
|
|
|
BanFromCommunity,
|
|
|
|
BanPerson,
|
|
|
|
BlockPerson,
|
|
|
|
CreatePostLike,
|
|
|
|
CreatePostReport,
|
|
|
|
DeletePost,
|
|
|
|
EditPost,
|
|
|
|
FeaturePost,
|
|
|
|
Language,
|
|
|
|
LockPost,
|
|
|
|
PostView,
|
|
|
|
PurgePerson,
|
|
|
|
PurgePost,
|
|
|
|
RemovePost,
|
|
|
|
SavePost,
|
|
|
|
TransferCommunity,
|
|
|
|
} from "lemmy-js-client";
|
2021-07-17 20:42:55 +00:00
|
|
|
import { i18n } from "../../i18next";
|
2021-02-22 02:39:04 +00:00
|
|
|
import { PostListing } from "./post-listing";
|
2020-09-06 16:15:25 +00:00
|
|
|
|
|
|
|
interface PostListingsProps {
|
2020-12-24 01:58:27 +00:00
|
|
|
posts: PostView[];
|
2022-09-22 15:14:58 +00:00
|
|
|
allLanguages: Language[];
|
2022-12-19 15:57:29 +00:00
|
|
|
siteLanguages: number[];
|
2020-09-06 16:15:25 +00:00
|
|
|
showCommunity?: boolean;
|
|
|
|
removeDuplicates?: boolean;
|
2023-01-04 16:56:24 +00:00
|
|
|
enableDownvotes?: boolean;
|
|
|
|
enableNsfw?: boolean;
|
2023-06-14 12:20:40 +00:00
|
|
|
viewOnly?: boolean;
|
|
|
|
onPostEdit(form: EditPost): void;
|
|
|
|
onPostVote(form: CreatePostLike): void;
|
|
|
|
onPostReport(form: CreatePostReport): void;
|
|
|
|
onBlockPerson(form: BlockPerson): void;
|
|
|
|
onLockPost(form: LockPost): void;
|
|
|
|
onDeletePost(form: DeletePost): void;
|
|
|
|
onRemovePost(form: RemovePost): void;
|
|
|
|
onSavePost(form: SavePost): void;
|
|
|
|
onFeaturePost(form: FeaturePost): void;
|
|
|
|
onPurgePerson(form: PurgePerson): void;
|
|
|
|
onPurgePost(form: PurgePost): void;
|
|
|
|
onBanPersonFromCommunity(form: BanFromCommunity): void;
|
|
|
|
onBanPerson(form: BanPerson): void;
|
|
|
|
onAddModToCommunity(form: AddModToCommunity): void;
|
|
|
|
onAddAdmin(form: AddAdmin): void;
|
|
|
|
onTransferCommunity(form: TransferCommunity): void;
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
2022-06-21 21:42:29 +00:00
|
|
|
export class PostListings extends Component<PostListingsProps, any> {
|
2021-10-18 01:44:39 +00:00
|
|
|
duplicatesMap = new Map<number, PostView[]>();
|
|
|
|
|
2020-09-06 16:15:25 +00:00
|
|
|
constructor(props: any, context: any) {
|
|
|
|
super(props, context);
|
2022-06-21 21:42:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get posts() {
|
|
|
|
return this.props.removeDuplicates
|
|
|
|
? this.removeDuplicates()
|
|
|
|
: this.props.posts;
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<div>
|
2022-06-21 21:42:29 +00:00
|
|
|
{this.posts.length > 0 ? (
|
|
|
|
this.posts.map(post_view => (
|
2020-09-06 16:15:25 +00:00
|
|
|
<>
|
|
|
|
<PostListing
|
2020-12-24 01:58:27 +00:00
|
|
|
post_view={post_view}
|
2023-06-14 12:20:40 +00:00
|
|
|
crossPosts={this.duplicatesMap.get(post_view.post.id)}
|
2020-09-06 16:15:25 +00:00
|
|
|
showCommunity={this.props.showCommunity}
|
|
|
|
enableDownvotes={this.props.enableDownvotes}
|
|
|
|
enableNsfw={this.props.enableNsfw}
|
2023-06-14 12:20:40 +00:00
|
|
|
viewOnly={this.props.viewOnly}
|
2022-09-22 15:14:58 +00:00
|
|
|
allLanguages={this.props.allLanguages}
|
2022-12-19 15:57:29 +00:00
|
|
|
siteLanguages={this.props.siteLanguages}
|
2023-06-14 12:20:40 +00:00
|
|
|
onPostEdit={this.props.onPostEdit}
|
|
|
|
onPostVote={this.props.onPostVote}
|
|
|
|
onPostReport={this.props.onPostReport}
|
|
|
|
onBlockPerson={this.props.onBlockPerson}
|
|
|
|
onLockPost={this.props.onLockPost}
|
|
|
|
onDeletePost={this.props.onDeletePost}
|
|
|
|
onRemovePost={this.props.onRemovePost}
|
|
|
|
onSavePost={this.props.onSavePost}
|
|
|
|
onFeaturePost={this.props.onFeaturePost}
|
|
|
|
onPurgePerson={this.props.onPurgePerson}
|
|
|
|
onPurgePost={this.props.onPurgePost}
|
|
|
|
onBanPersonFromCommunity={this.props.onBanPersonFromCommunity}
|
|
|
|
onBanPerson={this.props.onBanPerson}
|
|
|
|
onAddModToCommunity={this.props.onAddModToCommunity}
|
|
|
|
onAddAdmin={this.props.onAddAdmin}
|
|
|
|
onTransferCommunity={this.props.onTransferCommunity}
|
2020-09-06 16:15:25 +00:00
|
|
|
/>
|
2022-09-22 15:03:35 +00:00
|
|
|
<hr className="my-3" />
|
2020-09-06 16:15:25 +00:00
|
|
|
</>
|
|
|
|
))
|
|
|
|
) : (
|
|
|
|
<>
|
2021-02-22 02:39:04 +00:00
|
|
|
<div>{i18n.t("no_posts")}</div>
|
2022-06-21 21:42:29 +00:00
|
|
|
{this.props.showCommunity && (
|
2020-09-06 16:15:25 +00:00
|
|
|
<T i18nKey="subscribe_to_communities">
|
|
|
|
#<Link to="/communities">#</Link>
|
|
|
|
</T>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-10-18 01:44:39 +00:00
|
|
|
removeDuplicates(): PostView[] {
|
|
|
|
// Must use a spread to clone the props, because splice will fail below otherwise.
|
2023-06-14 12:20:40 +00:00
|
|
|
const posts = [...this.props.posts].filter(empty => empty);
|
2020-09-06 16:15:25 +00:00
|
|
|
|
|
|
|
// A map from post url to list of posts (dupes)
|
2023-06-05 21:31:12 +00:00
|
|
|
const urlMap = new Map<string, PostView[]>();
|
2020-09-06 16:15:25 +00:00
|
|
|
|
|
|
|
// Loop over the posts, find ones with same urls
|
2023-06-05 21:31:12 +00:00
|
|
|
for (const pv of posts) {
|
|
|
|
const url = pv.post.url;
|
2023-01-04 16:56:24 +00:00
|
|
|
if (
|
|
|
|
!pv.post.deleted &&
|
2020-12-24 01:58:27 +00:00
|
|
|
!pv.post.removed &&
|
|
|
|
!pv.community.deleted &&
|
2022-06-21 21:42:29 +00:00
|
|
|
!pv.community.removed &&
|
2023-01-04 16:56:24 +00:00
|
|
|
url
|
|
|
|
) {
|
|
|
|
if (!urlMap.get(url)) {
|
|
|
|
urlMap.set(url, [pv]);
|
|
|
|
} else {
|
|
|
|
urlMap.get(url)?.push(pv);
|
|
|
|
}
|
|
|
|
}
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Sort by oldest
|
|
|
|
// Remove the ones that have no length
|
2023-06-05 21:31:12 +00:00
|
|
|
for (const e of urlMap.entries()) {
|
2020-09-06 16:15:25 +00:00
|
|
|
if (e[1].length == 1) {
|
|
|
|
urlMap.delete(e[0]);
|
|
|
|
} else {
|
2020-12-24 01:58:27 +00:00
|
|
|
e[1].sort((a, b) => a.post.published.localeCompare(b.post.published));
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (let i = 0; i < posts.length; i++) {
|
2023-06-05 21:31:12 +00:00
|
|
|
const pv = posts[i];
|
|
|
|
const url = pv.post.url;
|
2023-01-04 16:56:24 +00:00
|
|
|
if (url) {
|
2023-06-05 21:31:12 +00:00
|
|
|
const found = urlMap.get(url);
|
2023-01-04 16:56:24 +00:00
|
|
|
if (found) {
|
|
|
|
// If its the oldest, add
|
|
|
|
if (pv.post.id == found[0].post.id) {
|
|
|
|
this.duplicatesMap.set(pv.post.id, found.slice(1));
|
|
|
|
}
|
|
|
|
// Otherwise, delete it
|
|
|
|
else {
|
|
|
|
posts.splice(i--, 1);
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
2023-01-04 16:56:24 +00:00
|
|
|
}
|
|
|
|
}
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return posts;
|
|
|
|
}
|
|
|
|
}
|