Close and leave polls on session leave.

This commit is contained in:
armored-dragon 2024-09-12 03:25:52 -05:00
parent 282c27ccb9
commit fe74545620
No known key found for this signature in database
GPG key ID: C7207ACC3382AD8B
2 changed files with 30 additions and 8 deletions

View file

@ -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)}`);

View file

@ -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;