|
|
@@ -34,6 +34,7 @@ export default class CommentContainer extends Container {
|
|
|
};
|
|
|
|
|
|
this.retrieveComments = this.retrieveComments.bind(this);
|
|
|
+ this.checkAndUpdateImageOfCommentAuthers = this.checkAndUpdateImageOfCommentAuthers.bind(this);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -62,17 +63,37 @@ export default class CommentContainer extends Container {
|
|
|
/**
|
|
|
* Load data of comments and store them in state
|
|
|
*/
|
|
|
- retrieveComments() {
|
|
|
- // [TODO][GW - 1942] add method for updating imageUrlCached
|
|
|
+ async retrieveComments() {
|
|
|
const { pageId } = this.getPageContainer().state;
|
|
|
|
|
|
// get data (desc order array)
|
|
|
- return this.appContainer.apiGet('/comments.get', { page_id: pageId })
|
|
|
- .then((res) => {
|
|
|
- if (res.ok) {
|
|
|
- this.setState({ comments: res.comments });
|
|
|
- }
|
|
|
- });
|
|
|
+ const res = await this.appContainer.apiGet('/comments.get', { page_id: pageId });
|
|
|
+ if (res.ok) {
|
|
|
+ const comments = res.comments;
|
|
|
+ this.setState({ comments });
|
|
|
+
|
|
|
+ this.checkAndUpdateImageOfCommentAuthers(comments);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ async checkAndUpdateImageOfCommentAuthers(comments) {
|
|
|
+ const noImageCacheUserIds = comments.filter((comment) => {
|
|
|
+ return comment.creator.imageUrlCached == null;
|
|
|
+ }).map((comment) => {
|
|
|
+ return comment.creator._id;
|
|
|
+ });
|
|
|
+
|
|
|
+ if (noImageCacheUserIds.length === 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ await this.appContainer.apiv3Put('/users/update.imageUrlCache', { userIds: noImageCacheUserIds });
|
|
|
+ }
|
|
|
+ catch (err) {
|
|
|
+ // Error alert doesn't apear, because user don't need to notice this error.
|
|
|
+ logger.error(err);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|