FIX: Who liked was not updating

If a like streamed in via the message bus and who liked was expanded,
it was not refreshing properly.
This commit is contained in:
Robin Ward 2016-02-25 14:00:50 -05:00
parent 954ae7a08a
commit fa9943c162
4 changed files with 41 additions and 17 deletions

View File

@ -170,6 +170,10 @@ export default MountWidget.extend({
if (args) {
if (args.id) {
keyDirty(`post-${args.id}`);
if (args.refreshLikes) {
keyDirty(`post-menu-${args.id}`, { onRefresh: 'refreshLikes' });
}
} else if (args.force) {
keyDirty(`*`);
}

View File

@ -642,7 +642,7 @@ export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, {
// Unsubscribe before subscribing again
this.unsubscribe();
const refresh = (id) => this.appEvents.trigger('post-stream:refresh', { id });
const refresh = (args) => this.appEvents.trigger('post-stream:refresh', args);
this.messageBus.subscribe("/topic/" + this.get('model.id'), data => {
const topic = this.get('model');
@ -655,19 +655,20 @@ export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, {
const postStream = this.get('model.postStream');
switch (data.type) {
case "revised":
case "acted":
postStream.triggerChangedPost(data.id, data.updated_at).then(() => refresh({ id: data.id, refreshLikes: true }));
break;
case "revised":
case "rebaked": {
// TODO we could update less data for "acted" (only post actions)
postStream.triggerChangedPost(data.id, data.updated_at).then(() => refresh(data.id));
postStream.triggerChangedPost(data.id, data.updated_at).then(() => refresh({ id: data.id }));
return;
}
case "deleted": {
postStream.triggerDeletedPost(data.id, data.post_number).then(() => refresh(data.id));
postStream.triggerDeletedPost(data.id, data.post_number).then(() => refresh({ id: data.id }));
return;
}
case "recovered": {
postStream.triggerRecoveredPost(data.id, data.post_number).then(() => refresh(data.id));
postStream.triggerRecoveredPost(data.id, data.post_number).then(() => refresh({ id: data.id }));
return;
}
case "created": {

View File

@ -340,14 +340,26 @@ export default createWidget('post-menu', {
});
},
toggleWhoLiked() {
refreshLikes() {
if (this.state.likedUsers.length) {
return this.getWhoLiked();
}
},
getWhoLiked() {
const { attrs, state } = this;
return this.store.find('post-action-user', { id: attrs.id, post_action_type_id: LIKE_ACTION }).then(users => {
state.likedUsers = users.map(avatarAtts);
});
},
toggleWhoLiked() {
const state = this.state;
if (state.likedUsers.length) {
state.likedUsers = [];
} else {
return this.store.find('post-action-user', { id: attrs.id, post_action_type_id: LIKE_ACTION }).then(users => {
state.likedUsers = users.map(avatarAtts);
});
return this.getWhoLiked();
}
},
});

View File

@ -7,8 +7,8 @@ function emptyContent() { }
const _registry = {};
let _dirty = {};
export function keyDirty(key) {
_dirty[key] = true;
export function keyDirty(key, options) {
_dirty[key] = options || {};
}
export function renderedKey(key) {
@ -131,13 +131,20 @@ export default class Widget {
this.state = _.merge(this.state, this.mergeState);
}
if (prev && prev.shadowTree) {
this.shadowTree = true;
if (!_dirty[prev.key] && !_dirty['*']) {
return prev.vnode;
if (prev) {
const dirtyOpts = _dirty[prev.key] || {};
if (prev.shadowTree) {
this.shadowTree = true;
if (!dirtyOpts && !_dirty['*']) {
return prev.vnode;
}
}
renderedKey(prev.key);
const refreshAction = dirtyOpts.onRefresh;
if (refreshAction) {
this.sendWidgetAction(refreshAction);
}
}
return this.draw(h, this.attrs, this.state);