Implement sending Quiz explanations

TDLib 1.7 feature
This commit is contained in:
John Gibbon 2021-01-22 11:12:12 +01:00
parent c5640ec13f
commit e6e63622e5
14 changed files with 165 additions and 5 deletions

View file

@ -39,6 +39,7 @@ Dialog {
property alias quiz: quizSwitch.checked property alias quiz: quizSwitch.checked
property alias multiple: multipleSwitch.checked property alias multiple: multipleSwitch.checked
property string replyToMessageId: "0" property string replyToMessageId: "0"
property alias quizExplanation: quizExplanationTextArea.text
// poll request data end // poll request data end
canAccept: validationErrors.length === 0 canAccept: validationErrors.length === 0
@ -81,6 +82,9 @@ Dialog {
if(quiz && (correctOption < 0 || correctOption > options.count - 1)) { if(quiz && (correctOption < 0 || correctOption > options.count - 1)) {
errors.push(qsTr("To send a quiz, you have to specify the right answer.")); errors.push(qsTr("To send a quiz, you have to specify the right answer."));
} }
if(quiz && quizExplanationTextArea.hasError) {
errors.push(qsTr("An explanation can be up to 200 characters long."));
}
if(errors.length === 0) { if(errors.length === 0) {
validationErrorsVisible = false; validationErrorsVisible = false;
} }
@ -333,6 +337,25 @@ Dialog {
} }
description: qsTr("Quizzes have one correct answer. Participants can't revoke their responses.") description: qsTr("Quizzes have one correct answer. Participants can't revoke their responses.")
} }
TextArea {
id: quizExplanationTextArea
width: parent.width
opacity: pollCreationPage.quiz ? 1.0 : 0.0
Behavior on opacity { FadeAnimation {} }
height: pollCreationPage.quiz ? implicitHeight : 0
Behavior on height { NumberAnimation { duration: quizExplanationTextArea.focus ? 0 : 200 } }
visible: opacity > 0
placeholderText: qsTr("Enter an optional explanation")
property int charactersLeft: 200 - text.length
property bool hasError: charactersLeft < 0
color: hasError ? Theme.errorColor : Theme.highlightColor
label: qsTr("Shown when the user selects a wrong answer.")
wrapMode: TextEdit.Wrap
onFocusChanged: {
validate();
}
}
} }
} }
@ -342,7 +365,7 @@ Dialog {
optionsArr.push(options.get(i).text); optionsArr.push(options.get(i).text);
} }
tdLibWrapper.sendPollMessage(chatId, pollQuestion, optionsArr, anonymous, quiz ? correctOption : -1, multiple, "0"); tdLibWrapper.sendPollMessage(chatId, pollQuestion, optionsArr, anonymous, quiz ? correctOption : -1, multiple, quizExplanation, "0");
} }

View file

@ -569,7 +569,7 @@ void TDLibWrapper::sendStickerMessage(const QString &chatId, const QString &file
this->sendRequest(requestObject); this->sendRequest(requestObject);
} }
void TDLibWrapper::sendPollMessage(const QString &chatId, const QString &question, const QVariantList &options, bool anonymous, int correctOption, bool multiple, const QString &replyToMessageId) void TDLibWrapper::sendPollMessage(const QString &chatId, const QString &question, const QVariantList &options, bool anonymous, int correctOption, bool multiple, const QString &explanation, const QString &replyToMessageId)
{ {
LOG("Sending poll message" << chatId << question << replyToMessageId); LOG("Sending poll message" << chatId << question << replyToMessageId);
QVariantMap requestObject; QVariantMap requestObject;
@ -585,6 +585,11 @@ void TDLibWrapper::sendPollMessage(const QString &chatId, const QString &questio
if(correctOption > -1) { if(correctOption > -1) {
pollType.insert(_TYPE, "pollTypeQuiz"); pollType.insert(_TYPE, "pollTypeQuiz");
pollType.insert("correct_option_id", correctOption); pollType.insert("correct_option_id", correctOption);
if(!explanation.isEmpty()) {
QVariantMap formattedExplanation;
formattedExplanation.insert("text", explanation);
pollType.insert("explanation", formattedExplanation);
}
} else { } else {
pollType.insert(_TYPE, "pollTypeRegular"); pollType.insert(_TYPE, "pollTypeRegular");
pollType.insert("allow_multiple_answers", multiple); pollType.insert("allow_multiple_answers", multiple);

View file

@ -145,7 +145,7 @@ public:
Q_INVOKABLE void sendVoiceNoteMessage(const QString &chatId, const QString &filePath, const QString &message, const QString &replyToMessageId = "0"); Q_INVOKABLE void sendVoiceNoteMessage(const QString &chatId, const QString &filePath, const QString &message, const QString &replyToMessageId = "0");
Q_INVOKABLE void sendLocationMessage(const QString &chatId, double latitude, double longitude, double horizontalAccuracy, const QString &replyToMessageId = "0"); Q_INVOKABLE void sendLocationMessage(const QString &chatId, double latitude, double longitude, double horizontalAccuracy, const QString &replyToMessageId = "0");
Q_INVOKABLE void sendStickerMessage(const QString &chatId, const QString &fileId, const QString &replyToMessageId = "0"); Q_INVOKABLE void sendStickerMessage(const QString &chatId, const QString &fileId, const QString &replyToMessageId = "0");
Q_INVOKABLE void sendPollMessage(const QString &chatId, const QString &question, const QVariantList &options, bool anonymous, int correctOption, bool multiple, const QString &replyToMessageId = "0"); Q_INVOKABLE void sendPollMessage(const QString &chatId, const QString &question, const QVariantList &options, bool anonymous, int correctOption, bool multiple, const QString &explanation, const QString &replyToMessageId = "0");
Q_INVOKABLE void forwardMessages(const QString &chatId, const QString &fromChatId, const QVariantList &messageIds, bool sendCopy, bool removeCaption); Q_INVOKABLE void forwardMessages(const QString &chatId, const QString &fromChatId, const QVariantList &messageIds, bool sendCopy, bool removeCaption);
Q_INVOKABLE void getMessage(qlonglong chatId, qlonglong messageId); Q_INVOKABLE void getMessage(qlonglong chatId, qlonglong messageId);
Q_INVOKABLE void getCallbackQueryAnswer(const QString &chatId, const QString &messageId, const QVariantMap &payload); Q_INVOKABLE void getCallbackQueryAnswer(const QString &chatId, const QString &messageId, const QVariantMap &payload);

View file

@ -1064,7 +1064,7 @@
<name>MessageVoiceNote</name> <name>MessageVoiceNote</name>
<message> <message>
<source>Voice Note</source> <source>Voice Note</source>
<translation type="unfinished"></translation> <translation>Sprachnotiz</translation>
</message> </message>
</context> </context>
<context> <context>
@ -1298,6 +1298,18 @@
<source>Quizzes have one correct answer. Participants can&apos;t revoke their responses.</source> <source>Quizzes have one correct answer. Participants can&apos;t revoke their responses.</source>
<translation>Quizze haben eine korrekte Antwort. Teilnehmer können ihre Antwort nicht zurückziehen.</translation> <translation>Quizze haben eine korrekte Antwort. Teilnehmer können ihre Antwort nicht zurückziehen.</translation>
</message> </message>
<message>
<source>Enter an optional explanation</source>
<translation>Geben Sie eine optionale Erklärung ein</translation>
</message>
<message>
<source>Shown when the user selects a wrong answer.</source>
<translation>Wird bei Auswahl einer falschen Antwort gezeigt.</translation>
</message>
<message>
<source>An explanation can be up to 200 characters long.</source>
<translation>Eine Erklärung kann bis zu 200 Zeichen lang sein.</translation>
</message>
</context> </context>
<context> <context>
<name>PollResultsPage</name> <name>PollResultsPage</name>

View file

@ -1064,7 +1064,7 @@
<name>MessageVoiceNote</name> <name>MessageVoiceNote</name>
<message> <message>
<source>Voice Note</source> <source>Voice Note</source>
<translation type="unfinished"></translation> <translation>Voice Note</translation>
</message> </message>
</context> </context>
<context> <context>
@ -1298,6 +1298,18 @@
<source>Quizzes have one correct answer. Participants can&apos;t revoke their responses.</source> <source>Quizzes have one correct answer. Participants can&apos;t revoke their responses.</source>
<translation>Quizzes have one correct answer. Participants can&apos;t revoke their responses.</translation> <translation>Quizzes have one correct answer. Participants can&apos;t revoke their responses.</translation>
</message> </message>
<message>
<source>Enter an optional explanation</source>
<translation>Enter an optional explanation</translation>
</message>
<message>
<source>Shown when the user selects a wrong answer.</source>
<translation>Shown when the user selects a wrong answer.</translation>
</message>
<message>
<source>An explanation can be up to 200 characters long.</source>
<translation>An explanation can be up to 200 characters long.</translation>
</message>
</context> </context>
<context> <context>
<name>PollResultsPage</name> <name>PollResultsPage</name>

View file

@ -1298,6 +1298,18 @@
<source>Quizzes have one correct answer. Participants can&apos;t revoke their responses.</source> <source>Quizzes have one correct answer. Participants can&apos;t revoke their responses.</source>
<translation>Los interrogatorios tienen una respuesta correcta. Los participantes no pueden revocar sus respuestas.</translation> <translation>Los interrogatorios tienen una respuesta correcta. Los participantes no pueden revocar sus respuestas.</translation>
</message> </message>
<message>
<source>Enter an optional explanation</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Shown when the user selects a wrong answer.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>An explanation can be up to 200 characters long.</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>PollResultsPage</name> <name>PollResultsPage</name>

View file

@ -1299,6 +1299,18 @@
<source>Quizzes have one correct answer. Participants can&apos;t revoke their responses.</source> <source>Quizzes have one correct answer. Participants can&apos;t revoke their responses.</source>
<translation>Visoilla on yksi oikea vastaus. Osallistujat eivät voi kumota vastaustaan.</translation> <translation>Visoilla on yksi oikea vastaus. Osallistujat eivät voi kumota vastaustaan.</translation>
</message> </message>
<message>
<source>Enter an optional explanation</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Shown when the user selects a wrong answer.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>An explanation can be up to 200 characters long.</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>PollResultsPage</name> <name>PollResultsPage</name>

View file

@ -1279,6 +1279,18 @@
<source>Quizzes have one correct answer. Participants can&apos;t revoke their responses.</source> <source>Quizzes have one correct answer. Participants can&apos;t revoke their responses.</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Enter an optional explanation</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Shown when the user selects a wrong answer.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>An explanation can be up to 200 characters long.</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>PollResultsPage</name> <name>PollResultsPage</name>

View file

@ -1298,6 +1298,18 @@
<source>Quizzes have one correct answer. Participants can&apos;t revoke their responses.</source> <source>Quizzes have one correct answer. Participants can&apos;t revoke their responses.</source>
<translation>I quiz hanno una sola risposta corretta. I partecipanti non possono revocare le risposte.</translation> <translation>I quiz hanno una sola risposta corretta. I partecipanti non possono revocare le risposte.</translation>
</message> </message>
<message>
<source>Enter an optional explanation</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Shown when the user selects a wrong answer.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>An explanation can be up to 200 characters long.</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>PollResultsPage</name> <name>PollResultsPage</name>

View file

@ -1317,6 +1317,18 @@
<source>Quizzes have one correct answer. Participants can&apos;t revoke their responses.</source> <source>Quizzes have one correct answer. Participants can&apos;t revoke their responses.</source>
<translation>Quizy mają jedną poprawną odpowiedź. Uczestnicy nie mogą odwołać swoich odpowiedzi.</translation> <translation>Quizy mają jedną poprawną odpowiedź. Uczestnicy nie mogą odwołać swoich odpowiedzi.</translation>
</message> </message>
<message>
<source>Enter an optional explanation</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Shown when the user selects a wrong answer.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>An explanation can be up to 200 characters long.</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>PollResultsPage</name> <name>PollResultsPage</name>

View file

@ -1317,6 +1317,18 @@
<source>Quizzes have one correct answer. Participants can&apos;t revoke their responses.</source> <source>Quizzes have one correct answer. Participants can&apos;t revoke their responses.</source>
<translation>Тесты имеют один правильный ответ. Участники не могут отозвать свои ответы.</translation> <translation>Тесты имеют один правильный ответ. Участники не могут отозвать свои ответы.</translation>
</message> </message>
<message>
<source>Enter an optional explanation</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Shown when the user selects a wrong answer.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>An explanation can be up to 200 characters long.</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>PollResultsPage</name> <name>PollResultsPage</name>

View file

@ -1298,6 +1298,18 @@
<source>Quizzes have one correct answer. Participants can&apos;t revoke their responses.</source> <source>Quizzes have one correct answer. Participants can&apos;t revoke their responses.</source>
<translation>Frågor har ett (1) korrekt svar. Deltagarna kan inte återkalla sina svar.</translation> <translation>Frågor har ett (1) korrekt svar. Deltagarna kan inte återkalla sina svar.</translation>
</message> </message>
<message>
<source>Enter an optional explanation</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Shown when the user selects a wrong answer.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>An explanation can be up to 200 characters long.</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>PollResultsPage</name> <name>PollResultsPage</name>

View file

@ -1279,6 +1279,18 @@
<source>Quizzes have one correct answer. Participants can&apos;t revoke their responses.</source> <source>Quizzes have one correct answer. Participants can&apos;t revoke their responses.</source>
<translation>Quiz </translation> <translation>Quiz </translation>
</message> </message>
<message>
<source>Enter an optional explanation</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Shown when the user selects a wrong answer.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>An explanation can be up to 200 characters long.</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>PollResultsPage</name> <name>PollResultsPage</name>

View file

@ -1298,6 +1298,18 @@
<source>Quizzes have one correct answer. Participants can&apos;t revoke their responses.</source> <source>Quizzes have one correct answer. Participants can&apos;t revoke their responses.</source>
<translation>Quizzes have one correct answer. Participants can&apos;t revoke their responses.</translation> <translation>Quizzes have one correct answer. Participants can&apos;t revoke their responses.</translation>
</message> </message>
<message>
<source>Enter an optional explanation</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Shown when the user selects a wrong answer.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>An explanation can be up to 200 characters long.</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>PollResultsPage</name> <name>PollResultsPage</name>