Merge pull request #67 from apamment/master

Msg area next/prev updated to use findIndex
This commit is contained in:
Bryan Ashby 2016-07-12 23:13:08 -06:00 committed by GitHub
commit 34b72d5040
1 changed files with 73 additions and 82 deletions

View File

@ -80,108 +80,99 @@ function nextMenu(callingMenu) {
function prevConf(callingMenu) { function prevConf(callingMenu) {
const confs = messageArea.getSortedAvailMessageConferences(callingMenu.client); const confs = messageArea.getSortedAvailMessageConferences(callingMenu.client);
let prev_tag = confs[confs.length - 1].confTag;
for (var i=0;i<confs.length;i++) { let curr_idx = confs.findIndex((e) => {
if (confs[i].confTag === callingMenu.client.user.properties.message_conf_tag) { if (e.confTag === callingMenu.client.user.properties.message_conf_tag) {
messageArea.changeMessageConference(callingMenu.client, prev_tag, err => { return true;
if (err) {
//...
}
return;
});
let prevMenu = callingMenu.client.menuStack.pop();
prevMenu.instance.leave();
callingMenu.client.menuStack.goto(prevMenu.name);
return;
} else {
prev_tag = confs[i].confTag;
} }
return false;
});
if (curr_idx === 0) {
curr_idx = confs.length;
} }
messageArea.changeMessageConference(callingMenu.client, confs[curr_idx - 1].confTag, err => {
if (err) {
//...
}
return;
});
let prevMenu = callingMenu.client.menuStack.pop();
prevMenu.instance.leave();
callingMenu.client.menuStack.goto(prevMenu.name);
} }
function nextConf(callingMenu) { function nextConf(callingMenu) {
const confs = messageArea.getSortedAvailMessageConferences(callingMenu.client); const confs = messageArea.getSortedAvailMessageConferences(callingMenu.client);
let prev_tag = confs[0].confTag;
if (confs.length > 1) { let curr_idx = confs.findIndex((e) => {
for (var i=1;i<confs.length;i++) { if (e.confTag === callingMenu.client.user.properties.message_conf_tag) {
if (prev_tag === callingMenu.client.user.properties.message_conf_tag) { return true;
messageArea.changeMessageConference(callingMenu.client, confs[i].confTag, err => {
if (err) {
//...
}
return;
});
let prevMenu = callingMenu.client.menuStack.pop();
prevMenu.instance.leave();
callingMenu.client.menuStack.goto(prevMenu.name);
return;
} else {
prev_tag = confs[i].confTag;
}
} }
messageArea.changeMessageConference(callingMenu.client, confs[0].confTag, err => { return false;
if (err) { });
//...
} if (curr_idx === confs.length - 1) {
let prevMenu = callingMenu.client.menuStack.pop(); curr_idx = -1;
prevMenu.instance.leave();
callingMenu.client.menuStack.goto(prevMenu.name);
return;
});
} }
messageArea.changeMessageConference(callingMenu.client, confs[curr_idx + 1].confTag, err => {
if (err) {
//...
}
return;
});
let prevMenu = callingMenu.client.menuStack.pop();
prevMenu.instance.leave();
callingMenu.client.menuStack.goto(prevMenu.name);
} }
function prevArea(callingMenu) { function prevArea(callingMenu) {
const areas = messageArea.getSortedAvailMessageAreasByConfTag(callingMenu.client.user.properties.message_conf_tag); const areas = messageArea.getSortedAvailMessageAreasByConfTag(callingMenu.client.user.properties.message_conf_tag);
let prev_tag = areas[areas.length - 1].areaTag;
for (var i=0;i<areas.length;i++) { let curr_idx = areas.findIndex((e) => {
if (areas[i].areaTag === callingMenu.client.user.properties.message_area_tag) { if (e.areaTag === callingMenu.client.user.properties.message_area_tag) {
messageArea.changeMessageArea(callingMenu.client, prev_tag, err => { return true;
if (err) {
//...
}
return;
});
let prevMenu = callingMenu.client.menuStack.pop();
prevMenu.instance.leave();
callingMenu.client.menuStack.goto(prevMenu.name);
return;
} else {
prev_tag = areas[i].areaTag;
} }
return false;
});
if (curr_idx === 0) {
curr_idx = areas.length;
} }
messageArea.changeMessageArea(callingMenu.client, areas[curr_idx - 1].areaTag, err => {
if (err) {
//...
}
return;
});
let prevMenu = callingMenu.client.menuStack.pop();
prevMenu.instance.leave();
callingMenu.client.menuStack.goto(prevMenu.name);
} }
function nextArea(callingMenu) { function nextArea(callingMenu) {
const areas = messageArea.getSortedAvailMessageAreasByConfTag(callingMenu.client.user.properties.message_conf_tag); const areas = messageArea.getSortedAvailMessageAreasByConfTag(callingMenu.client.user.properties.message_conf_tag);
let prev_tag = areas[0].areaTag;
if (areas.length > 1) { let curr_idx = areas.findIndex((e) => {
for (var i=1;i<areas.length;i++) { if (e.areaTag === callingMenu.client.user.properties.message_area_tag) {
if (prev_tag === callingMenu.client.user.properties.message_area_tag) { return true;
messageArea.changeMessageArea(callingMenu.client, areas[i].areaTag, err => {
if (err) {
//...
}
return;
});
let prevMenu = callingMenu.client.menuStack.pop();
prevMenu.instance.leave();
callingMenu.client.menuStack.goto(prevMenu.name);
return;
} else {
prev_tag = areas[i].areaTag;
}
} }
messageArea.changeMessageArea(callingMenu.client, areas[0].areaTag, err => { return false;
if (err) { });
//...
} if (curr_idx === areas.length - 1) {
let prevMenu = callingMenu.client.menuStack.pop(); curr_idx = -1;
prevMenu.instance.leave();
callingMenu.client.menuStack.goto(prevMenu.name);
return;
});
} }
messageArea.changeMessageArea(callingMenu.client, areas[curr_idx + 1].areaTag, err => {
if (err) {
//...
}
return;
});
let prevMenu = callingMenu.client.menuStack.pop();
prevMenu.instance.leave();
callingMenu.client.menuStack.goto(prevMenu.name);
} }