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

@@ -1,3 +1,5 @@
import 'dart:developer';
import 'package:bubble/bubble.dart';
import 'package:emoji_picker_flutter/emoji_picker_flutter.dart' as emojis;
import 'package:flowder/flowder.dart';
@@ -6,6 +8,7 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:jiffy/jiffy.dart';
import 'package:open_filex/open_filex.dart';
import '../../../../api/marianumcloud/talk/getPoll/getPollState.dart';
import '../../../../extensions/text.dart';
import 'package:provider/provider.dart';
@@ -18,11 +21,13 @@ import '../../../../api/marianumcloud/talk/reactMessage/reactMessageParams.dart'
import '../../../../api/marianumcloud/talk/room/getRoomResponse.dart';
import '../../../../model/chatList/chatProps.dart';
import '../../../../widget/debug/debugTile.dart';
import '../../../../widget/loadingSpinner.dart';
import '../../files/fileElement.dart';
import 'answerReference.dart';
import 'chatBubbleStyles.dart';
import 'chatMessage.dart';
import '../messageReactions.dart';
import 'pollOptionsList.dart';
class ChatBubble extends StatefulWidget {
final BuildContext context;
@@ -297,6 +302,41 @@ class _ChatBubbleState extends State<ChatBubble> with SingleTickerProviderStateM
onLongPress: showOptionsDialog,
onDoubleTap: showOptionsDialog,
onTap: () {
if(message.originalData?['object']?.type == RichObjectStringObjectType.talkPoll) {
log(message.originalData!['object']!.id);
var pollState = GetPollState(token: widget.bubbleData.token, pollId: int.parse(message.originalData!['object']!.id)).run();
List<int>? ownVotes;
showDialog(context: context, builder: (context) => AlertDialog(
title: Text(message.originalData!['object']!.name, textScaler: TextScaler.linear(0.9)),
content: FutureBuilder(
future: pollState,
builder: (context, snapshot) {
if(snapshot.connectionState == ConnectionState.waiting) return const LoadingSpinner();
var pollData = snapshot.data!.data;
ownVotes = pollData.votedSelf;
return PollOptionsList(
pollData: pollData,
callback: (votes) => ownVotes = votes
);
}
),
actions: [
TextButton(
onPressed: () {
Navigator.of(context).pop();
if(ownVotes == null) return;
},
child: const Text('Stimme abgeben')
),
TextButton(
onPressed: () => Navigator.of(context).pop(),
child: const Text('Abbrechen')
),
],
));
}
if(message.file == null) return;
if(downloadProgress > 0) {

View File

@@ -32,6 +32,14 @@ class ChatMessage {
onOpen: onOpen,
);
if(originalData?['object']?.type == RichObjectStringObjectType.talkPoll) {
return ListTile(
leading: const Icon(Icons.poll_outlined),
title: Text(originalData!['object']!.name),
contentPadding: const EdgeInsets.only(left: 10),
);
}
if(file == null) return contentWidget;
return Padding(

View File

@@ -0,0 +1,47 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../../../api/marianumcloud/talk/getPoll/getPollStateResponse.dart';
class PollOptionsList extends StatefulWidget {
final GetPollStateResponseObject pollData;
final Function(List<int>) callback;
const PollOptionsList({super.key, required this.pollData, required this.callback});
@override
State<PollOptionsList> createState() => _PollOptionsListState();
}
class _PollOptionsListState extends State<PollOptionsList> {
late List<int> ownVotes;
@override
void initState() {
super.initState();
ownVotes = widget.pollData.votedSelf;
}
@override
Widget build(BuildContext context) => ListView(
shrinkWrap: true,
children: [
...widget.pollData.options.map<Widget>(
(option) => CheckboxListTile(
value: ownVotes.contains(widget.pollData.options.indexOf(option)),
title: Text(option),
onChanged: (value) {
var optionId = widget.pollData.options.indexOf(option);
setState(() {
if(ownVotes.contains(optionId)) {
ownVotes.remove(optionId);
} else {
ownVotes.add(optionId);
}
});
widget.callback(ownVotes);
}
)
)
],
);
}