Compare commits
11 Commits
699aec8ab5
...
develop
| Author | SHA1 | Date | |
|---|---|---|---|
| a52817231e | |||
| f6933b6529 | |||
| e4243e53ac | |||
| 0aead45191 | |||
| dacefd321b | |||
| 92a9a7358e | |||
| 174e6ac0b7 | |||
| c9eaed782a | |||
| 567184bcf9 | |||
| 541d6ef164 | |||
| 3469d02033 |
@@ -1,3 +1,4 @@
|
||||
extensions:
|
||||
- provider: true
|
||||
- shared_preferences: true
|
||||
- hive_ce: true
|
||||
- shared_preferences: true
|
||||
- provider: true
|
||||
@@ -28,7 +28,7 @@ class GetPollStateResponseObject {
|
||||
int maxVotes;
|
||||
List<int> votedSelf;
|
||||
int? numVoters;
|
||||
List<String>? details;
|
||||
List<dynamic>? details;
|
||||
|
||||
GetPollStateResponseObject(
|
||||
this.id,
|
||||
|
||||
@@ -7,54 +7,56 @@ part of 'getPollStateResponse.dart';
|
||||
// **************************************************************************
|
||||
|
||||
GetPollStateResponse _$GetPollStateResponseFromJson(
|
||||
Map<String, dynamic> json) =>
|
||||
Map<String, dynamic> json,
|
||||
) =>
|
||||
GetPollStateResponse(
|
||||
GetPollStateResponseObject.fromJson(json['data'] as Map<String, dynamic>),
|
||||
)..headers = (json['headers'] as Map<String, dynamic>?)?.map(
|
||||
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(),
|
||||
};
|
||||
GetPollStateResponse instance,
|
||||
) => <String, dynamic>{
|
||||
'headers': ?instance.headers,
|
||||
'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> 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<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,
|
||||
};
|
||||
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,
|
||||
};
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:http/http.dart';
|
||||
@@ -8,21 +7,18 @@ import '../getPoll/getPollStateResponse.dart';
|
||||
import '../talkApi.dart';
|
||||
import 'votePollParams.dart';
|
||||
|
||||
@Deprecated('VotePoll is broken')
|
||||
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']);
|
||||
}
|
||||
GetPollStateResponse assemble(String raw) => 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;
|
||||
|
||||
@@ -5,10 +5,11 @@ import '../../../apiParams.dart';
|
||||
part 'votePollParams.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
@Deprecated('VotePoll is broken')
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,4 @@ VotePollParams _$VotePollParamsFromJson(Map<String, dynamic> json) =>
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$VotePollParamsToJson(VotePollParams instance) =>
|
||||
<String, dynamic>{
|
||||
'optionIds': instance.optionIds,
|
||||
};
|
||||
<String, dynamic>{'optionIds': instance.optionIds};
|
||||
|
||||
@@ -51,7 +51,7 @@ class GradeAveragesView extends StatelessWidget {
|
||||
color: Theme.of(context).colorScheme.onSurface
|
||||
),
|
||||
const SizedBox(width: 15),
|
||||
Text(isMiddleSchool ? 'Notensystem' : 'Punktesystem'),
|
||||
Text(isMiddleSchool ? 'Realschule' : 'Oberstufe'),
|
||||
],
|
||||
),
|
||||
)).toList(),
|
||||
@@ -80,11 +80,19 @@ class GradeAveragesView extends StatelessWidget {
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
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 Divider(),
|
||||
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 Expanded(
|
||||
child: GradeAveragesListView()
|
||||
|
||||
10
lib/utils/UrlOpener.dart
Normal file
10
lib/utils/UrlOpener.dart
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -51,6 +51,7 @@ class _ChatViewState extends State<ChatView> {
|
||||
var elementDate = DateTime.fromMillisecondsSinceEpoch(element.timestamp * 1000);
|
||||
|
||||
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');
|
||||
|
||||
if(!elementDate.isSameDay(lastDate)) {
|
||||
@@ -128,7 +129,7 @@ class _ChatViewState extends State<ChatView> {
|
||||
),
|
||||
),
|
||||
Container(
|
||||
color: Theme.of(context).colorScheme.background,
|
||||
color: Theme.of(context).colorScheme.surface,
|
||||
child: TalkNavigator.isSecondaryVisible(context)
|
||||
? ChatTextfield(widget.room.token, selfId: widget.selfId)
|
||||
: SafeArea(child: ChatTextfield(widget.room.token, selfId: widget.selfId)
|
||||
|
||||
@@ -7,8 +7,6 @@ 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 '../../../../api/marianumcloud/talk/votePoll/votePoll.dart';
|
||||
import '../../../../api/marianumcloud/talk/votePoll/votePollParams.dart';
|
||||
import '../../../../extensions/text.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
@@ -305,35 +303,26 @@ class _ChatBubbleState extends State<ChatBubble> with SingleTickerProviderStateM
|
||||
if(message.originalData?['object']?.type == RichObjectStringObjectType.talkPoll) {
|
||||
var pollId = int.parse(message.originalData!['object']!.id);
|
||||
var pollState = GetPollState(token: widget.bubbleData.token, pollId: pollId).run();
|
||||
List<int>? ownVotes;
|
||||
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(
|
||||
future: pollState,
|
||||
builder: (context, snapshot) {
|
||||
if(snapshot.connectionState == ConnectionState.waiting) return const Column(mainAxisSize: MainAxisSize.min, children: [LoadingSpinner()]);
|
||||
future: pollState,
|
||||
builder: (context, snapshot) {
|
||||
if(snapshot.connectionState == ConnectionState.waiting) return const Column(mainAxisSize: MainAxisSize.min, children: [LoadingSpinner()]);
|
||||
|
||||
var pollData = snapshot.data!.data;
|
||||
ownVotes = pollData.votedSelf;
|
||||
return PollOptionsList(
|
||||
var pollData = snapshot.data!.data;
|
||||
return SingleChildScrollView(
|
||||
child: PollOptionsList(
|
||||
pollData: pollData,
|
||||
callback: (votes) => ownVotes = votes
|
||||
);
|
||||
}
|
||||
chatToken: widget.chatData.token,
|
||||
),
|
||||
);
|
||||
}
|
||||
),
|
||||
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(
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
child: const Text('Abbrechen')
|
||||
child: const Text('Zurück')
|
||||
),
|
||||
],
|
||||
));
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:flutter/material.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/richObjectStringProcessor.dart';
|
||||
import '../../../../model/accountData.dart';
|
||||
import '../../../../model/endpointData.dart';
|
||||
import '../../../../utils/UrlOpener.dart';
|
||||
|
||||
class ChatMessage {
|
||||
String originalMessage;
|
||||
@@ -29,7 +29,7 @@ class ChatMessage {
|
||||
|
||||
var contentWidget = Linkify(
|
||||
text: content,
|
||||
onOpen: onOpen,
|
||||
onOpen: UrlOpener.onOpen,
|
||||
);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,46 +1,67 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_linkify/flutter_linkify.dart';
|
||||
|
||||
import '../../../../api/marianumcloud/talk/getPoll/getPollStateResponse.dart';
|
||||
import '../../../../utils/UrlOpener.dart';
|
||||
|
||||
class PollOptionsList extends StatefulWidget {
|
||||
final GetPollStateResponseObject pollData;
|
||||
final Function(List<int>) callback;
|
||||
const PollOptionsList({super.key, required this.pollData, required this.callback});
|
||||
final String chatToken;
|
||||
const PollOptionsList({super.key, required this.pollData, required this.chatToken});
|
||||
|
||||
@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) => Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
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);
|
||||
}
|
||||
)
|
||||
)
|
||||
],
|
||||
);
|
||||
children: [
|
||||
...widget.pollData.options.map<Widget>((option) {
|
||||
var optionId = widget.pollData.options.indexOf(option);
|
||||
var votedSelf = widget.pollData.votedSelf.contains(optionId);
|
||||
var portionsVisible = widget.pollData.votes is Map<String, dynamic>;
|
||||
var votes = portionsVisible
|
||||
? (widget.pollData.votes['option-$optionId'] as num?) ?? 0
|
||||
: 0;
|
||||
var numVoters = widget.pollData.numVoters ?? 0;
|
||||
double portion = numVoters == 0 ? 0 : (votes / numVoters);
|
||||
|
||||
return ListTile(
|
||||
// enabled: false,
|
||||
isThreeLine: portionsVisible,
|
||||
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,
|
||||
),
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user