11 Commits

12 changed files with 142 additions and 121 deletions

View File

@@ -1,3 +1,4 @@
extensions: extensions:
- provider: true - hive_ce: true
- shared_preferences: true - shared_preferences: true
- provider: true

View File

@@ -28,7 +28,7 @@ class GetPollStateResponseObject {
int maxVotes; int maxVotes;
List<int> votedSelf; List<int> votedSelf;
int? numVoters; int? numVoters;
List<String>? details; List<dynamic>? details;
GetPollStateResponseObject( GetPollStateResponseObject(
this.id, this.id,

View File

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

View File

@@ -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;
import 'package:http/http.dart'; import 'package:http/http.dart';
@@ -8,21 +7,18 @@ import '../getPoll/getPollStateResponse.dart';
import '../talkApi.dart'; import '../talkApi.dart';
import 'votePollParams.dart'; import 'votePollParams.dart';
@Deprecated('VotePoll is broken')
class VotePoll extends TalkApi { class VotePoll extends TalkApi {
String token; String token;
int pollId; int pollId;
VotePoll({required this.token, required this.pollId, required VotePollParams params}) : super('v1/poll/$token/$pollId', params); VotePoll({required this.token, required this.pollId, required VotePollParams params}) : super('v1/poll/$token/$pollId', params);
@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<Response>? request(Uri uri, Object? body, Map<String, String>? headers) { Future<Response>? request(Uri uri, Object? body, Map<String, String>? headers) {
if(body is VotePollParams) { if(body is VotePollParams) {
log(body.toJson().toString());
return http.post(uri, headers: headers, body: body.toJson().toString()); return http.post(uri, headers: headers, body: body.toJson().toString());
} }
return null; return null;

View File

@@ -5,6 +5,7 @@ import '../../../apiParams.dart';
part 'votePollParams.g.dart'; part 'votePollParams.g.dart';
@JsonSerializable() @JsonSerializable()
@Deprecated('VotePoll is broken')
class VotePollParams extends ApiParams { class VotePollParams extends ApiParams {
List<int> optionIds; List<int> optionIds;

View File

@@ -14,6 +14,4 @@ VotePollParams _$VotePollParamsFromJson(Map<String, dynamic> json) =>
); );
Map<String, dynamic> _$VotePollParamsToJson(VotePollParams instance) => Map<String, dynamic> _$VotePollParamsToJson(VotePollParams instance) =>
<String, dynamic>{ <String, dynamic>{'optionIds': instance.optionIds};
'optionIds': instance.optionIds,
};

View File

@@ -51,7 +51,7 @@ class GradeAveragesView extends StatelessWidget {
color: Theme.of(context).colorScheme.onSurface color: Theme.of(context).colorScheme.onSurface
), ),
const SizedBox(width: 15), const SizedBox(width: 15),
Text(isMiddleSchool ? 'Notensystem' : 'Punktesystem'), Text(isMiddleSchool ? 'Realschule' : 'Oberstufe'),
], ],
), ),
)).toList(), )).toList(),
@@ -80,11 +80,19 @@ class GradeAveragesView extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
const SizedBox(height: 30), const SizedBox(height: 30),
Text(bloc.average().toStringAsFixed(2), style: const TextStyle(fontSize: 30, fontWeight: FontWeight.bold)), Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('Ø', style: TextStyle(fontSize: 30, fontWeight: FontWeight.bold)),
SizedBox(width: 5),
Text(bloc.average().toStringAsFixed(2), style: const TextStyle(fontSize: 30, fontWeight: FontWeight.bold))
],
),
const SizedBox(height: 10), const SizedBox(height: 10),
const Divider(), const Divider(),
const SizedBox(height: 10), const SizedBox(height: 10),
Text(bloc.isMiddleSchool() ? 'Wähle unten die Anzahl deiner jeweiligen Noten aus' : 'Wähle unten die Anzahl deiner jeweiligen Punkte aus'), Text(bloc.isMiddleSchool() ? 'Wähle die Anzahl deiner jeweiligen Noten aus' : 'Wähle die Anzahl deiner jeweiligen Punkte aus'),
const SizedBox(height: 10), const SizedBox(height: 10),
const Expanded( const Expanded(
child: GradeAveragesListView() child: GradeAveragesListView()

10
lib/utils/UrlOpener.dart Normal file
View File

@@ -0,0 +1,10 @@
import 'package:flutter_linkify/flutter_linkify.dart';
import 'package:url_launcher/url_launcher_string.dart';
class UrlOpener {
static Future<void> onOpen(LinkableElement link) async {
if(await canLaunchUrlString(link.url)) {
await launchUrlString(link.url);
}
}
}

View File

@@ -51,6 +51,7 @@ class _ChatViewState extends State<ChatView> {
var elementDate = DateTime.fromMillisecondsSinceEpoch(element.timestamp * 1000); var elementDate = DateTime.fromMillisecondsSinceEpoch(element.timestamp * 1000);
if(element.systemMessage.contains('reaction')) return; if(element.systemMessage.contains('reaction')) return;
if(element.systemMessage.contains('poll_voted')) return;
var commonRead = int.parse(data.getChatResponse.headers?['x-chat-last-common-read'] ?? '0'); var commonRead = int.parse(data.getChatResponse.headers?['x-chat-last-common-read'] ?? '0');
if(!elementDate.isSameDay(lastDate)) { if(!elementDate.isSameDay(lastDate)) {
@@ -128,7 +129,7 @@ class _ChatViewState extends State<ChatView> {
), ),
), ),
Container( Container(
color: Theme.of(context).colorScheme.background, color: Theme.of(context).colorScheme.surface,
child: TalkNavigator.isSecondaryVisible(context) child: TalkNavigator.isSecondaryVisible(context)
? ChatTextfield(widget.room.token, selfId: widget.selfId) ? ChatTextfield(widget.room.token, selfId: widget.selfId)
: SafeArea(child: ChatTextfield(widget.room.token, selfId: widget.selfId) : SafeArea(child: ChatTextfield(widget.room.token, selfId: widget.selfId)

View File

@@ -7,8 +7,6 @@ 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';
@@ -305,35 +303,26 @@ class _ChatBubbleState extends State<ChatBubble> with SingleTickerProviderStateM
if(message.originalData?['object']?.type == RichObjectStringObjectType.talkPoll) { if(message.originalData?['object']?.type == RichObjectStringObjectType.talkPoll) {
var pollId = int.parse(message.originalData!['object']!.id); var pollId = int.parse(message.originalData!['object']!.id);
var pollState = GetPollState(token: widget.bubbleData.token, pollId: pollId).run(); var pollState = GetPollState(token: widget.bubbleData.token, pollId: pollId).run();
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, overflow: TextOverflow.ellipsis),
content: FutureBuilder( content: FutureBuilder(
future: pollState, future: pollState,
builder: (context, snapshot) { builder: (context, snapshot) {
if(snapshot.connectionState == ConnectionState.waiting) return const Column(mainAxisSize: MainAxisSize.min, children: [LoadingSpinner()]); if(snapshot.connectionState == ConnectionState.waiting) return const Column(mainAxisSize: MainAxisSize.min, children: [LoadingSpinner()]);
var pollData = snapshot.data!.data; var pollData = snapshot.data!.data;
ownVotes = pollData.votedSelf; return SingleChildScrollView(
return PollOptionsList( child: PollOptionsList(
pollData: pollData, pollData: pollData,
callback: (votes) => ownVotes = votes chatToken: widget.chatData.token,
); ),
} );
}
), ),
actions: [ actions: [
FutureBuilder(future: pollState, builder: (context, snapshot) => TextButton(
onPressed: () async {
if(snapshot.connectionState != ConnectionState.done) return;
Navigator.of(context).pop();
if(ownVotes == null) return;
VotePoll(pollId: pollId, token: widget.bubbleData.token, params: VotePollParams(optionIds: ownVotes!)).run();
},
child: const Text('Stimme abgeben')
)),
TextButton( TextButton(
onPressed: () => Navigator.of(context).pop(), onPressed: () => Navigator.of(context).pop(),
child: const Text('Abbrechen') child: const Text('Zurück')
), ),
], ],
)); ));

View File

@@ -2,12 +2,12 @@
import 'package:cached_network_image/cached_network_image.dart'; import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_linkify/flutter_linkify.dart'; import 'package:flutter_linkify/flutter_linkify.dart';
import 'package:url_launcher/url_launcher_string.dart';
import '../../../../api/marianumcloud/talk/chat/getChatResponse.dart'; import '../../../../api/marianumcloud/talk/chat/getChatResponse.dart';
import '../../../../api/marianumcloud/talk/chat/richObjectStringProcessor.dart'; import '../../../../api/marianumcloud/talk/chat/richObjectStringProcessor.dart';
import '../../../../model/accountData.dart'; import '../../../../model/accountData.dart';
import '../../../../model/endpointData.dart'; import '../../../../model/endpointData.dart';
import '../../../../utils/UrlOpener.dart';
class ChatMessage { class ChatMessage {
String originalMessage; String originalMessage;
@@ -29,7 +29,7 @@ class ChatMessage {
var contentWidget = Linkify( var contentWidget = Linkify(
text: content, text: content,
onOpen: onOpen, onOpen: UrlOpener.onOpen,
); );
if(originalData?['object']?.type == RichObjectStringObjectType.talkPoll) { if(originalData?['object']?.type == RichObjectStringObjectType.talkPoll) {
@@ -73,10 +73,4 @@ class ChatMessage {
) )
); );
} }
Future<void> onOpen(LinkableElement link) async {
if(await canLaunchUrlString(link.url)) {
await launchUrlString(link.url);
}
}
} }

View File

@@ -1,46 +1,67 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_linkify/flutter_linkify.dart';
import '../../../../api/marianumcloud/talk/getPoll/getPollStateResponse.dart'; import '../../../../api/marianumcloud/talk/getPoll/getPollStateResponse.dart';
import '../../../../utils/UrlOpener.dart';
class PollOptionsList extends StatefulWidget { class PollOptionsList extends StatefulWidget {
final GetPollStateResponseObject pollData; final GetPollStateResponseObject pollData;
final Function(List<int>) callback; final String chatToken;
const PollOptionsList({super.key, required this.pollData, required this.callback}); const PollOptionsList({super.key, required this.pollData, required this.chatToken});
@override @override
State<PollOptionsList> createState() => _PollOptionsListState(); State<PollOptionsList> createState() => _PollOptionsListState();
} }
class _PollOptionsListState extends State<PollOptionsList> { class _PollOptionsListState extends State<PollOptionsList> {
late List<int> ownVotes;
@override
void initState() {
super.initState();
ownVotes = widget.pollData.votedSelf;
}
@override @override
Widget build(BuildContext context) => Column( Widget build(BuildContext context) => Column(
mainAxisSize: MainAxisSize.min, children: [
children: [ ...widget.pollData.options.map<Widget>((option) {
...widget.pollData.options.map<Widget>((option) => CheckboxListTile( var optionId = widget.pollData.options.indexOf(option);
value: ownVotes.contains(widget.pollData.options.indexOf(option)), var votedSelf = widget.pollData.votedSelf.contains(optionId);
title: Text(option), var portionsVisible = widget.pollData.votes is Map<String, dynamic>;
onChanged: (value) { var votes = portionsVisible
var optionId = widget.pollData.options.indexOf(option); ? (widget.pollData.votes['option-$optionId'] as num?) ?? 0
setState(() { : 0;
if(ownVotes.contains(optionId)) { var numVoters = widget.pollData.numVoters ?? 0;
ownVotes.remove(optionId); double portion = numVoters == 0 ? 0 : (votes / numVoters);
} else {
ownVotes.add(optionId); return ListTile(
} // enabled: false,
}); isThreeLine: portionsVisible,
widget.callback(ownVotes); dense: true,
} title: Text(
) option,
) style: Theme.of(context).textTheme.bodyLarge,
], ),
); leading: Icon(
votedSelf ? Icons.check_circle_outlined : Icons.circle_outlined,
color: votedSelf
? Theme.of(context).colorScheme.primary.withValues(alpha: 0.6)
: Theme.of(context).colorScheme.onSurfaceVariant.withValues(alpha: 0.6),
),
subtitle: portionsVisible ? Row(
children: [
Expanded(
child: LinearProgressIndicator(value: portion.clamp(0.0, 1.0)),
),
Container(
margin: const EdgeInsets.only(left: 10),
child: Text('${(portion * 100).round()}%'),
),
],
) : null,
);
}),
ListTile(
title: Linkify(
text: 'Wenn du abstimmen möchtest, verwende die Webversion unter https://cloud.marianum-fulda.de/call/${widget.chatToken}',
onOpen: UrlOpener.onOpen,
style: Theme.of(context).textTheme.bodySmall,
),
)
],
);
} }