mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2024-11-05 19:49:29 +01:00
refactor: Use correct Matrix instance
This commit is contained in:
parent
f1a8716832
commit
507cd1f17e
@ -51,8 +51,6 @@ class ChatController extends State<Chat> {
|
|||||||
|
|
||||||
Timeline? timeline;
|
Timeline? timeline;
|
||||||
|
|
||||||
MatrixState? matrix;
|
|
||||||
|
|
||||||
String? readMarkerEventId;
|
String? readMarkerEventId;
|
||||||
|
|
||||||
String? get roomId => context.vRouter.pathParameters['roomid'];
|
String? get roomId => context.vRouter.pathParameters['roomid'];
|
||||||
@ -694,14 +692,14 @@ class ChatController extends State<Chat> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
List<Client?> get currentRoomBundle {
|
List<Client?> get currentRoomBundle {
|
||||||
final clients = matrix!.currentBundle!;
|
final clients = Matrix.of(context).currentBundle!;
|
||||||
clients.removeWhere((c) => c!.getRoomById(roomId!) == null);
|
clients.removeWhere((c) => c!.getRoomById(roomId!) == null);
|
||||||
return clients;
|
return clients;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool get canRedactSelectedEvents {
|
bool get canRedactSelectedEvents {
|
||||||
if (isArchived) return false;
|
if (isArchived) return false;
|
||||||
final clients = matrix!.currentBundle;
|
final clients = Matrix.of(context).currentBundle;
|
||||||
for (final event in selectedEvents) {
|
for (final event in selectedEvents) {
|
||||||
if (event.canRedact == false &&
|
if (event.canRedact == false &&
|
||||||
!(clients!.any((cl) => event.senderId == cl!.userID))) return false;
|
!(clients!.any((cl) => event.senderId == cl!.userID))) return false;
|
||||||
@ -1039,7 +1037,7 @@ class ChatController extends State<Chat> {
|
|||||||
await prefs.setString('draft_$roomId', text);
|
await prefs.setString('draft_$roomId', text);
|
||||||
});
|
});
|
||||||
setReadMarker();
|
setReadMarker();
|
||||||
if (text.endsWith(' ') && matrix!.hasComplexBundles) {
|
if (text.endsWith(' ') && Matrix.of(context).hasComplexBundles) {
|
||||||
final clients = currentRoomBundle;
|
final clients = currentRoomBundle;
|
||||||
for (final client in clients) {
|
for (final client in clients) {
|
||||||
final prefix = client!.sendPrefix;
|
final prefix = client!.sendPrefix;
|
||||||
|
@ -215,9 +215,9 @@ class ChatInputRow extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
if (controller.matrix!.isMultiAccount &&
|
if (Matrix.of(context).isMultiAccount &&
|
||||||
controller.matrix!.hasComplexBundles &&
|
Matrix.of(context).hasComplexBundles &&
|
||||||
controller.matrix!.currentBundle!.length > 1)
|
Matrix.of(context).currentBundle!.length > 1)
|
||||||
Container(
|
Container(
|
||||||
height: 56,
|
height: 56,
|
||||||
alignment: Alignment.center,
|
alignment: Alignment.center,
|
||||||
@ -279,8 +279,9 @@ class _ChatAccountPicker extends StatelessWidget {
|
|||||||
|
|
||||||
const _ChatAccountPicker(this.controller, {Key? key}) : super(key: key);
|
const _ChatAccountPicker(this.controller, {Key? key}) : super(key: key);
|
||||||
|
|
||||||
void _popupMenuButtonSelected(String mxid) {
|
void _popupMenuButtonSelected(String mxid, BuildContext context) {
|
||||||
final client = controller.matrix!.currentBundle!
|
final client = Matrix.of(context)
|
||||||
|
.currentBundle!
|
||||||
.firstWhere((cl) => cl!.userID == mxid, orElse: () => null);
|
.firstWhere((cl) => cl!.userID == mxid, orElse: () => null);
|
||||||
if (client == null) {
|
if (client == null) {
|
||||||
Logs().w('Attempted to switch to a non-existing client $mxid');
|
Logs().w('Attempted to switch to a non-existing client $mxid');
|
||||||
@ -291,14 +292,13 @@ class _ChatAccountPicker extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
controller.matrix ??= Matrix.of(context);
|
|
||||||
final clients = controller.currentRoomBundle;
|
final clients = controller.currentRoomBundle;
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: const EdgeInsets.all(8.0),
|
padding: const EdgeInsets.all(8.0),
|
||||||
child: FutureBuilder<Profile>(
|
child: FutureBuilder<Profile>(
|
||||||
future: controller.sendingClient!.fetchOwnProfile(),
|
future: controller.sendingClient!.fetchOwnProfile(),
|
||||||
builder: (context, snapshot) => PopupMenuButton<String>(
|
builder: (context, snapshot) => PopupMenuButton<String>(
|
||||||
onSelected: _popupMenuButtonSelected,
|
onSelected: (mxid) => _popupMenuButtonSelected(mxid, context),
|
||||||
itemBuilder: (BuildContext context) => clients
|
itemBuilder: (BuildContext context) => clients
|
||||||
.map(
|
.map(
|
||||||
(client) => PopupMenuItem<String>(
|
(client) => PopupMenuItem<String>(
|
||||||
@ -322,7 +322,7 @@ class _ChatAccountPicker extends StatelessWidget {
|
|||||||
child: Avatar(
|
child: Avatar(
|
||||||
mxContent: snapshot.data?.avatarUrl,
|
mxContent: snapshot.data?.avatarUrl,
|
||||||
name: snapshot.data?.displayName ??
|
name: snapshot.data?.displayName ??
|
||||||
controller.matrix!.client.userID!.localpart,
|
Matrix.of(context).client.userID!.localpart,
|
||||||
size: 20,
|
size: 20,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -139,8 +139,7 @@ class ChatView extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
controller.matrix ??= Matrix.of(context);
|
final client = Matrix.of(context).client;
|
||||||
final client = controller.matrix!.client;
|
|
||||||
controller.sendingClient ??= client;
|
controller.sendingClient ??= client;
|
||||||
controller.room = controller.sendingClient!.getRoomById(controller.roomId!);
|
controller.room = controller.sendingClient!.getRoomById(controller.roomId!);
|
||||||
controller.readMarkerEventId ??= controller.room!.fullyRead;
|
controller.readMarkerEventId ??= controller.room!.fullyRead;
|
||||||
|
Loading…
Reference in New Issue
Block a user