added functionality to show own votes in polls

This commit is contained in:
2025-10-10 02:01:43 +02:00
parent 7b7ab2e82e
commit 81f65750b7
6 changed files with 227 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
import 'dart:convert';
import 'dart:developer';
import 'package:http/http.dart' as http;
import '../talkApi.dart';
import 'getPollStateResponse.dart';
class GetPollState extends TalkApi<GetPollStateResponse> {
String token;
int pollId;
GetPollState({required this.token, required this.pollId}) : super('v1/poll/$token/$pollId', null);
@override
GetPollStateResponse assemble(String raw) {
log(raw);
return GetPollStateResponse.fromJson(jsonDecode(raw)['ocs']);
}
@override
Future<http.Response> request(Uri uri, Object? body, Map<String, String>? headers) => http.get(uri, headers: headers);
}

View File

@@ -0,0 +1,50 @@
import 'package:json_annotation/json_annotation.dart';
import '../../../apiResponse.dart';
part 'getPollStateResponse.g.dart';
@JsonSerializable(explicitToJson: true)
class GetPollStateResponse extends ApiResponse {
GetPollStateResponseObject data;
GetPollStateResponse(this.data);
factory GetPollStateResponse.fromJson(Map<String, dynamic> json) => _$GetPollStateResponseFromJson(json);
Map<String, dynamic> toJson() => _$GetPollStateResponseToJson(this);
}
@JsonSerializable(explicitToJson: true)
class GetPollStateResponseObject {
int id;
String question;
List<String> options;
dynamic votes;
String actorType;
String actorId;
String actorDisplayName;
int status;
int resultMode;
int maxVotes;
List<int> votedSelf;
int? numVoters;
List<String>? details;
GetPollStateResponseObject(
this.id,
this.question,
this.options,
this.votes,
this.actorType,
this.actorId,
this.actorDisplayName,
this.status,
this.resultMode,
this.maxVotes,
this.votedSelf,
this.numVoters,
this.details);
factory GetPollStateResponseObject.fromJson(Map<String, dynamic> json) => _$GetPollStateResponseObjectFromJson(json);
Map<String, dynamic> toJson() => _$GetPollStateResponseObjectToJson(this);
}

View File

@@ -0,0 +1,60 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'getPollStateResponse.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
GetPollStateResponse _$GetPollStateResponseFromJson(
Map<String, dynamic> json) =>
GetPollStateResponse(
GetPollStateResponseObject.fromJson(json['data'] as Map<String, dynamic>),
)..headers = (json['headers'] as Map<String, dynamic>?)?.map(
(k, e) => MapEntry(k, e as String),
);
Map<String, dynamic> _$GetPollStateResponseToJson(
GetPollStateResponse instance) =>
<String, dynamic>{
if (instance.headers case final value?) 'headers': value,
'data': instance.data.toJson(),
};
GetPollStateResponseObject _$GetPollStateResponseObjectFromJson(
Map<String, dynamic> json) =>
GetPollStateResponseObject(
(json['id'] as num).toInt(),
json['question'] as String,
(json['options'] as List<dynamic>).map((e) => e as String).toList(),
json['votes'],
json['actorType'] as String,
json['actorId'] as String,
json['actorDisplayName'] as String,
(json['status'] as num).toInt(),
(json['resultMode'] as num).toInt(),
(json['maxVotes'] as num).toInt(),
(json['votedSelf'] as List<dynamic>)
.map((e) => (e as num).toInt())
.toList(),
(json['numVoters'] as num?)?.toInt(),
(json['details'] as List<dynamic>?)?.map((e) => e as String).toList(),
);
Map<String, dynamic> _$GetPollStateResponseObjectToJson(
GetPollStateResponseObject instance) =>
<String, dynamic>{
'id': instance.id,
'question': instance.question,
'options': instance.options,
'votes': instance.votes,
'actorType': instance.actorType,
'actorId': instance.actorId,
'actorDisplayName': instance.actorDisplayName,
'status': instance.status,
'resultMode': instance.resultMode,
'maxVotes': instance.maxVotes,
'votedSelf': instance.votedSelf,
'numVoters': instance.numVoters,
'details': instance.details,
};