Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chat muting/unmuting (#63) #172

Merged
merged 40 commits into from
Nov 15, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
a981fe0
some changes
skazkiful Oct 12, 2022
529c5df
Merge remote-tracking branch 'origin/main' into 63-chat-muting-and-un…
skazkiful Oct 17, 2022
6cda259
some changes
skazkiful Oct 17, 2022
65efb02
Some changes
skazkiful Oct 18, 2022
255bb90
Fix CI
skazkiful Oct 18, 2022
11dfd7d
Change parser
skazkiful Oct 19, 2022
2d37d8b
Some changes
skazkiful Oct 19, 2022
0b1ffd9
Some changes
skazkiful Oct 19, 2022
25b86c5
Corrections
krida2000 Oct 20, 2022
6ae74de
Some changes
skazkiful Oct 24, 2022
acb606b
Final fixes
skazkiful Oct 24, 2022
39715ec
Merge remote-tracking branch 'origin/main' into 63-chat-muting-and-un…
skazkiful Oct 24, 2022
9c47759
Final fixes
skazkiful Oct 24, 2022
d5bf226
Fix ci
skazkiful Oct 24, 2022
4e0806c
Fix ci
skazkiful Oct 25, 2022
4dcb11e
Corrections
krida2000 Oct 25, 2022
3120bd7
Merge remote-tracking branch 'origin/main' into 63-chat-muting-and-un…
krida2000 Oct 25, 2022
e974d7f
Merge remote-tracking branch 'origin/main' into 63-chat-muting-and-un…
skazkiful Oct 31, 2022
a6ef013
Some changes
skazkiful Oct 31, 2022
7c59446
Merge remote-tracking branch 'origin/main' into 63-chat-muting-and-un…
SleepySquash Nov 3, 2022
98a0c33
Corrections
SleepySquash Nov 3, 2022
34604b8
some changes
skazkiful Nov 3, 2022
eeac580
try ci
skazkiful Nov 4, 2022
a64eb3e
some changes
skazkiful Nov 7, 2022
2054329
Merge branch 'main' into 63-chat-muting-and-unmuting
skazkiful Nov 7, 2022
2fcb8a3
some changes
skazkiful Nov 7, 2022
ae232d2
Merge branch 'main' into 63-chat-muting-and-unmuting
skazkiful Nov 8, 2022
bf318e8
changes
skazkiful Nov 8, 2022
a9e1cb8
some changes
skazkiful Nov 9, 2022
e78cdfa
small changes
skazkiful Nov 11, 2022
9cd8a28
Merge branch 'main' into 63-chat-muting-and-unmuting
skazkiful Nov 11, 2022
fa30ec1
fix ci
skazkiful Nov 11, 2022
a2e926b
Merge remote-tracking branch 'origin/main' into 63-chat-muting-and-un…
SleepySquash Nov 14, 2022
fc1cc62
Corrections
SleepySquash Nov 14, 2022
c4252f9
Corrections
SleepySquash Nov 14, 2022
00c8539
some changes
skazkiful Nov 14, 2022
1f44b63
some changes
skazkiful Nov 14, 2022
f36588b
some changes
skazkiful Nov 14, 2022
c82ae4e
changes
skazkiful Nov 15, 2022
466c15c
Minor correction
SleepySquash Nov 15, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 0 additions & 24 deletions lib/ui/page/home/tab/chats/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import 'dart:async';
import 'dart:collection';

import 'package:async/async.dart';
import 'package:get/get.dart';

import '/domain/model/chat.dart';
Expand Down Expand Up @@ -57,26 +56,6 @@ class ChatsTabController extends GetxController {
/// Reactive list of sorted [Chat]s.
late final RxList<RxChat> chats;

/// List of the mute periods.
///
/// `null` meaning mute forever.
final List<Duration?> muteDateTimes = [
const Duration(minutes: 15),
const Duration(minutes: 30),
const Duration(hours: 1),
const Duration(hours: 6),
const Duration(hours: 12),
const Duration(days: 1),
const Duration(days: 7),
null,
];

/// Indicates whether the mute chat dialog is opened or not.
final Rx<ChatId?> openedMuteDialogChatId = Rx<ChatId?>(null);

/// [CancelableOperation] of mute popup.
final Rx<CancelableOperation?> mutePopup = Rx<CancelableOperation?>(null);

/// [Chat]s service used to update the [chats].
final ChatService _chatService;

Expand Down Expand Up @@ -122,9 +101,6 @@ class ChatsTabController extends GetxController {
break;

case OperationKind.removed:
if (openedMuteDialogChatId.value == event.key) {
mutePopup.value?.cancel();
}
_sortingData.remove(event.key)?.dispose();
chats.removeWhere((e) => e.chat.value.id == event.key);
break;
Expand Down
43 changes: 10 additions & 33 deletions lib/ui/page/home/tab/chats/view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ import 'package:get/get.dart';
import '/domain/repository/chat.dart';
import '/l10n/l10n.dart';
import '/ui/page/home/widget/app_bar.dart';
import '/ui/page/home/widget/confirm_dialog.dart';
import '/ui/widget/menu_interceptor/menu_interceptor.dart';
import '/ui/widget/svg/svg.dart';
import '/ui/widget/widget_button.dart';
import 'controller.dart';
import 'create_group/controller.dart';
import 'widget/mute_chat_popup.dart';
import 'widget/recent_chat.dart';

/// View of the `HomeTab.chats` tab.
Expand Down Expand Up @@ -100,38 +100,15 @@ class ChatsTabView extends StatelessWidget {
onLeave: () => c.leaveChat(chat.id),
onHide: () => c.hideChat(chat.id),
inCall: () => c.inCall(chat.id),
muteDialogOpened: () async {
c.openedMuteDialogChatId.value = chat.id;
c.mutePopup.value =
await ConfirmDialog.showCancelable(
context,
title: 'label_mute_chat_for'.l10n,
onClosed: () {
c.openedMuteDialogChatId.value = null;
},
variants: c.muteDateTimes
.map(
(e) => ConfirmDialogVariant(
onProceed: () => c.muteChat(
chat.id,
duration: e,
),
child: Text(
'label_mute_for'.l10nfmt({
'days': e?.inDays ?? 0,
'hours': e?.inHours ?? 0,
'minutes': e?.inMinutes ?? 0,
}),
key: e == null
? const Key('MuteForever')
: null,
),
),
)
.toList(),
);
},
unmuteChat: () => c.unmuteChat(chat.id),
onMuteDialogOpened: () => MuteChatPopup.show(
skazkiful marked this conversation as resolved.
Show resolved Hide resolved
context,
chatId: chat.id,
onMute: (duration) => c.muteChat(
chat.id,
duration: duration,
),
),
onUnmuteChat: () => c.unmuteChat(chat.id),
),
),
),
Expand Down
76 changes: 76 additions & 0 deletions lib/ui/page/home/tab/chats/widget/mute_chat_popup.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// Copyright © 2022 IT ENGINEERING MANAGEMENT INC, <https://github.com/team113>
//
// This program is free software: you can redistribute it and/or modify it under
// the terms of the GNU Affero General Public License v3.0 as published by the
// Free Software Foundation, either version 3 of the License, or (at your
// option) any later version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License v3.0 for
// more details.
//
// You should have received a copy of the GNU Affero General Public License v3.0
// along with this program. If not, see
// <https://www.gnu.org/licenses/agpl-3.0.html>.

import 'package:flutter/material.dart';
import 'package:get/get.dart';

import '/domain/model/chat.dart';
import '/domain/service/chat.dart';
import '/l10n/l10n.dart';
import '/ui/page/home/widget/confirm_dialog.dart';
import '/ui/widget/modal_popup.dart';
import '/util/obs/obs.dart';

class MuteChatPopup {
skazkiful marked this conversation as resolved.
Show resolved Hide resolved
static void show(
BuildContext context, {
Function(Duration? duration)? onMute,
required ChatId chatId,
}) async {
// [Chat]s service.
final ChatService chatService = Get.find();
skazkiful marked this conversation as resolved.
Show resolved Hide resolved

// Subscription for [ChatService.chats] changes.
final chatsSubscription = chatService.chats.changes.listen((event) {
if (event.op == OperationKind.removed && chatId == event.key) {
Navigator.of(context).pop();
}
});

await ModalPopup.show<ConfirmDialog?>(
context: context,
child: ConfirmDialog(
skazkiful marked this conversation as resolved.
Show resolved Hide resolved
title: 'label_mute_chat_for'.l10n,
variants: const [
Duration(minutes: 15),
Duration(minutes: 30),
Duration(hours: 1),
Duration(hours: 6),
Duration(hours: 12),
Duration(days: 1),
Duration(days: 7),
null,
]
.map(
(e) => ConfirmDialogVariant(
onProceed: () => onMute?.call(e),
child: Text(
'label_mute_for'.l10nfmt({
'days': e?.inDays ?? 0,
'hours': e?.inHours ?? 0,
'minutes': e?.inMinutes ?? 0,
}),
key: e == null ? const Key('MuteForever') : null,
),
),
)
.toList(),
),
);

chatsSubscription.cancel();
}
}
12 changes: 6 additions & 6 deletions lib/ui/page/home/tab/chats/widget/recent_chat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ class RecentChatTile extends StatelessWidget {
this.onHide,
this.onDrop,
this.onJoin,
this.muteDialogOpened,
this.unmuteChat,
this.onMuteDialogOpened,
this.onUnmuteChat,
}) : super(key: key);

/// [RxChat] this [RecentChatTile] is about.
Expand Down Expand Up @@ -83,10 +83,10 @@ class RecentChatTile extends StatelessWidget {
final void Function()? onJoin;

/// Callback, called when open mute dialog action is triggered.
final void Function()? muteDialogOpened;
final void Function()? onMuteDialogOpened;

/// Callback, called when this [rxChat] unmute action is triggered.
final void Function()? unmuteChat;
final void Function()? onUnmuteChat;

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -174,12 +174,12 @@ class RecentChatTile extends StatelessWidget {
? ContextMenuButton(
key: const Key('MuteChatButton'),
label: 'btn_mute_chat'.l10n,
onPressed: muteDialogOpened,
onPressed: onMuteDialogOpened,
)
: ContextMenuButton(
key: const Key('UnmuteChatButton'),
label: 'btn_unmute_chat'.l10n,
onPressed: unmuteChat,
onPressed: onUnmuteChat,
),
],
selected: selected,
Expand Down
32 changes: 0 additions & 32 deletions lib/ui/page/home/widget/confirm_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
// along with this program. If not, see
// <https://www.gnu.org/licenses/agpl-3.0.html>.

import 'package:async/async.dart';
import 'package:flutter/material.dart';

import '/l10n/l10n.dart';
Expand Down Expand Up @@ -54,37 +53,6 @@ class ConfirmDialog extends StatefulWidget {
/// Optional description to display above the [variants].
final String? description;

/// Returns [CancelableOperation] and displays a [ConfirmDialog] wrapped in
/// a [ModalPopup].
static Future<CancelableOperation> showCancelable(
BuildContext context, {
String? description,
Function? onClosed,
required String title,
required List<ConfirmDialogVariant> variants,
}) async {
bool isClosed = false;
return CancelableOperation.fromFuture(
Future(() async {
await ModalPopup.show<ConfirmDialog?>(
context: context,
child: ConfirmDialog(
description: description,
title: title,
variants: variants,
),
);
isClosed = true;
onClosed?.call();
}),
onCancel: () {
if (!isClosed) {
Navigator.of(context).pop();
}
},
);
}

/// Displays a [ConfirmDialog] wrapped in a [ModalPopup].
static Future<ConfirmDialog?> show(
BuildContext context, {
Expand Down