mirror of
https://github.com/AleziaKurdis/Overte-community-apps.git
synced 2025-04-05 13:37:41 +02:00
Close and leave polls on session leave.
This commit is contained in:
parent
282c27ccb9
commit
fe74545620
2 changed files with 30 additions and 8 deletions
|
@ -14,9 +14,9 @@
|
|||
// TODO: Documentation
|
||||
// FIXME: Handle ties: kill both of tied results
|
||||
|
||||
// TODO: Joining poll sometimes causes to double stack on other clients poll_list?
|
||||
// TODO: Do active polls persist across domain leave? If so close them on session leave
|
||||
// FIXME: Empty arrays in responses don't count as valid votes anymore? Causes miscounts?
|
||||
// FIXME: Host closes window does not return them to client view when applicable
|
||||
// FIXME: Sound playing on every user join.
|
||||
|
||||
(() => {
|
||||
"use strict";
|
||||
|
@ -50,6 +50,8 @@
|
|||
deletePoll(true);
|
||||
});
|
||||
|
||||
AvatarList.avatarSessionChangedEvent.connect(_resetNetworking);
|
||||
|
||||
// Overlay button toggle
|
||||
appButton.clicked.connect(toolbarButtonClicked);
|
||||
tablet.fromQml.connect(fromQML);
|
||||
|
@ -143,7 +145,7 @@
|
|||
_emitEvent({type: "close_poll", poll: {id: poll.id}, change_page: true});
|
||||
|
||||
// Clear our active poll data
|
||||
poll = { host: '', title: '', description: '', id: '', question: '', options: []};
|
||||
_resetNetworking();
|
||||
}
|
||||
|
||||
// Join an existing poll hosted by another user
|
||||
|
@ -168,13 +170,12 @@
|
|||
|
||||
// Leave a poll hosted by another user
|
||||
function leavePoll() {
|
||||
if (!poll.id) return; // No poll to leave
|
||||
|
||||
let pollToLeave = poll.id;
|
||||
|
||||
// Unsubscribe from message mixer for poll information
|
||||
Messages.unsubscribe(poll.id);
|
||||
|
||||
// Clear poll
|
||||
poll = {id: '', host: ''};
|
||||
_resetNetworking();
|
||||
|
||||
console.log(`Successfully left ${pollToLeave}`);
|
||||
}
|
||||
|
@ -297,6 +298,16 @@
|
|||
}
|
||||
}
|
||||
|
||||
// Reset application "networking" information to default values
|
||||
function _resetNetworking(){
|
||||
if (poll.id) Messages.unsubscribe(poll.id);
|
||||
|
||||
poll = {id: '', title: '', description: '', host: '', question: '', options: [], host_can_vote: false};
|
||||
responses = {};
|
||||
electionIterations = 0;
|
||||
activePolls = [];
|
||||
}
|
||||
|
||||
// Communication
|
||||
function fromQML(event) {
|
||||
console.log(`New QML event:\n${JSON.stringify(event)}`);
|
||||
|
|
|
@ -515,7 +515,7 @@ Rectangle {
|
|||
Text {
|
||||
id: poll_winner
|
||||
width: parent.width
|
||||
text: "Me"
|
||||
text: "---"
|
||||
color: "white"
|
||||
font.pointSize: 20
|
||||
wrapMode: Text.NoWrap
|
||||
|
@ -864,6 +864,13 @@ Rectangle {
|
|||
}
|
||||
}
|
||||
|
||||
function _clearResults(){
|
||||
poll_winner.text = "---"
|
||||
tally_votes_itterations.text = "-"
|
||||
tally_votes_counted.text = "-"
|
||||
tally_votes_received.text = "0"
|
||||
}
|
||||
|
||||
// Messages from script
|
||||
function fromScript(message) {
|
||||
switch (message.type){
|
||||
|
@ -899,6 +906,10 @@ Rectangle {
|
|||
console.log("adding option "+ option);
|
||||
poll_option_model.append({option: option, rank: 0})
|
||||
}
|
||||
|
||||
// Clear the results page
|
||||
_clearResults()
|
||||
|
||||
// Set the options
|
||||
break;
|
||||
|
||||
|
|
Loading…
Reference in a new issue