WIP: add option to vote on polls
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'dart:developer';
|
|
||||||
|
|
||||||
import 'package:http/http.dart' as http;
|
import 'package:http/http.dart' as http;
|
||||||
|
|
||||||
@@ -12,10 +11,7 @@ class GetPollState extends TalkApi<GetPollStateResponse> {
|
|||||||
GetPollState({required this.token, required this.pollId}) : super('v1/poll/$token/$pollId', null);
|
GetPollState({required this.token, required this.pollId}) : super('v1/poll/$token/$pollId', null);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
GetPollStateResponse assemble(String raw) {
|
GetPollStateResponse assemble(String raw) => GetPollStateResponse.fromJson(jsonDecode(raw)['ocs']);
|
||||||
log(raw);
|
|
||||||
return GetPollStateResponse.fromJson(jsonDecode(raw)['ocs']);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<http.Response> request(Uri uri, Object? body, Map<String, String>? headers) => http.get(uri, headers: headers);
|
Future<http.Response> request(Uri uri, Object? body, Map<String, String>? headers) => http.get(uri, headers: headers);
|
||||||
|
30
lib/api/marianumcloud/talk/votePoll/votePoll.dart
Normal file
30
lib/api/marianumcloud/talk/votePoll/votePoll.dart
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
import 'dart:developer';
|
||||||
|
|
||||||
|
import 'package:http/http.dart' as http;
|
||||||
|
import 'package:http/http.dart';
|
||||||
|
|
||||||
|
import '../getPoll/getPollStateResponse.dart';
|
||||||
|
import '../talkApi.dart';
|
||||||
|
import 'votePollParams.dart';
|
||||||
|
|
||||||
|
class VotePoll extends TalkApi {
|
||||||
|
String token;
|
||||||
|
int pollId;
|
||||||
|
VotePoll({required this.token, required this.pollId, required VotePollParams params}) : super('v1/poll/$token/$pollId', params);
|
||||||
|
|
||||||
|
@override
|
||||||
|
GetPollStateResponse assemble(String raw) {
|
||||||
|
log(raw);
|
||||||
|
return GetPollStateResponse.fromJson(jsonDecode(raw)['ocs']);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<Response>? request(Uri uri, Object? body, Map<String, String>? headers) {
|
||||||
|
if(body is VotePollParams) {
|
||||||
|
log(body.toJson().toString());
|
||||||
|
return http.post(uri, headers: headers, body: body.toJson().toString());
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
14
lib/api/marianumcloud/talk/votePoll/votePollParams.dart
Normal file
14
lib/api/marianumcloud/talk/votePoll/votePollParams.dart
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
import 'package:json_annotation/json_annotation.dart';
|
||||||
|
|
||||||
|
import '../../../apiParams.dart';
|
||||||
|
|
||||||
|
part 'votePollParams.g.dart';
|
||||||
|
|
||||||
|
@JsonSerializable()
|
||||||
|
class VotePollParams extends ApiParams {
|
||||||
|
List<int> optionIds;
|
||||||
|
|
||||||
|
VotePollParams({required this.optionIds});
|
||||||
|
factory VotePollParams.fromJson(Map<String, dynamic> json) => _$VotePollParamsFromJson(json);
|
||||||
|
Map<String, dynamic> toJson() => _$VotePollParamsToJson(this);
|
||||||
|
}
|
19
lib/api/marianumcloud/talk/votePoll/votePollParams.g.dart
Normal file
19
lib/api/marianumcloud/talk/votePoll/votePollParams.g.dart
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||||
|
|
||||||
|
part of 'votePollParams.dart';
|
||||||
|
|
||||||
|
// **************************************************************************
|
||||||
|
// JsonSerializableGenerator
|
||||||
|
// **************************************************************************
|
||||||
|
|
||||||
|
VotePollParams _$VotePollParamsFromJson(Map<String, dynamic> json) =>
|
||||||
|
VotePollParams(
|
||||||
|
optionIds: (json['optionIds'] as List<dynamic>)
|
||||||
|
.map((e) => (e as num).toInt())
|
||||||
|
.toList(),
|
||||||
|
);
|
||||||
|
|
||||||
|
Map<String, dynamic> _$VotePollParamsToJson(VotePollParams instance) =>
|
||||||
|
<String, dynamic>{
|
||||||
|
'optionIds': instance.optionIds,
|
||||||
|
};
|
@@ -1,5 +1,3 @@
|
|||||||
import 'dart:developer';
|
|
||||||
|
|
||||||
import 'package:bubble/bubble.dart';
|
import 'package:bubble/bubble.dart';
|
||||||
import 'package:emoji_picker_flutter/emoji_picker_flutter.dart' as emojis;
|
import 'package:emoji_picker_flutter/emoji_picker_flutter.dart' as emojis;
|
||||||
import 'package:flowder/flowder.dart';
|
import 'package:flowder/flowder.dart';
|
||||||
@@ -9,6 +7,8 @@ import 'package:flutter/services.dart';
|
|||||||
import 'package:jiffy/jiffy.dart';
|
import 'package:jiffy/jiffy.dart';
|
||||||
import 'package:open_filex/open_filex.dart';
|
import 'package:open_filex/open_filex.dart';
|
||||||
import '../../../../api/marianumcloud/talk/getPoll/getPollState.dart';
|
import '../../../../api/marianumcloud/talk/getPoll/getPollState.dart';
|
||||||
|
import '../../../../api/marianumcloud/talk/votePoll/votePoll.dart';
|
||||||
|
import '../../../../api/marianumcloud/talk/votePoll/votePollParams.dart';
|
||||||
import '../../../../extensions/text.dart';
|
import '../../../../extensions/text.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
@@ -303,8 +303,8 @@ class _ChatBubbleState extends State<ChatBubble> with SingleTickerProviderStateM
|
|||||||
onDoubleTap: showOptionsDialog,
|
onDoubleTap: showOptionsDialog,
|
||||||
onTap: () {
|
onTap: () {
|
||||||
if(message.originalData?['object']?.type == RichObjectStringObjectType.talkPoll) {
|
if(message.originalData?['object']?.type == RichObjectStringObjectType.talkPoll) {
|
||||||
log(message.originalData!['object']!.id);
|
var pollId = int.parse(message.originalData!['object']!.id);
|
||||||
var pollState = GetPollState(token: widget.bubbleData.token, pollId: int.parse(message.originalData!['object']!.id)).run();
|
var pollState = GetPollState(token: widget.bubbleData.token, pollId: pollId).run();
|
||||||
List<int>? ownVotes;
|
List<int>? ownVotes;
|
||||||
showDialog(context: context, builder: (context) => AlertDialog(
|
showDialog(context: context, builder: (context) => AlertDialog(
|
||||||
title: Text(message.originalData!['object']!.name, textScaler: TextScaler.linear(0.9)),
|
title: Text(message.originalData!['object']!.name, textScaler: TextScaler.linear(0.9)),
|
||||||
@@ -323,9 +323,10 @@ class _ChatBubbleState extends State<ChatBubble> with SingleTickerProviderStateM
|
|||||||
),
|
),
|
||||||
actions: [
|
actions: [
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () {
|
onPressed: () async {
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
if(ownVotes == null) return;
|
if(ownVotes == null) return;
|
||||||
|
VotePoll(pollId: pollId, token: widget.bubbleData.token, params: VotePollParams(optionIds: ownVotes!)).run();
|
||||||
},
|
},
|
||||||
child: const Text('Stimme abgeben')
|
child: const Text('Stimme abgeben')
|
||||||
),
|
),
|
||||||
|
Reference in New Issue
Block a user