feat: closes #11553, add forked from message like merged into

This commit is contained in:
Barış Soner Uşaklı
2023-09-28 10:10:30 -04:00
parent a05666b9ca
commit be14f6cc52
6 changed files with 34 additions and 1 deletions

View File

@@ -79,6 +79,7 @@
"resolve-flag": "Resolve Flag", "resolve-flag": "Resolve Flag",
"merged_message": "This topic has been merged into <a href=\"%1\">%2</a>", "merged_message": "This topic has been merged into <a href=\"%1\">%2</a>",
"forked-message": "This topic was forked from <a href=\"%1\">%2</a>",
"deleted_message": "This topic has been deleted. Only users with topic management privileges can see it.", "deleted_message": "This topic has been deleted. Only users with topic management privileges can see it.",
"following_topic.message": "You will now be receiving notifications when somebody posts to this topic.", "following_topic.message": "You will now be receiving notifications when somebody posts to this topic.",

View File

@@ -315,6 +315,8 @@ get:
nullable: true nullable: true
merger: merger:
nullable: true nullable: true
forker:
nullable: true
related: related:
type: array type: array
items: items:

View File

@@ -70,6 +70,9 @@ module.exports = function (Topics) {
Topics.setTopicFields(tid, { Topics.setTopicFields(tid, {
upvotes: postData.upvotes, upvotes: postData.upvotes,
downvotes: postData.downvotes, downvotes: postData.downvotes,
forkedFromTid: fromTid,
forkerUid: uid,
forkTimestamp: Date.now(),
}), }),
db.sortedSetsAdd(['topics:votes', `cid:${cid}:tids:votes`], postData.votes, tid), db.sortedSetsAdd(['topics:votes', `cid:${cid}:tids:votes`], postData.votes, tid),
Topics.events.log(fromTid, { type: 'fork', uid, href: `/topic/${tid}` }), Topics.events.log(fromTid, { type: 'fork', uid, href: `/topic/${tid}` }),

View File

@@ -164,6 +164,7 @@ Topics.getTopicWithPosts = async function (topicData, set, uid, start, stop, rev
postSharing, postSharing,
deleter, deleter,
merger, merger,
forker,
related, related,
thumbs, thumbs,
events, events,
@@ -177,6 +178,7 @@ Topics.getTopicWithPosts = async function (topicData, set, uid, start, stop, rev
social.getActivePostSharing(), social.getActivePostSharing(),
getDeleter(topicData), getDeleter(topicData),
getMerger(topicData), getMerger(topicData),
getForker(topicData),
Topics.getRelatedTopics(topicData, uid), Topics.getRelatedTopics(topicData, uid),
Topics.thumbs.load([topicData]), Topics.thumbs.load([topicData]),
Topics.events.get(topicData.tid, uid, reverse), Topics.events.get(topicData.tid, uid, reverse),
@@ -211,6 +213,10 @@ Topics.getTopicWithPosts = async function (topicData, set, uid, start, stop, rev
if (merger) { if (merger) {
topicData.mergedTimestampISO = utils.toISOString(topicData.mergedTimestamp); topicData.mergedTimestampISO = utils.toISOString(topicData.mergedTimestamp);
} }
topicData.forker = forker;
if (forker) {
topicData.forkTimestampISO = utils.toISOString(topicData.forkTimestamp);
}
topicData.related = related || []; topicData.related = related || [];
topicData.unreplied = topicData.postcount === 1; topicData.unreplied = topicData.postcount === 1;
topicData.icons = []; topicData.icons = [];
@@ -241,6 +247,21 @@ async function getMerger(topicData) {
return merger; return merger;
} }
async function getForker(topicData) {
if (!parseInt(topicData.forkerUid, 10)) {
return null;
}
const [
forker,
forkedFromTitle,
] = await Promise.all([
user.getUserFields(topicData.forkerUid, ['username', 'userslug', 'picture']),
Topics.getTopicField(topicData.forkedFromTid, 'title'),
]);
forker.forkedFromTitle = forkedFromTitle;
return forker;
}
Topics.getMainPost = async function (tid, uid) { Topics.getMainPost = async function (tid, uid) {
const mainPosts = await Topics.getMainPosts([tid], uid); const mainPosts = await Topics.getMainPosts([tid], uid);
return Array.isArray(mainPosts) && mainPosts.length ? mainPosts[0] : null; return Array.isArray(mainPosts) && mainPosts.length ? mainPosts[0] : null;

View File

@@ -0,0 +1,6 @@
<div component="topic/forked/message" class="alert alert-info mt-3 d-flex justify-content-between flex-wrap">
<span>[[topic:forked-message, {config.relative_path}/topic/{forkedFromTid}, {forker.forkedFromTitle}]]</span>
<span>
<a class="fw-bold" href="{config.relative_path}/user/{forker.userslug}">{forker.username}</strong></a> <small class="timeago" title="{forkTimestampISO}"></small>
</span>
</div>

View File

@@ -1,4 +1,4 @@
<div component="topic/merged/message" class="alert alert-warning mt-3 d-flex justify-content-between flex-wrap"> <div component="topic/merged/message" class="alert alert-info mt-3 d-flex justify-content-between flex-wrap">
<span>[[topic:merged_message, {config.relative_path}/topic/{mergeIntoTid}, {merger.mergedIntoTitle}]]</span> <span>[[topic:merged_message, {config.relative_path}/topic/{mergeIntoTid}, {merger.mergedIntoTitle}]]</span>
<span> <span>
<a class="fw-bold" href="{config.relative_path}/user/{merger.userslug}">{merger.username}</strong></a> <small class="timeago" title="{mergedTimestampISO}"></small> <a class="fw-bold" href="{config.relative_path}/user/{merger.userslug}">{merger.username}</strong></a> <small class="timeago" title="{mergedTimestampISO}"></small>