Skip to content
Snippets Groups Projects
Commit 55d89ee7 authored by Guido Berhoerster's avatar Guido Berhoerster
Browse files

Add support for groups in results

parent 934d55af
No related branches found
No related tags found
No related merge requests found
......@@ -106,7 +106,7 @@ class Result {
}
}
class Results {
class GroupResults {
constructor({agree: agree = [], disagree: disagree = []} = {}) {
this.agree = [];
this.disagree = [];
......@@ -119,6 +119,16 @@ class Results {
}
}
class Results {
constructor({majority: majority = {}, groups: groups = []} = {}) {
this.majority = new GroupResults(majority);
this.groups = [];
for (const o of groups) {
this.groups.push(new GroupResults(o));
}
}
}
class Notifications {
constructor({enabled = false, email = null}) {
this.enabled = enabled;
......@@ -354,18 +364,34 @@ export class ConversationClient {
const results = await this.#fetchResults(
{signal: options.signal}
);
if (results.agree.length !== this.results.agree.length ||
results.disagree.length !== this.results.disagree.length) {
function groupResultChanged(oldGroup, newGroup) {
if (newGroup.agree.length !== oldGroup.agree.length ||
newGroup.disagree.length !== oldGroup.disagree.length) {
return true;
}
for (let type of ["agree", "disagree"]) {
for (let i = 0; i < newGroup[type].length; i++) {
if (newGroup[type][i].statementID !== oldGroup[type][i].statementID ||
newGroup[type][i].value !== oldGroup[type][i].value) {
return true;
}
}
}
return false;
}
if (groupResultChanged(results.majority, this.results.majority)) {
this.results = results;
return true;
}
for (let type of ["agree", "disagree"]) {
for (let i = 0; i < results[type].length; i++) {
if (results[type][i].statementID !== this.results[type][i].statementID ||
results[type][i].value !== this.results[type][i].value) {
this.results = results;
return true;
}
if (results.groups.length !== this.results.groups.length) {
this.results = results;
return true;
}
for (let i = 0; i < results.groups.length; i++) {
if (groupResultChanged(results.groups[i], this.results.groups[i])) {
this.results = results;
return true;
}
}
return false;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment