Refactor PollHandler
Refactor PollHandler to make it more reliable. This ended up with much more code than I expected as the original intent was just to stop a crash when switching rooms. - Using a event string was flaky, changing to using an event reference is more reliable. - Since we're only creating them from NeoChatRoom there is no need to to be able to set properties from QML so only read properties. - Pass from the MessageEventModel rather than an invokable method. - Create a basic test suite - Create properties in PollHandler to remove the need to use content in PollDelegate, this means content is no longer a required role.
This commit is contained in:
@@ -16,28 +16,23 @@ import org.kde.neochat
|
||||
MessageDelegate {
|
||||
id: root
|
||||
|
||||
/**
|
||||
* @brief The matrix message content.
|
||||
*/
|
||||
required property var content
|
||||
|
||||
/**
|
||||
* @brief The poll handler for this poll.
|
||||
*
|
||||
* This contains the required information like what the question, answers and
|
||||
* current number of votes for each is.
|
||||
*/
|
||||
property var pollHandler: currentRoom.poll(root.eventId)
|
||||
required property var pollHandler
|
||||
|
||||
bubbleContent: ColumnLayout {
|
||||
Label {
|
||||
id: questionLabel
|
||||
text: root.content["org.matrix.msc3381.poll.start"]["question"]["body"]
|
||||
text: root.pollHandler.question
|
||||
wrapMode: Text.Wrap
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
Repeater {
|
||||
model: root.content["org.matrix.msc3381.poll.start"]["answers"]
|
||||
model: root.pollHandler.options
|
||||
delegate: RowLayout {
|
||||
Layout.fillWidth: true
|
||||
CheckBox {
|
||||
@@ -51,14 +46,14 @@ MessageDelegate {
|
||||
wrapMode: Text.Wrap
|
||||
}
|
||||
Label {
|
||||
visible: root.content["org.matrix.msc3381.poll.start"]["kind"] == "org.matrix.msc3381.poll.disclosed" || pollHandler.hasEnded
|
||||
visible: root.pollHandler.kind == "org.matrix.msc3381.poll.disclosed" || pollHandler.hasEnded
|
||||
Layout.preferredWidth: contentWidth
|
||||
text: root.pollHandler.counts[modelData["id"]] ?? "0"
|
||||
}
|
||||
}
|
||||
}
|
||||
Label {
|
||||
visible: root.content["org.matrix.msc3381.poll.start"]["kind"] == "org.matrix.msc3381.poll.disclosed" || root.pollHandler.hasEnded
|
||||
visible: root.pollHandler.kind == "org.matrix.msc3381.poll.disclosed" || root.pollHandler.hasEnded
|
||||
text: i18np("Based on votes by %1 user", "Based on votes by %1 users", root.pollHandler.answerCount) + (root.pollHandler.hasEnded ? (" " + i18nc("as in 'this vote has ended'", "(Ended)")) : "")
|
||||
font.pointSize: questionLabel.font.pointSize * 0.8
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user