Skip to content

Commit

Permalink
krille-chan#91 FluffyChat: refactor read receipt (removed ReadReceipt…
Browse files Browse the repository at this point in the history
…OverviewController from Message), needs changes in famedlysdk
  • Loading branch information
carowebtec authored and Matthias committed Apr 25, 2023
1 parent e1ee0dd commit 58119bb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 43 deletions.
11 changes: 1 addition & 10 deletions lib/pages/chat/events/message.dart
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
import 'package:flutter/material.dart';

import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:matrix/matrix.dart';
import 'package:swipe_to_action/swipe_to_action.dart';

import 'package:fluffychat/config/themes.dart';
import 'package:fluffychat/utils/date_time_extension.dart';
import 'package:fluffychat/utils/string_color.dart';
import 'package:fluffychat/widgets/avatar.dart';
import 'package:fluffychat/widgets/matrix.dart';
import '../../../config/app_config.dart';
import '../../read_receipt_overview/read_receipt_overview.dart';
import 'message_content.dart';
import 'message_reactions.dart';
import 'reply_content.dart';
import 'state_message.dart';
import 'verification_request_content.dart';

// import 'package:fluffychat/config/edu_settings.dart';

class Message extends StatelessWidget {
final Event event;
final Event? nextEvent;
Expand All @@ -32,7 +27,6 @@ class Message extends StatelessWidget {
final bool selected;
final Timeline timeline;
final String? searchTerm;
final ReadReceiptOverviewController? readReceiptOverviewController;

const Message(this.event,
{this.nextEvent,
Expand All @@ -46,7 +40,6 @@ class Message extends StatelessWidget {
this.selected = false,
required this.timeline,
this.searchTerm,
this.readReceiptOverviewController,
Key? key})
: super(key: key);

Expand Down Expand Up @@ -153,9 +146,7 @@ class Message extends StatelessWidget {
color: AppConfig.primaryColor,
),
)
: (readReceiptOverviewController != null &&
readReceiptOverviewController!
.readReceiptInProgress(event))
: (event.isReadReceiptGiving)
? const SizedBox(
width: 22,
height: 22,
Expand Down
37 changes: 13 additions & 24 deletions lib/pages/read_receipt_overview/read_receipt_overview.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import 'dart:async';

import 'package:flutter/material.dart';

import 'package:matrix/matrix.dart';

import 'package:fluffychat/pages/chat/read_receipt/read_receipt_extension.dart';
import 'package:fluffychat/widgets/matrix.dart';
import 'read_receipt_overview_view.dart';
Expand All @@ -18,7 +15,7 @@ class ReadReceiptOverviewPage extends StatefulWidget {

class ExpansionPanelItem {
List<Event> readReceiptRequests = [];
Map<String, MessageItem> messageItems = {};
Map<String, Event> messages = {};
bool messagesLoaded = false;
Timeline? timeline;
Room? room;
Expand All @@ -29,13 +26,6 @@ class ExpansionPanelItem {
ExpansionPanelItem(Room this.room);
}

class MessageItem {
final Event message;
bool readReceiptInProgress = false;

MessageItem(this.message);
}

class ReadReceiptOverviewController extends State<ReadReceiptOverviewPage> {
Map<String, ExpansionPanelItem> panelItems = {};
final Map<String, Map<String, Event>> _localStorageEvents = {};
Expand Down Expand Up @@ -147,7 +137,7 @@ class ReadReceiptOverviewController extends State<ReadReceiptOverviewPage> {
await _addParentToMessages(event, panelItem);

setState(() {
panelItem.messageItems;
panelItem.messages;
panelItem.hasToGiveReadReceipt =
_client!.roomsWithOpenReadReceipts.contains(room.id);
});
Expand All @@ -167,7 +157,7 @@ class ReadReceiptOverviewController extends State<ReadReceiptOverviewPage> {
final String roomId = panelItem.room!.id;

panelItem.timeline = await _getTimeline(panelItem.room);
panelItem.messageItems.clear();
panelItem.messages.clear();

if (_client!.readReceiptRequests.containsKey(roomId)) {
for (final MatrixEvent mEvent
Expand All @@ -178,7 +168,7 @@ class ReadReceiptOverviewController extends State<ReadReceiptOverviewPage> {

setState(() {
panelItem.messagesLoaded = true;
panelItem.messageItems;
panelItem.messages;
});
}
}
Expand Down Expand Up @@ -207,8 +197,7 @@ class ReadReceiptOverviewController extends State<ReadReceiptOverviewPage> {

// events from sync are sorted chronologically up
// but we need latest event first -> therefore insert(0, ...
panelItem.messageItems
.addAll({parentEvent.eventId: MessageItem(parentEvent)});
panelItem.messages.addAll({parentEvent.eventId: parentEvent});
return true;
}
}
Expand Down Expand Up @@ -281,11 +270,11 @@ class ReadReceiptOverviewController extends State<ReadReceiptOverviewPage> {
return parentEvent;
}

void onReadReceiptClick(Event event, ExpansionPanelItem panelItem,
MessageItem messageItem) async {
if (!messageItem.readReceiptInProgress) {
void onReadReceiptClick(
Event event, ExpansionPanelItem panelItem, Event message) async {
if (!message.isReadReceiptGiving) {
setState(() {
messageItem.readReceiptInProgress = true;
message.isReadReceiptGiving = true;
});

final String? readReceiptEventId = await event.onReadReceiptIconClick(
Expand All @@ -307,9 +296,9 @@ class ReadReceiptOverviewController extends State<ReadReceiptOverviewPage> {
_updateOpenReadReceipt(panelItem);
_sortPanelItems();

messageItem.readReceiptInProgress = false;
message.isReadReceiptGiving = false;
setState(() {
messageItem;
message;
});
}
}
Expand All @@ -320,8 +309,8 @@ class ReadReceiptOverviewController extends State<ReadReceiptOverviewPage> {
if (panelItems.containsKey(event.roomId)) {
final panelItem = panelItems[event.roomId]!;

if (panelItem.messageItems.containsKey(event.eventId)) {
return panelItem.messageItems[event.eventId]!.readReceiptInProgress;
if (panelItem.messages.containsKey(event.eventId)) {
return panelItem.messages[event.eventId]!.isReadReceiptGiving;
}
}

Expand Down
14 changes: 5 additions & 9 deletions lib/pages/read_receipt_overview/read_receipt_overview_view.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

import 'package:flutter_gen/gen_l10n/l10n.dart';

import 'package:fluffychat/config/app_config.dart';
import 'package:fluffychat/pages/chat/events/message.dart';
import 'package:fluffychat/widgets/avatar.dart';
Expand Down Expand Up @@ -98,33 +96,31 @@ class ReadReceiptOverviewView extends StatelessWidget {
child: item.messagesLoaded == true
? Column(
children: [
if (item.messageItems.isEmpty)
if (item.messages.isEmpty)
Text(
L10n.of(context)!
.noReadReceiptRequestsFound,
)
else
for (var messageItem in item
.messageItems.values
for (var message in item
.messages.values
.toList()
.reversed)
Padding(
padding: const EdgeInsets.only(
right: 25,
),
child: Message(
messageItem.message,
message,
onSwipe: (swipeDirection) {},
onReadReceipt: (event) =>
controller
.onReadReceiptClick(
event,
item,
messageItem),
message),
onSelect: (event) {},
timeline: item.timeline!,
readReceiptOverviewController:
controller,
),
),
],
Expand Down

0 comments on commit 58119bb

Please sign in to comment.