mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2025-10-19 14:07:24 +02:00
Add simple client switcher buttons for within a bundle next to the input bar
This commit is contained in:
parent
8225c00e02
commit
08c09051ea
@ -222,6 +222,10 @@ class ChatController extends State<Chat> {
|
|||||||
|
|
||||||
TextEditingController sendController = TextEditingController();
|
TextEditingController sendController = TextEditingController();
|
||||||
|
|
||||||
|
void setActiveClient(Client c) => setState(() {
|
||||||
|
Matrix.of(context).setActiveClient(c);
|
||||||
|
});
|
||||||
|
|
||||||
Future<void> send() async {
|
Future<void> send() async {
|
||||||
if (sendController.text.trim().isEmpty) return;
|
if (sendController.text.trim().isEmpty) return;
|
||||||
var parseCommands = true;
|
var parseCommands = true;
|
||||||
|
@ -37,9 +37,9 @@ class ChatView extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
controller.matrix = Matrix.of(context);
|
controller.matrix ??= Matrix.of(context);
|
||||||
final client = controller.matrix.client;
|
final client = controller.matrix.client;
|
||||||
controller.room ??= client.getRoomById(controller.roomId);
|
controller.room = client.getRoomById(controller.roomId);
|
||||||
if (controller.room == null) {
|
if (controller.room == null) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
@ -680,6 +680,14 @@ class ChatView extends StatelessWidget {
|
|||||||
alignment: Alignment.center,
|
alignment: Alignment.center,
|
||||||
child: EncryptionButton(controller.room),
|
child: EncryptionButton(controller.room),
|
||||||
),
|
),
|
||||||
|
if (controller.matrix.isMultiAccount &&
|
||||||
|
controller.matrix.currentBundle.length >
|
||||||
|
1)
|
||||||
|
Container(
|
||||||
|
height: 56,
|
||||||
|
alignment: Alignment.center,
|
||||||
|
child: _ChatAccountPicker(controller),
|
||||||
|
),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.symmetric(
|
padding: const EdgeInsets.symmetric(
|
||||||
@ -792,3 +800,55 @@ class _EditContent extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class _ChatAccountPicker extends StatelessWidget {
|
||||||
|
final ChatController controller;
|
||||||
|
|
||||||
|
const _ChatAccountPicker(this.controller, {Key key}) : super(key: key);
|
||||||
|
|
||||||
|
void _popupMenuButtonSelected(String mxid) {
|
||||||
|
final client = controller.matrix.currentBundle
|
||||||
|
.firstWhere((cl) => cl.userID == mxid, orElse: () => null);
|
||||||
|
if (client == null) {
|
||||||
|
Logs().w('Attempted to switch to a non-existing client $mxid');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
controller.setActiveClient(client);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
controller.matrix ??= Matrix.of(context);
|
||||||
|
final clients = controller.matrix.currentBundle;
|
||||||
|
clients.removeWhere((c) => c.getRoomById(controller.roomId) == null);
|
||||||
|
return FutureBuilder<Profile>(
|
||||||
|
future: controller.matrix.client.ownProfile,
|
||||||
|
builder: (context, snapshot) => PopupMenuButton<String>(
|
||||||
|
onSelected: _popupMenuButtonSelected,
|
||||||
|
itemBuilder: (BuildContext context) => clients
|
||||||
|
.map((client) => PopupMenuItem<String>(
|
||||||
|
value: client.userID,
|
||||||
|
child: FutureBuilder<Profile>(
|
||||||
|
future: client.ownProfile,
|
||||||
|
builder: (context, snapshot) => ListTile(
|
||||||
|
leading: Avatar(
|
||||||
|
snapshot.data?.avatarUrl,
|
||||||
|
snapshot.data?.displayName ?? client.userID.localpart,
|
||||||
|
size: 20,
|
||||||
|
),
|
||||||
|
title: Text(snapshot.data?.displayName ?? client.userID),
|
||||||
|
contentPadding: EdgeInsets.all(0),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
))
|
||||||
|
.toList(),
|
||||||
|
child: Avatar(
|
||||||
|
snapshot.data?.avatarUrl,
|
||||||
|
snapshot.data?.displayName ??
|
||||||
|
controller.matrix.client.userID.localpart,
|
||||||
|
size: 20,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -80,6 +80,23 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
|
|||||||
return activeClient;
|
return activeClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setActiveClient(Client cl) {
|
||||||
|
final i = widget.clients.indexWhere((c) => c == cl);
|
||||||
|
if (i != null) {
|
||||||
|
activeClient = i;
|
||||||
|
} else {
|
||||||
|
Logs().w('Tried to set an unknown client ${cl.userID} as active');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Client> get currentBundle {
|
||||||
|
final bundles = accountBundles;
|
||||||
|
if (bundles.containsKey(activeBundle)) {
|
||||||
|
return bundles[activeBundle];
|
||||||
|
}
|
||||||
|
return bundles.values.first;
|
||||||
|
}
|
||||||
|
|
||||||
Map<String, List<Client>> get accountBundles {
|
Map<String, List<Client>> get accountBundles {
|
||||||
final resBundles = <String, List<_AccountBundleWithClient>>{};
|
final resBundles = <String, List<_AccountBundleWithClient>>{};
|
||||||
for (var i = 0; i < widget.clients.length; i++) {
|
for (var i = 0; i < widget.clients.length; i++) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user