Skip to content

Commit

Permalink
Fix edit functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
cannawen committed Oct 24, 2017
1 parent ba9802e commit 628445c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 461 deletions.
2 changes: 1 addition & 1 deletion src/bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ function replyToMessages() {
return;
}

network.editComment('t1_' + botReply['data']['id'], reply);
network.editComment('t1_' + botReply['data']['id'], "Edit: " + reply);

if (! comment['link_id']) {
comment['link_id'] = 't3_value';
Expand Down
16 changes: 9 additions & 7 deletions src/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ function get(url) {
requestPromise = networkRequest({ url: 'https://oauth.reddit.com' + url }, true);
}

return requestPromise
.then(json => json.data.children)
return requestPromise;
}

function post(urlPath, form) {
Expand Down Expand Up @@ -135,7 +134,8 @@ function printBannedSubreddits() {

return new Promise((resolve, reject) => {
get(endpoint)
.then((messages) => {
.then(json => json.data.children)
.then(messages => {
if (messages.length > 0) {
// This call returned messages, add them to the list.
messagesList = messagesList.concat(messages);
Expand Down Expand Up @@ -181,6 +181,7 @@ function printBannedSubreddits() {

function getRedditComments(subreddit) {
return get("https://www.reddit.com/r/" + subreddit + "/comments.json?limit=100&raw_json=1")
.then(json => json.data.children)
.then((comments) => {
if (!comments) {
return;
Expand Down Expand Up @@ -218,7 +219,8 @@ function postComment(parentId, markdownBody) {

function getComment(commentId) {
return get('https://www.reddit.com/api/info.json?id=' + commentId)
.then((comment) => {
.then(json => json.data.children)
.then(comment => {
if (comment.length == 0) {
return;
}
Expand All @@ -242,18 +244,18 @@ function editComment(commentId, markdownBody) {
}

function getCommentReplies(linkId, commentId) {
return get('https://www.reddit.com/api/morechildren.json?api_type=json&link_id=' + linkId + '&children=' + commentId.replace(/t1_/g, ''))
return get('https://www.reddit.com/api/morechildren.json?api_type=json&link_id=' + linkId + '&children=' + commentId.replace(/t1_/g, '') + '&depth=1')
.then((replies) => {
if (replies.length === 0) {
return [];
}

return replies['json']['data']['things'];
});
}

function getUnreadMessages() {
return get("/message/unread?limit=100");
return get("/message/unread?limit=100")
.then(json => json.data.children);
}

function markAllMessagesAsRead() {
Expand Down
Loading

0 comments on commit 628445c

Please sign in to comment.