Skip to content

Commit

Permalink
Post and comment replies
Browse files Browse the repository at this point in the history
  • Loading branch information
ajacksified committed May 23, 2016
1 parent 94fd95e commit a2dcad0
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 9 deletions.
10 changes: 5 additions & 5 deletions apiClient.js

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions apis/CommentsEndpoint.es6.js
@@ -1,4 +1,4 @@
import { runQuery } from '../apiBase/APIRequestUtils';
import { runQuery, save } from '../apiBase/APIRequestUtils';
import { formatBaseContentQuery } from './BaseContentEndpoint';

import { has } from 'lodash/object';
Expand Down Expand Up @@ -99,8 +99,9 @@ export default {
api_type: 'json',
thing_id: data.thingId,
text: data.text,
raw_json: 1,
};

return runQuery(apiOptions, 'post', path, postData, data, parsePostBody);
return save(apiOptions, 'post', path, postData, parsePostBody);
},
};
2 changes: 2 additions & 0 deletions models2/CommentModel.es6.js
Expand Up @@ -3,6 +3,7 @@ import Record from '../apiBase/Record';
import { COMMENT, COMMENT_LOAD_MORE } from './thingTypes';

import votable from './mixins/votable';
import replyable from './mixins/replyable';

const T = RedditModel.Types;

Expand Down Expand Up @@ -84,3 +85,4 @@ export default class CommentModel extends RedditModel {
}

votable(CommentModel);
replyable(CommentModel);
2 changes: 2 additions & 0 deletions models2/PostModel.es6.js
@@ -1,6 +1,7 @@
import RedditModel from './RedditModel';
import { POST } from './thingTypes';
import votable from './mixins/votable';
import replyable from './mixins/replyable';

const T = RedditModel.Types;

Expand Down Expand Up @@ -133,3 +134,4 @@ export default class PostModel extends RedditModel {
}

votable(PostModel);
replyable(PostModel);
13 changes: 13 additions & 0 deletions models2/mixins/replyable.js
@@ -0,0 +1,13 @@
import mixin from './mixin';
import comment from '../../apis/CommentsEndpoint';

export function reply (apiOptions, text) {
const oldModel = this;

return comment.post(apiOptions, {
thingId: this.uuid,
text,
});
};

export default (cls) => mixin(cls, { reply });
2 changes: 0 additions & 2 deletions models2/mixins/votable.js
Expand Up @@ -16,7 +16,6 @@ export function _vote (apiOptions, direction) {

const stub = this.stub('likes', direction, async (resolve, reject) => {
try {
const data = { comment: oldModel.name };
const endpoint = direction === 0 ? votes.del : votes.post;
await endpoint(apiOptions, { thingId: oldModel.name, direction });
return stub;
Expand All @@ -30,4 +29,3 @@ export function _vote (apiOptions, direction) {
};

export default (cls) => mixin(cls, { upvote, downvote, _vote });

0 comments on commit a2dcad0

Please sign in to comment.