Skip to content

Commit

Permalink
Update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
changhc committed Dec 29, 2019
1 parent 52db428 commit 7968268
Show file tree
Hide file tree
Showing 10 changed files with 605 additions and 150 deletions.
648 changes: 564 additions & 84 deletions package-lock.json

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"devDependencies": {
"@babel/cli": "^7.6.0",
"@babel/core": "^7.6.0",
"@babel/node": "^7.7.7",
"@babel/plugin-proposal-class-properties": "^7.5.5",
"@babel/plugin-proposal-json-strings": "^7.2.0",
"@babel/plugin-syntax-dynamic-import": "^7.2.0",
Expand All @@ -46,11 +47,11 @@
"babel-jest": "^24.9.0",
"coveralls": "^3.0.0",
"eslint": "^6.8.0",
"eslint-config-prettier": "^2.0.0",
"eslint-plugin-import": "^2.2.0",
"eslint-plugin-prettier": "^2.0.1",
"eslint-config-prettier": "^6.9.0",
"eslint-plugin-import": "^2.19.1",
"eslint-plugin-prettier": "^3.1.2",
"jest-cli": "^24.9.0",
"prettier": "=1.12.1",
"prettier": "^1.19.1",
"ttag-cli": "^1.7.27"
},
"jest": {
Expand Down
21 changes: 10 additions & 11 deletions src/fbClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export async function pagePublicContentAccess(postId) {

let msg = '';
for (let field of fields) {
if (results.hasOwnProperty(field)) {
if (Object.prototype.hasOwnProperty.call(results, field)) {
msg += `${results[field]}\n`;
}
}
Expand Down Expand Up @@ -179,26 +179,24 @@ export async function replyToComment(commentId, msg) {
* @returns {Promise} Promise wrapping a request for long-lived tokens
*/
export function getLongLivedPageAccessToken() {
return new Promise(async (resolve, reject) => {
return new Promise((resolve, reject) => {
if (process.env.APP_ID === undefined) {
reject(new Error(`Invalid page id: ${process.env.APP_ID}`));
return;
}

let token = process.env.PAGE_ACCESS_TOKEN;
const redisToken = await redis.get('pageAccessToken');
const redisToken = Promise.resolve(redis.get('pageAccessToken'));
if (redisToken) {
token = redisToken;
}

fetch(
`${URL}/oauth/access_token?grant_type=fb_exchange_token&client_id=${
process.env.APP_ID
}&client_secret=${process.env.APP_SECRET}&fb_exchange_token=${token}`
`${URL}/oauth/access_token?grant_type=fb_exchange_token&client_id=${process.env.APP_ID}&client_secret=${process.env.APP_SECRET}&fb_exchange_token=${token}`
)
.then(res => res.json())
.then(res => {
if (!res.hasOwnProperty('access_token')) {
if (!Object.prototype.hasOwnProperty.call(res, 'access_token')) {
throw new Error(
'Failed to get a page access token: ' + JSON.stringify(res)
);
Expand All @@ -223,13 +221,14 @@ export async function checkCommentCommentable(commentId) {
return false;
}
const resp = await fetch(
`${URL}/${graphApiVersion}/${commentId}?access_token=${
process.env.PAGE_ACCESS_TOKEN
}&fields=can_comment`,
`${URL}/${graphApiVersion}/${commentId}?access_token=${process.env.PAGE_ACCESS_TOKEN}&fields=can_comment`,
{ method: 'POST' }
);
const results = await resp.json();
if (resp.status !== 200 || !results.hasOwnProperty('can_comment')) {
if (
resp.status !== 200 ||
!Object.prototype.hasOwnProperty.call(results, 'can_comment')
) {
console.error(
'Error when fetching comment meta: ' + JSON.stringify(results, null, ' ')
);
Expand Down
8 changes: 2 additions & 6 deletions src/handlers/askingReplyRequestReason.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,8 @@ export default async function askingArticleSubmission(params) {
type: 'text',
content: {
text: ngettext(
msgid`We've recorded your reason. ${
CreateReplyRequest.replyRequestCount
} other user is also waiting for clarification. Please refer to this page for updates: ${articleUrl}`,
`We've recorded your reason. ${
CreateReplyRequest.replyRequestCount
} other users are also waiting for clarification. Please refer to this page for updates: ${articleUrl}`,
msgid`We've recorded your reason. ${CreateReplyRequest.replyRequestCount} other user is also waiting for clarification. Please refer to this page for updates: ${articleUrl}`,
`We've recorded your reason. ${CreateReplyRequest.replyRequestCount} other users are also waiting for clarification. Please refer to this page for updates: ${articleUrl}`,
CreateReplyRequest.replyRequestCount
),
},
Expand Down
16 changes: 4 additions & 12 deletions src/handlers/askingReplyRequestSubmission.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,8 @@ export default async function askingArticleSubmission(params) {
type: 'text',
content: {
text: ngettext(
msgid`We've recorded your reason. ${
CreateReplyRequest.replyRequestCount
} other user is also waiting for clarification. Please refer to this page for updates: ${articleUrl}`,
`We've recorded your reason. ${
CreateReplyRequest.replyRequestCount
} other users are also waiting for clarification. Please refer to this page for updates: ${articleUrl}`,
msgid`We've recorded your reason. ${CreateReplyRequest.replyRequestCount} other user is also waiting for clarification. Please refer to this page for updates: ${articleUrl}`,
`We've recorded your reason. ${CreateReplyRequest.replyRequestCount} other users are also waiting for clarification. Please refer to this page for updates: ${articleUrl}`,
CreateReplyRequest.replyRequestCount
),
},
Expand All @@ -61,12 +57,8 @@ export default async function askingArticleSubmission(params) {
type: 'text',
content: {
text: ngettext(
msgid`We've recorded your reason. ${
CreateReplyRequest.replyRequestCount
} other user is also waiting for clarification. Please refer to this page for updates: ${articleUrl}`,
`We've recorded your reason. ${
CreateReplyRequest.replyRequestCount
} other users are also waiting for clarification. Please refer to this page for updates: ${articleUrl}`,
msgid`We've recorded your reason. ${CreateReplyRequest.replyRequestCount} other user is also waiting for clarification. Please refer to this page for updates: ${articleUrl}`,
`We've recorded your reason. ${CreateReplyRequest.replyRequestCount} other users are also waiting for clarification. Please refer to this page for updates: ${articleUrl}`,
CreateReplyRequest.replyRequestCount
),
},
Expand Down
8 changes: 2 additions & 6 deletions src/handlers/choosingArticle.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ export default async function choosingArticle(params) {
{
type: 'text',
content: {
text: t`Please enter 1~${
data.foundArticleIds.length
} to choose a reply.`,
text: t`Please enter 1~${data.foundArticleIds.length} to choose a reply.`,
},
},
];
Expand Down Expand Up @@ -138,9 +136,7 @@ export default async function choosingArticle(params) {
' ⭕\n' +
t`${count.OPINIONATED} person(s) think this is simply personal opinion` +
' 💬\n' +
t`${
count.NOT_ARTICLE
} person(s) thinks it's off-topic and Cofacts need not to handle this message` +
t`${count.NOT_ARTICLE} person(s) thinks it's off-topic and Cofacts need not to handle this message` +
' ⚠️️\n';

replies = [
Expand Down
4 changes: 1 addition & 3 deletions src/handlers/choosingReply.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ export default async function choosingReply(params) {
{
type: 'text',
content: {
text: t`Please enter 1~${
data.foundReplyIds.length
} to choose a reply.`,
text: t`Please enter 1~${data.foundReplyIds.length} to choose a reply.`,
},
},
];
Expand Down
28 changes: 7 additions & 21 deletions src/handlers/initState.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,32 +129,22 @@ export default async function initState(params) {

const rumorSummary = count.RUMOR
? ngettext(
msgid`${
count.RUMOR
} user considers that this contains misinformation`,
msgid`${count.RUMOR} user considers that this contains misinformation`,
`${count.RUMOR} users consider that this contains misinformation`,
count.RUMOR
) + ' ❌\n'
: '';
const notRumorSummary = count.NOT_RUMOR
? ngettext(
msgid`${
count.NOT_RUMOR
} user thinks that this contains true information`,
`${
count.NOT_RUMOR
} users think that this contains true information`,
msgid`${count.NOT_RUMOR} user thinks that this contains true information`,
`${count.NOT_RUMOR} users think that this contains true information`,
count.NOT_RUMOR
) + ' ⭕\n'
: '';
const opinionatedSummary = count.OPINIONATED
? ngettext(
msgid`${
count.OPINIONATED
} user thinks that this is simply a personal opinion`,
`${
count.OPINIONATED
} users think that this is simply a personal opinion`,
msgid`${count.OPINIONATED} user thinks that this is simply a personal opinion`,
`${count.OPINIONATED} users think that this is simply a personal opinion`,
count.OPINIONATED
) + ' 💬\n'
: '';
Expand All @@ -168,12 +158,8 @@ export default async function initState(params) {
if (count.NOT_ARTICLE) {
const notArticleSummary =
ngettext(
msgid`but ${
count.NOT_ARTICLE
} user thinks that this is off-topic and Cofacts need not to handle it`,
`but ${
count.NOT_ARTICLE
} users think that this is off-topic and Cofacts need not to handle it`,
msgid`but ${count.NOT_ARTICLE} user thinks that this is off-topic and Cofacts need not to handle it`,
`but ${count.NOT_ARTICLE} users think that this is off-topic and Cofacts need not to handle it`,
count.NOT_ARTICLE
) + '\n';
summary += notArticleSummary;
Expand Down
8 changes: 6 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ const groupHandler = async (req, type, replyToken, userId, otherFields) => {

router.post('*', checkSignatureAndParse);
router.post('/callback', ctx => {
if (ctx.request.body.entry[0].hasOwnProperty('changes')) {
if (
Object.prototype.hasOwnProperty.call(ctx.request.body.entry[0], 'changes')
) {
const messageInstances = ctx.request.body.entry[0].changes;
messageInstances.forEach(instance => {
if (
Expand All @@ -46,7 +48,9 @@ router.post('/callback', ctx => {
mentionEventHandler(ctx.request, instance);
});
ctx.status = 200;
} else if (ctx.request.body.entry[0].hasOwnProperty('messaging')) {
} else if (
Object.prototype.hasOwnProperty.call(ctx.request.body.entry[0], 'messaging')
) {
// uncomment to enable chatbot
const messageInstances = ctx.request.body.entry[0].messaging;
messageInstances.forEach(instance => {
Expand Down
5 changes: 4 additions & 1 deletion src/mentionEventHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import handleInput from './handleInput';
* @param {object} instance message instance
*/
const mentionEventHandler = async (context, instance) => {
if (!instance.value || !instance.value.hasOwnProperty('post_id')) {
if (
!instance.value ||
!Object.prototype.hasOwnProperty.call(instance.value, 'post_id')
) {
return;
}
// Track reported page whenever mentioned
Expand Down

0 comments on commit 7968268

Please sign in to comment.