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

fix(quick switching): various switches related to quick switching #1135

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
19 changes: 12 additions & 7 deletions lib/pages/chat/chat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ class ChatController extends State<ChatPageWithRoom>
Future<void>? _setReadMarkerFuture;

void setReadMarker({String? eventId}) {
if (!mounted) return;
if (_setReadMarkerFuture != null) return;
if (_scrolledUp) return;
if (scrollUpBannerEventId != null) return;
Expand Down Expand Up @@ -430,17 +431,21 @@ class ChatController extends State<ChatPageWithRoom>
room.setTyping(false);
currentlyTyping = false;
}
// then cancel the old timeline
// fixes bug with read reciepts and quick switching
loadTimelineFuture = _getTimeline(eventContextId: room.fullyRead).onError(

setState(() {
sendingClient = c;
});

loadTimelineFuture = _getTimeline(eventContextId: room.fullyRead)
.onError(
ErrorReporter(
context,
'Unable to load timeline after changing sending Client',
).onErrorCallback,
);

// then set the new sending client
setState(() => sendingClient = c);
)
.then((_) {
setReadMarker();
});
}

void setActiveClient(Client c) => setState(() {
Expand Down
1 change: 1 addition & 0 deletions lib/pages/chat/chat_event_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ class ChatEventList extends StatelessWidget {
index: i,
controller: controller.scrollController,
child: Message(
controller,
event,
animateIn: animateIn,
resetAnimateIn: () {
Expand Down
2 changes: 1 addition & 1 deletion lib/pages/chat/chat_input_row.dart
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ class _ChatAccountPicker extends StatelessWidget {
child: Avatar(
mxContent: snapshot.data?.avatarUrl,
name: snapshot.data?.displayName ??
Matrix.of(context).client.userID!.localpart,
controller.sendingClient.userID!.localpart,
size: 20,
),
),
Expand Down
2 changes: 1 addition & 1 deletion lib/pages/chat/chat_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class ChatView extends StatelessWidget {
final bottomSheetPadding = FluffyThemes.isColumnMode(context) ? 16.0 : 8.0;
final scrollUpBannerEventId = controller.scrollUpBannerEventId;

final accountConfig = Matrix.of(context).client.applicationAccountConfig;
final accountConfig = controller.sendingClient.applicationAccountConfig;

return PopScope(
canPop: controller.selectedEvents.isEmpty && !controller.showEmojiPicker,
Expand Down
10 changes: 6 additions & 4 deletions lib/pages/chat/events/message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import 'package:matrix/matrix.dart';
import 'package:swipe_to_action/swipe_to_action.dart';

import 'package:fluffychat/config/themes.dart';
import 'package:fluffychat/pages/chat/chat.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 'message_content.dart';
import 'message_reactions.dart';
Expand All @@ -18,6 +18,7 @@ import 'state_message.dart';
import 'verification_request_content.dart';

class Message extends StatelessWidget {
final ChatController controller;
final Event event;
final Event? nextEvent;
final Event? previousEvent;
Expand All @@ -36,6 +37,7 @@ class Message extends StatelessWidget {
final Color? avatarPresenceBackgroundColor;

const Message(
this.controller,
this.event, {
this.nextEvent,
this.previousEvent,
Expand Down Expand Up @@ -74,8 +76,7 @@ class Message extends StatelessWidget {
return VerificationRequestContent(event: event, timeline: timeline);
}

final client = Matrix.of(context).client;
final ownMessage = event.senderId == client.userID;
final ownMessage = event.senderId == controller.sendingClient.userID;
final alignment = ownMessage ? Alignment.topRight : Alignment.topLeft;
// ignore: deprecated_member_use
var color = Theme.of(context).colorScheme.surfaceVariant;
Expand Down Expand Up @@ -369,6 +370,7 @@ class Message extends StatelessWidget {
},
),
MessageContent(
controller,
displayEvent,
textColor: textColor,
onInfoTab: onInfoTab,
Expand Down Expand Up @@ -468,7 +470,7 @@ class Message extends StatelessWidget {
left: (ownMessage ? 0 : Avatar.defaultSize) + 12.0,
right: ownMessage ? 0 : 12.0,
),
child: MessageReactions(event, timeline),
child: MessageReactions(controller, event, timeline),
),
),
if (displayReadMarker)
Expand Down
8 changes: 5 additions & 3 deletions lib/pages/chat/events/message_content.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:flutter_linkify/flutter_linkify.dart';
import 'package:matrix/matrix.dart';

import 'package:fluffychat/pages/chat/chat.dart';
import 'package:fluffychat/pages/chat/events/video_player.dart';
import 'package:fluffychat/utils/adaptive_bottom_sheet.dart';
import 'package:fluffychat/utils/date_time_extension.dart';
import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_locals.dart';
import 'package:fluffychat/widgets/avatar.dart';
import 'package:fluffychat/widgets/matrix.dart';
import '../../../config/app_config.dart';
import '../../../utils/platform_infos.dart';
import '../../../utils/url_launcher.dart';
Expand All @@ -24,12 +24,14 @@ import 'map_bubble.dart';
import 'message_download_content.dart';

class MessageContent extends StatelessWidget {
final ChatController controller;
final Event event;
final Color textColor;
final void Function(Event)? onInfoTab;
final BorderRadius borderRadius;

const MessageContent(
this.controller,
this.event, {
this.onInfoTab,
super.key,
Expand All @@ -49,10 +51,10 @@ class MessageContent extends StatelessWidget {
);
return;
}
final client = Matrix.of(context).client;
final client = controller.sendingClient;
if (client.isUnknownSession && client.encryption!.crossSigning.enabled) {
final success = await BootstrapDialog(
client: Matrix.of(context).client,
client: controller.sendingClient,
).show(context);
if (success != true) return;
}
Expand Down
12 changes: 9 additions & 3 deletions lib/pages/chat/events/message_reactions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,28 @@ import 'package:future_loading_dialog/future_loading_dialog.dart';
import 'package:matrix/matrix.dart';

import 'package:fluffychat/config/app_config.dart';
import 'package:fluffychat/pages/chat/chat.dart';
import 'package:fluffychat/widgets/avatar.dart';
import 'package:fluffychat/widgets/matrix.dart';
import 'package:fluffychat/widgets/mxc_image.dart';

class MessageReactions extends StatelessWidget {
final ChatController controller;
final Event event;
final Timeline timeline;

const MessageReactions(this.event, this.timeline, {super.key});
const MessageReactions(
this.controller,
this.event,
this.timeline, {
super.key,
});

@override
Widget build(BuildContext context) {
final allReactionEvents =
event.aggregatedEvents(timeline, RelationshipTypes.reaction);
final reactionMap = <String, _ReactionEntry>{};
final client = Matrix.of(context).client;
final client = controller.sendingClient;

for (final e in allReactionEvents) {
final key = e.content
Expand Down
3 changes: 1 addition & 2 deletions lib/pages/chat/seen_by_row.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import 'package:fluffychat/config/themes.dart';
import 'package:fluffychat/pages/chat/chat.dart';
import 'package:fluffychat/utils/room_status_extension.dart';
import 'package:fluffychat/widgets/avatar.dart';
import 'package:fluffychat/widgets/matrix.dart';

class SeenByRow extends StatelessWidget {
final ChatController controller;
Expand All @@ -27,7 +26,7 @@ class SeenByRow extends StatelessWidget {
curve: FluffyThemes.animationCurve,
alignment: controller.timeline!.events.isNotEmpty &&
controller.timeline!.events.first.senderId ==
Matrix.of(context).client.userID
controller.sendingClient.userID
? Alignment.topRight
: Alignment.topLeft,
padding: const EdgeInsets.only(left: 8, right: 8, bottom: 4),
Expand Down
5 changes: 2 additions & 3 deletions lib/pages/chat/typing_indicators.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import 'package:fluffychat/config/app_config.dart';
import 'package:fluffychat/config/themes.dart';
import 'package:fluffychat/pages/chat/chat.dart';
import 'package:fluffychat/widgets/avatar.dart';
import 'package:fluffychat/widgets/matrix.dart';

class TypingIndicators extends StatelessWidget {
final ChatController controller;
Expand All @@ -25,7 +24,7 @@ class TypingIndicators extends StatelessWidget {
),
builder: (context, _) {
final typingUsers = controller.room.typingUsers
..removeWhere((u) => u.stateKey == Matrix.of(context).client.userID);
..removeWhere((u) => u.stateKey == controller.sendingClient.userID);

return Container(
width: double.infinity,
Expand All @@ -38,7 +37,7 @@ class TypingIndicators extends StatelessWidget {
curve: FluffyThemes.animationCurve,
alignment: controller.timeline!.events.isNotEmpty &&
controller.timeline!.events.first.senderId ==
Matrix.of(context).client.userID
controller.sendingClient.userID
? Alignment.topRight
: Alignment.topLeft,
clipBehavior: Clip.hardEdge,
Expand Down