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:
parent
954ae7a08a
commit
fa9943c162
|
@ -170,6 +170,10 @@ export default MountWidget.extend({
|
||||||
if (args) {
|
if (args) {
|
||||||
if (args.id) {
|
if (args.id) {
|
||||||
keyDirty(`post-${args.id}`);
|
keyDirty(`post-${args.id}`);
|
||||||
|
|
||||||
|
if (args.refreshLikes) {
|
||||||
|
keyDirty(`post-menu-${args.id}`, { onRefresh: 'refreshLikes' });
|
||||||
|
}
|
||||||
} else if (args.force) {
|
} else if (args.force) {
|
||||||
keyDirty(`*`);
|
keyDirty(`*`);
|
||||||
}
|
}
|
||||||
|
|
|
@ -642,7 +642,7 @@ export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, {
|
||||||
// Unsubscribe before subscribing again
|
// Unsubscribe before subscribing again
|
||||||
this.unsubscribe();
|
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 => {
|
this.messageBus.subscribe("/topic/" + this.get('model.id'), data => {
|
||||||
const topic = this.get('model');
|
const topic = this.get('model');
|
||||||
|
@ -655,19 +655,20 @@ export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, {
|
||||||
|
|
||||||
const postStream = this.get('model.postStream');
|
const postStream = this.get('model.postStream');
|
||||||
switch (data.type) {
|
switch (data.type) {
|
||||||
case "revised":
|
|
||||||
case "acted":
|
case "acted":
|
||||||
|
postStream.triggerChangedPost(data.id, data.updated_at).then(() => refresh({ id: data.id, refreshLikes: true }));
|
||||||
|
break;
|
||||||
|
case "revised":
|
||||||
case "rebaked": {
|
case "rebaked": {
|
||||||
// TODO we could update less data for "acted" (only post actions)
|
postStream.triggerChangedPost(data.id, data.updated_at).then(() => refresh({ id: data.id }));
|
||||||
postStream.triggerChangedPost(data.id, data.updated_at).then(() => refresh(data.id));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
case "deleted": {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
case "recovered": {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
case "created": {
|
case "created": {
|
||||||
|
|
|
@ -340,14 +340,26 @@ export default createWidget('post-menu', {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
toggleWhoLiked() {
|
refreshLikes() {
|
||||||
|
if (this.state.likedUsers.length) {
|
||||||
|
return this.getWhoLiked();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
getWhoLiked() {
|
||||||
const { attrs, state } = this;
|
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) {
|
if (state.likedUsers.length) {
|
||||||
state.likedUsers = [];
|
state.likedUsers = [];
|
||||||
} else {
|
} else {
|
||||||
return this.store.find('post-action-user', { id: attrs.id, post_action_type_id: LIKE_ACTION }).then(users => {
|
return this.getWhoLiked();
|
||||||
state.likedUsers = users.map(avatarAtts);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -7,8 +7,8 @@ function emptyContent() { }
|
||||||
const _registry = {};
|
const _registry = {};
|
||||||
let _dirty = {};
|
let _dirty = {};
|
||||||
|
|
||||||
export function keyDirty(key) {
|
export function keyDirty(key, options) {
|
||||||
_dirty[key] = true;
|
_dirty[key] = options || {};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function renderedKey(key) {
|
export function renderedKey(key) {
|
||||||
|
@ -131,13 +131,20 @@ export default class Widget {
|
||||||
this.state = _.merge(this.state, this.mergeState);
|
this.state = _.merge(this.state, this.mergeState);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (prev && prev.shadowTree) {
|
if (prev) {
|
||||||
this.shadowTree = true;
|
const dirtyOpts = _dirty[prev.key] || {};
|
||||||
if (!_dirty[prev.key] && !_dirty['*']) {
|
if (prev.shadowTree) {
|
||||||
return prev.vnode;
|
this.shadowTree = true;
|
||||||
|
if (!dirtyOpts && !_dirty['*']) {
|
||||||
|
return prev.vnode;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
renderedKey(prev.key);
|
renderedKey(prev.key);
|
||||||
|
|
||||||
|
const refreshAction = dirtyOpts.onRefresh;
|
||||||
|
if (refreshAction) {
|
||||||
|
this.sendWidgetAction(refreshAction);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.draw(h, this.attrs, this.state);
|
return this.draw(h, this.attrs, this.state);
|
||||||
|
|
Loading…
Reference in New Issue