implemented full interactive poll support in Talk, including creation, voting, and closing functionality
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
import '../../../api_params.dart';
|
||||
import '../talk_api.dart';
|
||||
import 'create_poll_params.dart';
|
||||
|
||||
/// Erstellt eine Umfrage; der Server postet die Poll-Nachricht selbst in den
|
||||
/// Chat, danach genügt ein Chat-Refresh. Nur in Gruppen-Chats erlaubt.
|
||||
class CreatePoll extends TalkApi {
|
||||
CreatePoll({required String token, required CreatePollParams params})
|
||||
: super(
|
||||
'v1/poll/$token',
|
||||
params,
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
);
|
||||
|
||||
@override
|
||||
Null assemble(String raw) => null;
|
||||
|
||||
@override
|
||||
Future<http.Response>? request(
|
||||
Uri uri,
|
||||
ApiParams? body,
|
||||
Map<String, String>? headers,
|
||||
) {
|
||||
if (body is! CreatePollParams) return null;
|
||||
return http.post(uri, headers: headers, body: jsonEncode(body.toJson()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
import '../../../api_params.dart';
|
||||
|
||||
part 'create_poll_params.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
class CreatePollParams extends ApiParams {
|
||||
String question;
|
||||
List<String> options;
|
||||
|
||||
/// 0 = Ergebnisse öffentlich, 1 = bis zum Schließen verborgen.
|
||||
int resultMode;
|
||||
|
||||
/// Stimmen pro Teilnehmer; 0 = unbegrenzt.
|
||||
int maxVotes;
|
||||
|
||||
CreatePollParams({
|
||||
required this.question,
|
||||
required this.options,
|
||||
required this.resultMode,
|
||||
required this.maxVotes,
|
||||
});
|
||||
factory CreatePollParams.fromJson(Map<String, dynamic> json) =>
|
||||
_$CreatePollParamsFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$CreatePollParamsToJson(this);
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'create_poll_params.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
CreatePollParams _$CreatePollParamsFromJson(Map<String, dynamic> json) =>
|
||||
CreatePollParams(
|
||||
question: json['question'] as String,
|
||||
options: (json['options'] as List<dynamic>)
|
||||
.map((e) => e as String)
|
||||
.toList(),
|
||||
resultMode: (json['resultMode'] as num).toInt(),
|
||||
maxVotes: (json['maxVotes'] as num).toInt(),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$CreatePollParamsToJson(CreatePollParams instance) =>
|
||||
<String, dynamic>{
|
||||
'question': instance.question,
|
||||
'options': instance.options,
|
||||
'resultMode': instance.resultMode,
|
||||
'maxVotes': instance.maxVotes,
|
||||
};
|
||||
Reference in New Issue
Block a user