Skip to content

Commit c5fd78d

Browse files
authored
Merge pull request #21 from fbsamples/my-replies
Replies
2 parents cf98058 + a779a1f commit c5fd78d

2 files changed

Lines changed: 53 additions & 1 deletion

File tree

src/index.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,57 @@ app.get('/threads', loggedInUserChecker, async (req, res) => {
507507
});
508508
});
509509

510+
app.get('/replies', loggedInUserChecker, async (req, res) => {
511+
const { before, after, limit } = req.query;
512+
const params = {
513+
[PARAMS__FIELDS]: [
514+
FIELD__TEXT,
515+
FIELD__MEDIA_TYPE,
516+
FIELD__MEDIA_URL,
517+
FIELD__PERMALINK,
518+
FIELD__TIMESTAMP,
519+
FIELD__REPLY_AUDIENCE,
520+
].join(','),
521+
limit: limit ?? DEFAULT_THREADS_QUERY_LIMIT,
522+
};
523+
if (before) {
524+
params.before = before;
525+
}
526+
if (after) {
527+
params.after = after;
528+
}
529+
530+
let threads = [];
531+
let paging = {};
532+
533+
const queryRepliesUrl = buildGraphAPIURL(`me/replies`, params, req.session.access_token);
534+
535+
try {
536+
const queryResponse = await axios.get(queryRepliesUrl);
537+
threads = queryResponse.data.data;
538+
539+
if (queryResponse.data.paging) {
540+
const { next, previous } = queryResponse.data.paging;
541+
542+
if (next) {
543+
paging.nextUrl = getCursorUrlFromGraphApiPagingUrl(req, next);
544+
}
545+
546+
if (previous) {
547+
paging.previousUrl = getCursorUrlFromGraphApiPagingUrl(req, previous);
548+
}
549+
}
550+
} catch (e) {
551+
console.error(e?.response?.data?.error?.message ?? e.message);
552+
}
553+
554+
res.render('threads', {
555+
paging,
556+
threads,
557+
title: 'My Replies',
558+
});
559+
});
560+
510561
app.get('/threads/:threadId/replies', loggedInUserChecker, (req, res) => {
511562
showReplies(req, res, true);
512563
});

views/account.pug

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ block content
1212

1313
.button-group
1414
button(onclick="location.href='/upload'") Publish
15-
button(onclick="location.href='/threads'") Read
15+
button(onclick="location.href='/threads'") My Threads
16+
button(onclick="location.href='/replies'") My Replies
1617
button(onclick="location.href='/userInsights'") Insights
1718
button(onclick="location.href='/publishingLimit'") Publishing Limit

0 commit comments

Comments
 (0)