提交 7b093581 编写于 作者: F Filipa Lacerda

[ci skip] Fix emoji being posted twice originating an error

上级 d8ebcb74
......@@ -119,6 +119,7 @@
class="note timeline-entry"
:id="noteAnchorId"
:class="classNameBindings"
:data-award-url="note.toggle_award_path"
:note-id="note.id">
<div class="timeline-entry-inner">
<div class="timeline-icon">
......
......@@ -52,7 +52,12 @@
// We need to do this otherwise we will render the same emoji over and over again.
groupedAwards() {
const awards = this.awards.reduce((acc, award) => {
if (acc.hasOwnProperty(award.name)) {
acc[award.name].push(award);
} else {
Object.assign(acc, {[award.name]: [award]});
}
return acc;
}, {});
......@@ -67,6 +72,7 @@
orderedAwards.thumbsdown = thumbsdown;
delete awards.thumbsdown;
}
return Object.assign({}, orderedAwards, awards);
},
isAuthoredByMe() {
......@@ -75,7 +81,7 @@
},
methods: {
...mapActions([
'toggleAward',
'toggleAwardRequest',
]),
getAwardHTML(name) {
return Emoji.glEmojiTag(name);
......@@ -147,7 +153,7 @@
awardName: awardName === "100" ? 100: awardName,
};
this.toggleAward(data)
this.toggleAwardRequest(data)
.catch(() => Flash('Something went wrong on our end.'));
},
},
......
......@@ -99,10 +99,8 @@
bindEventHubListeners() {
this.$el.parentElement.addEventListener('toggleAward', (event) => {
const { awardName, noteId } = event.detail;
const endpoint = this.notesById[noteId].toggle_award_path;
this.actionToggleAward({ awardName, noteId })
this.actionToggleAward({ endpoint, awardName, noteId })
.catch((error) => Flash('Something went wrong on our end.'));
});
// JQuery is needed here because it is a custom event being dispatched with jQuery.
......
......@@ -174,7 +174,7 @@ export const poll = ({ commit, state, getters }) => {
if (!Visibility.hidden()) {
eTagPoll.makeRequest();
} else {
this.service.poll(requestData);
service.poll(requestData);
}
Visibility.change(() => {
......@@ -186,38 +186,17 @@ export const poll = ({ commit, state, getters }) => {
});
};
export const toggleAward = ({ commit, getters, dispatch }, data) => {
const { endpoint, awardName, noteId, skipMutalityCheck } = data;
const note = getters.notesById[noteId];
export const toggleAward = ({ commit, state, getters, dispatch }, { awardName, noteId }) => {
commit(types.TOGGLE_AWARD, { awardName, note: getters.notesById[noteId] });
};
export const toggleAwardRequest = ({ commit, getters, dispatch }, data) => {
const { endpoint, awardName } = data;
return service
.toggleAward(endpoint, { name: awardName })
.then(res => res.json())
.then(() => {
commit(types.TOGGLE_AWARD, { awardName, note });
if (!skipMutalityCheck &&
(awardName === constants.EMOJI_THUMBSUP || awardName === constants.EMOJI_THUMBSDOWN)) {
const counterAward = awardName === constants.EMOJI_THUMBSUP ?
constants.EMOJI_THUMBSDOWN :
constants.EMOJI_THUMBSUP;
const targetNote = getters.notesById[noteId];
let noteHasAwardByCurrentUser = false;
targetNote.award_emoji.forEach((a) => {
if (a.name === counterAward && a.user.id === window.gon.current_user_id) {
noteHasAwardByCurrentUser = true;
}
});
if (noteHasAwardByCurrentUser) {
Object.assign(data, { awardName: counterAward });
Object.assign(data, { skipMutalityCheck: true });
dispatch(types.TOGGLE_AWARD, data);
}
}
dispatch('toggleAward', data);
});
};
......
......@@ -102,16 +102,13 @@ export default {
[types.TOGGLE_AWARD](state, data) {
const { awardName, note } = data;
const { id, name, username } = state.userData;
let index = -1;
note.award_emoji.forEach((a, i) => {
if (a.name === awardName && a.user.id === id) {
index = i;
}
});
const hasEmojiAwardedByCurrentUser = note.award_emoji
.filter(emoji => emoji.name === data.awardName && emoji.user.id === id);
if (index > -1) { // If current user has awarded this emoji, remove it.
note.award_emoji.splice(index, 1);
if (hasEmojiAwardedByCurrentUser.length) {
// If current user has awarded this emoji, remove it.
note.award_emoji.splice(note.award_emoji.indexOf(hasEmojiAwardedByCurrentUser[0]), 1);
} else {
note.award_emoji.push({
name: awardName,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册