chore: on click of chat invite, show dialog asking user to accept or decline (#2007)
This commit is contained in:
parent
90faab6068
commit
8819499500
2 changed files with 51 additions and 58 deletions
|
|
@ -43,6 +43,7 @@ import '../../widgets/matrix.dart';
|
|||
import 'package:fluffychat/utils/tor_stub.dart'
|
||||
if (dart.library.html) 'package:tor_detector_web/tor_detector_web.dart';
|
||||
|
||||
|
||||
enum PopupMenuAction {
|
||||
settings,
|
||||
invite,
|
||||
|
|
@ -131,23 +132,59 @@ class ChatListController extends State<ChatList>
|
|||
});
|
||||
context.go("/rooms");
|
||||
}
|
||||
|
||||
/// show alert dialog prompting user to accept invite or reject invite
|
||||
Future<void> showInviteDialog(Room room) async {
|
||||
final acceptInvite = await showOkCancelAlertDialog(
|
||||
context: context,
|
||||
title: L10n.of(context).youreInvited,
|
||||
message: room.isSpace
|
||||
? L10n.of(context).invitedToSpace(room.name, room.creatorId ?? "???")
|
||||
: L10n.of(context).invitedToChat(room.name, room.creatorId ?? "???"),
|
||||
okLabel: L10n.of(context).accept,
|
||||
cancelLabel: L10n.of(context).decline,
|
||||
);
|
||||
|
||||
await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () async {
|
||||
if (acceptInvite == OkCancelResult.ok) {
|
||||
await room.join();
|
||||
if (room.isSpace) {
|
||||
setActiveSpace(room.id);
|
||||
context.go(
|
||||
FluffyThemes.isColumnMode(context)
|
||||
? "/rooms/${room.id}/details"
|
||||
: "/rooms",
|
||||
);
|
||||
return;
|
||||
}
|
||||
context.go("/rooms/${room.id}");
|
||||
return;
|
||||
}
|
||||
await room.leave();
|
||||
},
|
||||
);
|
||||
}
|
||||
// Pangea#
|
||||
|
||||
void onChatTap(Room room) async {
|
||||
if (room.membership == Membership.invite) {
|
||||
final joinResult = await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () async {
|
||||
final waitForRoom = room.client.waitForRoomInSync(
|
||||
room.id,
|
||||
join: true,
|
||||
);
|
||||
await room.join();
|
||||
await waitForRoom;
|
||||
},
|
||||
exceptionContext: ExceptionContext.joinRoom,
|
||||
);
|
||||
if (joinResult.error != null) return;
|
||||
await showInviteDialog(room);
|
||||
return;
|
||||
// final joinResult = await showFutureLoadingDialog(
|
||||
// context: context,
|
||||
// future: () async {
|
||||
// final waitForRoom = room.client.waitForRoomInSync(
|
||||
// room.id,
|
||||
// join: true,
|
||||
// );
|
||||
// await room.join();
|
||||
// await waitForRoom;
|
||||
// },
|
||||
// exceptionContext: ExceptionContext.joinRoom,
|
||||
// );
|
||||
// if (joinResult.error != null) return;
|
||||
}
|
||||
|
||||
if (room.membership == Membership.ban) {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
|
||||
|
|
@ -8,7 +7,6 @@ import 'package:fluffychat/config/themes.dart';
|
|||
import 'package:fluffychat/pages/chat_list/chat_list.dart';
|
||||
import 'package:fluffychat/pangea/common/constants/local.key.dart';
|
||||
import 'package:fluffychat/pangea/extensions/pangea_room_extension.dart';
|
||||
import 'package:fluffychat/widgets/adaptive_dialogs/show_ok_cancel_alert_dialog.dart';
|
||||
import 'package:fluffychat/widgets/future_loading_dialog.dart';
|
||||
import 'package:fluffychat/widgets/matrix.dart';
|
||||
import '../../common/utils/error_handler.dart';
|
||||
|
|
@ -40,48 +38,6 @@ void chatListHandleSpaceTap(
|
|||
);
|
||||
}
|
||||
|
||||
//show alert dialog prompting user to accept invite or reject
|
||||
//if accepted, setActiveSpaceAndCloseChat()
|
||||
//if rejected, leave space
|
||||
// use standard alert diolog, not cupertino
|
||||
Future<void> showAlertDialog(BuildContext context) async {
|
||||
final acceptInvite = await showOkCancelAlertDialog(
|
||||
context: context,
|
||||
title: L10n.of(context).youreInvited,
|
||||
message: space.isSpace
|
||||
? L10n.of(context)
|
||||
.invitedToSpace(space.name, space.creatorId ?? "???")
|
||||
: L10n.of(context)
|
||||
.invitedToChat(space.name, space.creatorId ?? "???"),
|
||||
okLabel: L10n.of(context).accept,
|
||||
cancelLabel: L10n.of(context).decline,
|
||||
);
|
||||
|
||||
if (acceptInvite == OkCancelResult.ok) {
|
||||
await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () async {
|
||||
await space.join();
|
||||
setActiveSpaceAndCloseChat();
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(L10n.of(context).acceptedInvitation),
|
||||
duration: const Duration(seconds: 3),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
} else {
|
||||
await space.leave();
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(L10n.of(context).declinedInvitation),
|
||||
duration: const Duration(seconds: 3),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
switch (space.membership) {
|
||||
case Membership.join:
|
||||
setActiveSpaceAndCloseChat();
|
||||
|
|
@ -103,7 +59,7 @@ void chatListHandleSpaceTap(
|
|||
justInputtedCode == space.classCode) {
|
||||
// do nothing
|
||||
} else {
|
||||
showAlertDialog(context);
|
||||
controller.showInviteDialog(space);
|
||||
}
|
||||
break;
|
||||
case Membership.leave:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue