chore: fix dialogs in report offensive message flow (#2380)
This commit is contained in:
parent
9161a346ed
commit
b6a6991e61
3 changed files with 89 additions and 77 deletions
|
|
@ -58,18 +58,14 @@ void reportEvent(
|
|||
hintText: L10n.of(context).reason,
|
||||
autoSubmit: true,
|
||||
);
|
||||
if (reason == null || reason.isEmpty) return;
|
||||
|
||||
if (score == 1) {
|
||||
await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () async => reportOffensiveMessage(
|
||||
context,
|
||||
event.room.id,
|
||||
reason,
|
||||
event.senderId,
|
||||
event.content['body'].toString(),
|
||||
),
|
||||
await reportOffensiveMessage(
|
||||
context,
|
||||
event.room.id,
|
||||
reason,
|
||||
event.senderId,
|
||||
event.content['body'].toString(),
|
||||
);
|
||||
controller.clearSelectedEvents();
|
||||
return;
|
||||
|
|
@ -85,13 +81,12 @@ void reportEvent(
|
|||
"reason": reason,
|
||||
},
|
||||
);
|
||||
controller.clearSelectedEvents();
|
||||
}
|
||||
|
||||
Future<void> reportOffensiveMessage(
|
||||
BuildContext context,
|
||||
String roomId,
|
||||
String reason,
|
||||
String? reason,
|
||||
String reportedUserId,
|
||||
String reportedMessage,
|
||||
) async {
|
||||
|
|
@ -100,57 +95,66 @@ Future<void> reportOffensiveMessage(
|
|||
throw ("Null room with id $roomId in reportMessage");
|
||||
}
|
||||
|
||||
final List<SpaceTeacher> teachers =
|
||||
await getReportTeachers(context, reportedInRoom);
|
||||
if (teachers.isEmpty) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
L10n.of(context).noTeachersFound,
|
||||
),
|
||||
),
|
||||
);
|
||||
final resp = await showFutureLoadingDialog<List<SpaceTeacher>>(
|
||||
context: context,
|
||||
future: () async {
|
||||
final List<SpaceTeacher> teachers =
|
||||
await getReportTeachers(context, reportedInRoom);
|
||||
if (teachers.isEmpty) {
|
||||
throw L10n.of(context).noTeachersFound;
|
||||
}
|
||||
return teachers;
|
||||
},
|
||||
);
|
||||
|
||||
if (resp.isError || resp.result == null || resp.result!.isEmpty) {
|
||||
return;
|
||||
}
|
||||
|
||||
final List<SpaceTeacher>? selectedTeachers = await showDialog(
|
||||
context: context,
|
||||
useRootNavigator: false,
|
||||
builder: (BuildContext context) => TeacherSelectDialog(teachers: teachers),
|
||||
builder: (BuildContext context) =>
|
||||
TeacherSelectDialog(teachers: resp.result!),
|
||||
);
|
||||
|
||||
if (selectedTeachers == null || selectedTeachers.isEmpty) {
|
||||
return;
|
||||
}
|
||||
|
||||
final List<Room> reportDMs = [];
|
||||
for (final SpaceTeacher teacher in selectedTeachers) {
|
||||
final Room reportDM = await getReportsDM(
|
||||
teacher.teacher,
|
||||
teacher.space,
|
||||
);
|
||||
reportDMs.add(reportDM);
|
||||
}
|
||||
await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () async {
|
||||
final List<Room> reportDMs = [];
|
||||
for (final SpaceTeacher teacher in selectedTeachers) {
|
||||
final Room reportDM = await getReportsDM(
|
||||
teacher.teacher,
|
||||
teacher.space,
|
||||
);
|
||||
reportDMs.add(reportDM);
|
||||
}
|
||||
|
||||
final String reportingUserId = Matrix.of(context).client.userID ?? "";
|
||||
final String roomName = reportedInRoom.getLocalizedDisplayname();
|
||||
final String messageTitle = L10n.of(context).reportMessageTitle(
|
||||
reportingUserId,
|
||||
reportedUserId,
|
||||
roomName,
|
||||
final String reportingUserId = Matrix.of(context).client.userID ?? "";
|
||||
final String roomName = reportedInRoom.getLocalizedDisplayname();
|
||||
final String messageTitle = L10n.of(context).reportMessageTitle(
|
||||
reportingUserId,
|
||||
reportedUserId,
|
||||
roomName,
|
||||
);
|
||||
final String messageBody = L10n.of(context).reportMessageBody(
|
||||
reportedMessage,
|
||||
reason ?? L10n.of(context).none,
|
||||
);
|
||||
final String message = "$messageTitle\n\n$messageBody";
|
||||
for (final Room reportDM in reportDMs) {
|
||||
final event = <String, dynamic>{
|
||||
'msgtype': PangeaEventTypes.report,
|
||||
'body': message,
|
||||
};
|
||||
await reportDM.sendEvent(event);
|
||||
}
|
||||
},
|
||||
);
|
||||
final String messageBody = L10n.of(context).reportMessageBody(
|
||||
reportedMessage,
|
||||
reason,
|
||||
);
|
||||
final String message = "$messageTitle\n\n$messageBody";
|
||||
for (final Room reportDM in reportDMs) {
|
||||
final event = <String, dynamic>{
|
||||
'msgtype': PangeaEventTypes.report,
|
||||
'body': message,
|
||||
};
|
||||
await reportDM.sendEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<SpaceTeacher>> getReportTeachers(
|
||||
|
|
|
|||
|
|
@ -28,7 +28,9 @@ class EmptyChatPopupState extends State<EmptyChatPopup> {
|
|||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
if (widget.room.summary.mJoinedMemberCount == 1) {
|
||||
if ((widget.room.summary.mJoinedMemberCount ?? 0) +
|
||||
(widget.room.summary.mInvitedMemberCount ?? 0) ==
|
||||
1) {
|
||||
WidgetsBinding.instance.addPostFrameCallback(
|
||||
(_) => instructionsShowPopup(
|
||||
context,
|
||||
|
|
@ -44,8 +46,9 @@ class EmptyChatPopupState extends State<EmptyChatPopup> {
|
|||
u.state.type == EventTypes.RoomMember;
|
||||
},
|
||||
).listen((event) {
|
||||
final members = widget.room.summary.mJoinedMemberCount;
|
||||
if (members != null && members > 1) {
|
||||
final members = (widget.room.summary.mJoinedMemberCount ?? 0) +
|
||||
(widget.room.summary.mInvitedMemberCount ?? 0);
|
||||
if (members > 1) {
|
||||
MatrixState.pAnyState.closeOverlay(
|
||||
InstructionsEnum.emptyChatWarning.toString(),
|
||||
);
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@ class OverlayHeader extends StatelessWidget {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = L10n.of(context);
|
||||
final theme = Theme.of(context);
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20),
|
||||
decoration: BoxDecoration(
|
||||
|
|
@ -26,73 +28,76 @@ class OverlayHeader extends StatelessWidget {
|
|||
bottomLeft: Radius.circular(AppConfig.borderRadius),
|
||||
bottomRight: Radius.circular(AppConfig.borderRadius),
|
||||
),
|
||||
color: Theme.of(context).appBarTheme.backgroundColor ??
|
||||
Theme.of(context).colorScheme.surfaceContainerHighest,
|
||||
color: theme.appBarTheme.backgroundColor ??
|
||||
theme.colorScheme.surfaceContainerHighest,
|
||||
),
|
||||
height: Theme.of(context).appBarTheme.toolbarHeight ??
|
||||
AppConfig.defaultHeaderHeight,
|
||||
height: theme.appBarTheme.toolbarHeight ?? AppConfig.defaultHeaderHeight,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
if (controller.selectedEvents.length == 1)
|
||||
IconButton(
|
||||
icon: const Icon(Symbols.reply_all),
|
||||
tooltip: L10n.of(context).reply,
|
||||
tooltip: l10n.reply,
|
||||
onPressed: controller.replyAction,
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
color: theme.colorScheme.primary,
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Symbols.forward),
|
||||
tooltip: L10n.of(context).forward,
|
||||
tooltip: l10n.forward,
|
||||
onPressed: controller.forwardEventsAction,
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
color: theme.colorScheme.primary,
|
||||
),
|
||||
if (controller.selectedEvents.length == 1 &&
|
||||
controller.selectedEvents.single.messageType == MessageTypes.Text)
|
||||
IconButton(
|
||||
icon: const Icon(Icons.copy_outlined),
|
||||
tooltip: L10n.of(context).copy,
|
||||
tooltip: l10n.copy,
|
||||
onPressed: controller.copyEventsAction,
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
color: theme.colorScheme.primary,
|
||||
),
|
||||
if (controller.canPinSelectedEvents)
|
||||
IconButton(
|
||||
icon: const Icon(Icons.push_pin_outlined),
|
||||
onPressed: controller.pinEvent,
|
||||
tooltip: L10n.of(context).pinMessage,
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
tooltip: l10n.pinMessage,
|
||||
color: theme.colorScheme.primary,
|
||||
),
|
||||
if (controller.canEditSelectedEvents &&
|
||||
!controller.selectedEvents.first.isActivityMessage)
|
||||
IconButton(
|
||||
icon: const Icon(Icons.edit_outlined),
|
||||
tooltip: L10n.of(context).edit,
|
||||
tooltip: l10n.edit,
|
||||
onPressed: controller.editSelectedEventAction,
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
color: theme.colorScheme.primary,
|
||||
),
|
||||
if (controller.canRedactSelectedEvents)
|
||||
IconButton(
|
||||
icon: const Icon(Icons.delete_outlined),
|
||||
tooltip: L10n.of(context).redactMessage,
|
||||
tooltip: l10n.redactMessage,
|
||||
onPressed: controller.redactEventsAction,
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
color: theme.colorScheme.primary,
|
||||
),
|
||||
if (controller.selectedEvents.length == 1)
|
||||
IconButton(
|
||||
icon: const Icon(Icons.shield_outlined),
|
||||
tooltip: L10n.of(context).reportMessage,
|
||||
onPressed: () => reportEvent(
|
||||
controller.selectedEvents.first,
|
||||
controller,
|
||||
context,
|
||||
),
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
tooltip: l10n.reportMessage,
|
||||
onPressed: () {
|
||||
final event = controller.selectedEvents.first;
|
||||
controller.clearSelectedEvents();
|
||||
reportEvent(
|
||||
event,
|
||||
controller,
|
||||
controller.context,
|
||||
);
|
||||
},
|
||||
color: theme.colorScheme.primary,
|
||||
),
|
||||
if (controller.selectedEvents.length == 1)
|
||||
IconButton(
|
||||
icon: const Icon(Icons.info_outlined),
|
||||
tooltip: L10n.of(context).messageInfo,
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
tooltip: l10n.messageInfo,
|
||||
color: theme.colorScheme.primary,
|
||||
onPressed: () {
|
||||
controller.showEventInfo();
|
||||
controller.clearSelectedEvents();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue