gitlab-org--gitlab-foss/app/assets/javascripts/diff_notes/stores/comments.js.es6

60 lines
1.7 KiB
JavaScript
Raw Normal View History

2016-07-26 06:56:36 -04:00
((w) => {
w.CommentsStore = {
state: {},
loading: {},
get: function (discussionId, noteId) {
return this.state[discussionId][noteId];
},
create: function (discussionId, noteId, resolved, user) {
2016-07-26 06:56:36 -04:00
if (!this.state[discussionId]) {
Vue.set(this.state, discussionId, {});
Vue.set(this.loading, discussionId, false);
}
Vue.set(this.state[discussionId], noteId, { resolved, user});
2016-07-26 06:56:36 -04:00
},
update: function (discussionId, noteId, resolved, user) {
this.state[discussionId][noteId].resolved = resolved;
this.state[discussionId][noteId].user = user;
2016-07-26 06:56:36 -04:00
},
delete: function (discussionId, noteId) {
Vue.delete(this.state[discussionId], noteId);
if (Object.keys(this.state[discussionId]).length === 0) {
Vue.delete(this.state, discussionId);
Vue.delete(this.loading, discussionId);
}
},
updateCommentsForDiscussion: function (discussionId, resolve, user) {
const noteIds = CommentsStore.resolvedNotesForDiscussion(discussionId, resolve);
for (let i = 0; i < noteIds.length; i++) {
const noteId = noteIds[i];
CommentsStore.update(discussionId, noteId, resolve, user);
}
},
notesForDiscussion: function (discussionId) {
let ids = [];
for (const noteId in CommentsStore.state[discussionId]) {
ids.push(noteId);
}
return ids;
},
resolvedNotesForDiscussion: function (discussionId, resolve) {
let ids = [];
for (const noteId in CommentsStore.state[discussionId]) {
const resolved = CommentsStore.state[discussionId][noteId].resolved;
if (resolved !== resolve) {
ids.push(noteId);
}
}
return ids;
}
2016-07-26 06:56:36 -04:00
};
}(window));