Merge branch 'mark_unread' into 'main'

feat: add ability to mark a room as unread

See merge request ChristianPauly/fluffychat-flutter!286
This commit is contained in:
Christian Pauly 2020-12-09 17:23:42 +00:00
commit 94d4cdbf7a
6 changed files with 73 additions and 44 deletions

View file

@ -1,12 +1,12 @@
import 'package:adaptive_dialog/adaptive_dialog.dart';
import 'package:flushbar/flushbar_helper.dart';
import 'package:circular_check_box/circular_check_box.dart';
import 'package:famedlysdk/famedlysdk.dart';
import 'package:fluffychat/utils/matrix_locals.dart';
import 'package:fluffychat/views/chat.dart';
import 'package:flutter/material.dart';
import 'package:fluffychat/utils/event_extension.dart';
import 'package:fluffychat/utils/matrix_locals.dart';
import 'package:fluffychat/utils/room_status_extension.dart';
import 'package:fluffychat/views/chat.dart';
import 'package:flushbar/flushbar_helper.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:pedantic/pedantic.dart';
@ -249,23 +249,25 @@ class ChatListItem extends StatelessWidget {
color: Theme.of(context).primaryColor,
),
),
if (room.notificationCount > 0)
if (room.isUnread)
Container(
padding: EdgeInsets.symmetric(horizontal: 7),
height: 20,
height: room.notificationCount > 0 ? 20 : 14,
decoration: BoxDecoration(
color: room.highlightCount > 0
color: room.highlightCount > 0 || room.markedUnread
? Colors.red
: Theme.of(context).primaryColor,
borderRadius: BorderRadius.circular(20),
),
child: Center(
child: Text(
room.notificationCount.toString(),
style: TextStyle(
color: Colors.white,
),
),
child: room.notificationCount > 0
? Text(
room.notificationCount.toString(),
style: TextStyle(
color: Colors.white,
),
)
: Container(),
),
),
],

View file

@ -1665,6 +1665,21 @@
"type": "text",
"placeholders": {}
},
"toggleFavorite": "Toggle Favorite",
"@toggleFavorite": {
"type": "text",
"placeholders": {}
},
"toggleMuted": "Toggle Muted",
"@toggleMuted": {
"type": "text",
"placeholders": {}
},
"toggleUnread": "Mark Read/Unread",
"@toggleUnread": {
"type": "text",
"placeholders": {}
},
"tryToSendAgain": "Try to send again",
"@tryToSendAgain": {
"type": "text",

View file

@ -4,7 +4,6 @@ import 'dart:math';
import 'package:adaptive_dialog/adaptive_dialog.dart';
import 'package:famedlysdk/famedlysdk.dart';
import 'package:file_picker_cross/file_picker_cross.dart';
import 'package:fluffychat/components/adaptive_page_layout.dart';
import 'package:fluffychat/components/avatar.dart';
@ -34,8 +33,8 @@ import 'package:swipe_to_action/swipe_to_action.dart';
import '../components/dialogs/send_file_dialog.dart';
import '../components/input_bar.dart';
import '../utils/matrix_file_extension.dart';
import '../config/app_config.dart';
import '../utils/matrix_file_extension.dart';
import 'chat_details.dart';
import 'chat_list.dart';
@ -181,9 +180,7 @@ class _ChatState extends State<_Chat> {
if (timeline == null) {
timeline = await room.getTimeline(onUpdate: updateView);
if (timeline.events.isNotEmpty) {
unawaited(room
.sendReadReceipt(timeline.events.first.eventId)
.catchError((err) {
unawaited(room.setUnread(false).catchError((err) {
if (err is MatrixException && err.errcode == 'M_FORBIDDEN') {
// ignore if the user is not in the room (still joining)
return;
@ -484,7 +481,6 @@ class _ChatState extends State<_Chat> {
}
final typingText = room.getLocalizedTypingText(context);
return Scaffold(
appBar: AppBar(
leading: selectMode
@ -624,7 +620,7 @@ class _ChatState extends State<_Chat> {
timeline != null &&
timeline.events.isNotEmpty &&
Matrix.of(context).webHasFocus) {
room.sendReadReceipt(timeline.events.first.eventId);
room.sendReadMarker(timeline.events.first.eventId);
}
final filteredEvents = getFilteredEvents();

View file

@ -140,6 +140,13 @@ class _ChatListState extends State<ChatList> {
super.dispose();
}
Future<void> _toggleUnread(BuildContext context) {
final room = Matrix.of(context).client.getRoomById(_selectedRoomIds.single);
return SimpleDialogs(context).tryRequestWithLoadingDialog(
room.setUnread(!room.isUnread),
);
}
Future<void> _toggleFavouriteRoom(BuildContext context) {
final room = Matrix.of(context).client.getRoomById(_selectedRoomIds.single);
return SimpleDialogs(context).tryRequestWithLoadingDialog(
@ -226,16 +233,25 @@ class _ChatListState extends State<ChatList> {
: [
if (_selectedRoomIds.length == 1)
IconButton(
tooltip: L10n.of(context).toggleUnread,
icon: Icon(Icons.mark_chat_unread_outlined),
onPressed: () => _toggleUnread(context),
),
if (_selectedRoomIds.length == 1)
IconButton(
tooltip: L10n.of(context).toggleFavorite,
icon: Icon(Icons.favorite_border_outlined),
onPressed: () => _toggleFavouriteRoom(context),
),
if (_selectedRoomIds.length == 1)
IconButton(
icon: Icon(Icons.notifications_none_outlined),
tooltip: L10n.of(context).toggleMuted,
onPressed: () => _toggleMuted(context),
),
IconButton(
icon: Icon(Icons.archive_outlined),
tooltip: L10n.of(context).archive,
onPressed: () => _archiveAction(context),
),
],