Skip to content

Commit 2db1426

Browse files
authored
Quote Posts and Reposts (#28)
* add quote posts * add reposts * change upload text to repost
1 parent 9a5305c commit 2db1426

3 files changed

Lines changed: 46 additions & 4 deletions

File tree

src/index.js

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ const PARAMS__HIDE = 'hide';
5656
const PARAMS__LINK_ATTACHMENT = 'link_attachment';
5757
const PARAMS__METRIC = 'metric';
5858
const PARAMS__QUOTA_USAGE = 'quota_usage';
59+
const PARAMS__QUOTE_POST_ID = 'quote_post_id';
5960
const PARAMS__REDIRECT_URI = 'redirect_uri';
6061
const PARAMS__REPLY_CONFIG = 'reply_config';
6162
const PARAMS__REPLY_CONTROL = 'reply_control';
@@ -293,23 +294,46 @@ app.get('/publishingLimit', loggedInUserChecker, async (req, res) => {
293294
});
294295

295296
app.get('/upload', loggedInUserChecker, (req, res) => {
296-
const { replyToId } = req.query;
297+
const { replyToId, quotePostId } = req.query;
297298
const title = replyToId === undefined ? 'Upload' : 'Upload (Reply)';
298299
res.render('upload', {
299300
title,
300-
replyToId
301+
replyToId,
302+
quotePostId,
301303
});
302304
});
303305

306+
app.post('/repost', upload.array(), async (req, res) => {
307+
const { repostId } = req.body;
308+
309+
const repostThreadsUrl = buildGraphAPIURL(`${repostId}/repost`, {}, req.session.access_token);
310+
try {
311+
const repostResponse = await axios.post(repostThreadsUrl, {});
312+
const containerId = repostResponse.data.id;
313+
return res.redirect(`threads/${containerId}`);
314+
}
315+
catch (e) {
316+
console.error(e.message);
317+
return res.json({
318+
error: true,
319+
message: `Error during repost: ${e}`,
320+
});
321+
}
322+
});
323+
304324
app.post('/upload', upload.array(), async (req, res) => {
305-
const { text, attachmentType, attachmentUrl, attachmentAltText, replyControl, replyToId, linkAttachment } = req.body;
325+
const { text, attachmentType, attachmentUrl, attachmentAltText, replyControl, replyToId, linkAttachment, quotePostId } = req.body;
306326
const params = {
307327
[PARAMS__TEXT]: text,
308328
[PARAMS__REPLY_CONTROL]: replyControl,
309329
[PARAMS__REPLY_TO_ID]: replyToId,
310-
[PARAMS__LINK_ATTACHMENT]: linkAttachment
330+
[PARAMS__LINK_ATTACHMENT]: linkAttachment,
311331
};
312332

333+
if (quotePostId) {
334+
params[PARAMS__QUOTE_POST_ID] = quotePostId;
335+
}
336+
313337
// No attachments
314338
if (!attachmentType?.length) {
315339
params.media_type = MEDIA_TYPE__TEXT;

views/thread.pug

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,13 @@ block content
4444
td Insights
4545
td
4646
a(href=`/threads/${threadId}/insights`) View Insights
47+
tr
48+
td Quote
49+
td
50+
button(onclick=`location.href='/upload?quotePostId=${threadId}'`) Quote
51+
tr
52+
td Repost
53+
td
54+
form(action='/repost' method='post')
55+
input(type='hidden' name='repostId' value=threadId)
56+
button(type='submit') Repost

views/upload.pug

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ block content
4444
}
4545
#link-attachment {
4646
width: 200px;
47+
margin-bottom: 15px;
48+
}
49+
#quote-post-id {
50+
width: 200px;
4751
}
4852

4953
if (replyToId !== undefined)
@@ -71,6 +75,10 @@ block content
7175
| Link Attachment
7276
input#link-attachment(type='text' name='linkAttachment' value='')
7377

78+
if quotePostId
79+
a(href=`/threads/${quotePostId}`) Quoting #{quotePostId}
80+
input#quote-post-id(type='hidden' name='quotePostId' value=quotePostId)
81+
7482
input(type='hidden' name='replyToId' value=replyToId)
7583
input.threads-button(type='submit' id='submit' value='Post')
7684

0 commit comments

Comments
 (0)