ROOMS
This commit is contained in:
parent
65028a1231
commit
aaeee8e355
10 changed files with 527 additions and 164 deletions
|
|
@ -1,7 +1,10 @@
|
|||
import "dart:io";
|
||||
|
||||
import "package:flutter/foundation.dart";
|
||||
import "package:matrix/matrix.dart";
|
||||
import "package:flutter_riverpod/flutter_riverpod.dart";
|
||||
import "package:path/path.dart";
|
||||
import "package:path_provider/path_provider.dart";
|
||||
import "package:sqflite_common_ffi/sqflite_ffi.dart";
|
||||
|
||||
class ClientController extends AsyncNotifier<Client> {
|
||||
|
|
@ -9,18 +12,27 @@ class ClientController extends AsyncNotifier<Client> {
|
|||
Future<Client> build() async {
|
||||
final client = Client(
|
||||
"nexus",
|
||||
logLevel: kReleaseMode ? Level.warning : Level.verbose,
|
||||
importantStateEvents: {"im.ponies.room_emotes"},
|
||||
database: await MatrixSdkDatabase.init(
|
||||
"nexus",
|
||||
database: await databaseFactoryFfi.openDatabase("./test.db"),
|
||||
database: await databaseFactoryFfi.openDatabase(
|
||||
join((await getApplicationSupportDirectory()).path, "database.db"),
|
||||
),
|
||||
),
|
||||
);
|
||||
//mxc
|
||||
await client.checkHomeserver(Uri.https("federated.nexus"));
|
||||
await client.login(
|
||||
LoginType.mLoginPassword,
|
||||
identifier: AuthenticationUserIdentifier(user: "quadradical"),
|
||||
password: File("./password.txt").readAsStringSync(),
|
||||
);
|
||||
|
||||
// TODO: Save info
|
||||
if (client.homeserver == null) {
|
||||
await client.checkHomeserver(Uri.https("federated.nexus"));
|
||||
}
|
||||
if (client.accessToken == null) {
|
||||
await client.login(
|
||||
LoginType.mLoginPassword,
|
||||
identifier: AuthenticationUserIdentifier(user: "quadradical"),
|
||||
password: File("./password.txt").readAsStringSync(),
|
||||
);
|
||||
}
|
||||
|
||||
return client;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,34 +2,13 @@ import "package:flutter_chat_core/flutter_chat_core.dart";
|
|||
import "package:flutter_riverpod/flutter_riverpod.dart";
|
||||
|
||||
class RoomChatController extends Notifier<ChatController> {
|
||||
RoomChatController(this.id);
|
||||
final String id;
|
||||
RoomChatController(this.roomId);
|
||||
final String roomId;
|
||||
|
||||
@override
|
||||
InMemoryChatController build() => InMemoryChatController(
|
||||
messages: [
|
||||
Message.text(id: "foo2", authorId: "foo", text: "**Some** text"),
|
||||
Message.text(
|
||||
id: "foo3",
|
||||
authorId: "foo5",
|
||||
text: "Some text 2 https://federated.nexus",
|
||||
),
|
||||
Message.text(
|
||||
id: "aksdjflkasdjf",
|
||||
authorId: "foo",
|
||||
text: "Some text 2 https://github.com/Henry-hiles/nixos",
|
||||
),
|
||||
Message.system(id: "foo4", authorId: "", text: "system"),
|
||||
Message.text(id: "foo6", authorId: "foo5", text: "Some text 2"),
|
||||
Message.image(
|
||||
id: "foo5",
|
||||
authorId: "foobar3",
|
||||
source:
|
||||
"https://henryhiles.com/_astro/federatedNexus.BvZmkdyc_2b28Im.webp",
|
||||
),
|
||||
Message.text(id: "foo7", authorId: "foobar3", text: "this has an image"),
|
||||
],
|
||||
);
|
||||
InMemoryChatController build() => InMemoryChatController();
|
||||
|
||||
// void setRoom(Room room) => state = (await ref.watch(ClientController.provider.future));
|
||||
|
||||
void send(String message) {
|
||||
state.insertMessage(
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
import "package:flutter/widgets.dart";
|
||||
import "package:matrix/matrix.dart";
|
||||
import "package:collection/collection.dart";
|
||||
import "package:flutter/material.dart";
|
||||
import "package:flutter_riverpod/flutter_riverpod.dart";
|
||||
import "package:nexus/controllers/client_controller.dart";
|
||||
import "package:nexus/helpers/extension_helper.dart";
|
||||
import "package:nexus/models/space.dart";
|
||||
|
||||
class SpacesController extends AsyncNotifier<List<Space>> {
|
||||
|
|
@ -9,25 +10,60 @@ class SpacesController extends AsyncNotifier<List<Space>> {
|
|||
Future<List<Space>> build() async {
|
||||
final client = await ref.watch(ClientController.provider.future);
|
||||
|
||||
return Future.wait(
|
||||
client.rooms.where((room) => room.isSpace).map((data) async {
|
||||
final thumb = await data.avatar?.getThumbnailUri(
|
||||
client,
|
||||
width: 40,
|
||||
height: 40,
|
||||
);
|
||||
return Space(
|
||||
roomData: data,
|
||||
avatar: thumb == null
|
||||
? null
|
||||
: Image.network(
|
||||
thumb.toString(),
|
||||
width: 40,
|
||||
headers: {"authorization": "Bearer ${client.accessToken}"},
|
||||
final topLevel = await Future.wait(
|
||||
client.rooms
|
||||
.where((room) => !room.isDirectChat)
|
||||
.where(
|
||||
(room) => client.rooms
|
||||
.where((room) => room.isSpace)
|
||||
.every(
|
||||
(match) => match.spaceChildren.every(
|
||||
(child) => child.roomId != room.id,
|
||||
),
|
||||
),
|
||||
);
|
||||
}),
|
||||
)
|
||||
.map((room) => room.fullRoom),
|
||||
);
|
||||
|
||||
final topLevelSpaces = topLevel.where((r) => r.roomData.isSpace).toList();
|
||||
final topLevelRooms = topLevel.where((r) => !r.roomData.isSpace).toList();
|
||||
|
||||
return [
|
||||
Space(
|
||||
title: "Home",
|
||||
children: topLevelRooms,
|
||||
avatar: Icon(Icons.home),
|
||||
fake: true,
|
||||
),
|
||||
Space(
|
||||
title: "Direct Messages",
|
||||
children: await Future.wait(
|
||||
client.rooms
|
||||
.where((room) => room.isDirectChat)
|
||||
.map((room) => room.fullRoom),
|
||||
),
|
||||
avatar: Icon(Icons.person),
|
||||
fake: true,
|
||||
),
|
||||
...(await Future.wait(
|
||||
topLevelSpaces.map(
|
||||
(space) async => Space(
|
||||
title: space.title,
|
||||
avatar: space.avatar,
|
||||
children: await Future.wait(
|
||||
space.roomData.spaceChildren
|
||||
.map(
|
||||
(child) => client.rooms.firstWhereOrNull(
|
||||
(room) => room.id == child.roomId,
|
||||
),
|
||||
)
|
||||
.nonNulls
|
||||
.map((room) => room.fullRoom),
|
||||
),
|
||||
),
|
||||
),
|
||||
)),
|
||||
];
|
||||
}
|
||||
|
||||
static final provider = AsyncNotifierProvider<SpacesController, List<Space>>(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue