forked from Henry-Hiles/nexus
fix some stuff (maybe?)
This commit is contained in:
parent
a4d60e6c83
commit
3e82faeb86
10 changed files with 58 additions and 36 deletions
|
|
@ -9,7 +9,9 @@ class MessageController extends AsyncNotifier<TextMessage?> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<TextMessage?> build() async {
|
Future<TextMessage?> build() async {
|
||||||
final room = await ref.watch(SelectedRoomController.provider.future);
|
final room = await ref.watch(
|
||||||
|
SelectedRoomController.provider.selectAsync((a) => a),
|
||||||
|
);
|
||||||
if (room == null) return null;
|
if (room == null) return null;
|
||||||
|
|
||||||
final event = await room.roomData.getEventById(id);
|
final event = await room.roomData.getEventById(id);
|
||||||
|
|
|
||||||
|
|
@ -82,8 +82,10 @@ class RoomChatController extends AsyncNotifier<ChatController> {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> markRead() async {
|
Future<void> markRead() async {
|
||||||
|
if (!room.hasNewMessages) return;
|
||||||
final controller = await future;
|
final controller = await future;
|
||||||
final id = controller.messages.last.id;
|
final id = controller.messages.last.id;
|
||||||
|
|
||||||
await room.setReadMarker(id, mRead: id);
|
await room.setReadMarker(id, mRead: id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,14 +5,6 @@ import "package:nexus/controllers/selected_space_controller.dart";
|
||||||
import "package:nexus/models/full_room.dart";
|
import "package:nexus/models/full_room.dart";
|
||||||
|
|
||||||
class SelectedRoomController extends AsyncNotifier<FullRoom?> {
|
class SelectedRoomController extends AsyncNotifier<FullRoom?> {
|
||||||
@override
|
|
||||||
bool updateShouldNotify(
|
|
||||||
AsyncValue<FullRoom?> previous,
|
|
||||||
AsyncValue<FullRoom?> next,
|
|
||||||
) =>
|
|
||||||
previous.value?.avatar != next.value?.avatar ||
|
|
||||||
previous.value?.title != next.value?.title;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<FullRoom?> build() async {
|
Future<FullRoom?> build() async {
|
||||||
final space = await ref.watch(SelectedSpaceController.provider.future);
|
final space = await ref.watch(SelectedSpaceController.provider.future);
|
||||||
|
|
|
||||||
|
|
@ -15,23 +15,25 @@ class SpacesController extends AsyncNotifier<IList<Space>> {
|
||||||
client.onSync.stream.listen((_) => ref.invalidateSelf()).cancel,
|
client.onSync.stream.listen((_) => ref.invalidateSelf()).cancel,
|
||||||
);
|
);
|
||||||
|
|
||||||
final topLevel = await Future.wait(
|
final topLevel = IList(
|
||||||
client.rooms
|
await Future.wait(
|
||||||
.where((room) => !room.isDirectChat)
|
client.rooms
|
||||||
.where(
|
.where((room) => !room.isDirectChat)
|
||||||
(room) => client.rooms
|
.where(
|
||||||
.where((room) => room.isSpace)
|
(room) => client.rooms
|
||||||
.every(
|
.where((room) => room.isSpace)
|
||||||
(match) => match.spaceChildren.every(
|
.every(
|
||||||
(child) => child.roomId != room.id,
|
(match) => match.spaceChildren.every(
|
||||||
|
(child) => child.roomId != room.id,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
)
|
||||||
)
|
.map((room) => room.fullRoom),
|
||||||
.map((room) => room.fullRoom),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
final topLevelSpaces = topLevel.where((r) => r.roomData.isSpace).toList();
|
final topLevelSpaces = topLevel.where((r) => r.roomData.isSpace).toIList();
|
||||||
final topLevelRooms = topLevel.where((r) => !r.roomData.isSpace).toList();
|
final topLevelRooms = topLevel.where((r) => !r.roomData.isSpace).toIList();
|
||||||
|
|
||||||
return IList([
|
return IList([
|
||||||
Space(
|
Space(
|
||||||
|
|
@ -45,10 +47,12 @@ class SpacesController extends AsyncNotifier<IList<Space>> {
|
||||||
client: client,
|
client: client,
|
||||||
title: "Direct Messages",
|
title: "Direct Messages",
|
||||||
id: "dms",
|
id: "dms",
|
||||||
children: await Future.wait(
|
children: IList(
|
||||||
client.rooms
|
await Future.wait(
|
||||||
.where((room) => room.isDirectChat)
|
client.rooms
|
||||||
.map((room) => room.fullRoom),
|
.where((room) => room.isDirectChat)
|
||||||
|
.map((room) => room.fullRoom),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
icon: Icon(Icons.person),
|
icon: Icon(Icons.person),
|
||||||
),
|
),
|
||||||
|
|
@ -60,7 +64,7 @@ class SpacesController extends AsyncNotifier<IList<Space>> {
|
||||||
avatar: space.avatar,
|
avatar: space.avatar,
|
||||||
id: space.roomData.id,
|
id: space.roomData.id,
|
||||||
roomData: space.roomData,
|
roomData: space.roomData,
|
||||||
children: await space.roomData.getAllChildren(client),
|
children: IList(await space.roomData.getAllChildren(client)),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
)),
|
)),
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,20 @@ part "full_room.freezed.dart";
|
||||||
|
|
||||||
@freezed
|
@freezed
|
||||||
abstract class FullRoom with _$FullRoom {
|
abstract class FullRoom with _$FullRoom {
|
||||||
|
const FullRoom._();
|
||||||
const factory FullRoom({
|
const factory FullRoom({
|
||||||
required Room roomData,
|
required Room roomData,
|
||||||
required String title,
|
required String title,
|
||||||
required Uri? avatar,
|
required Uri? avatar,
|
||||||
}) = _FullRoom;
|
}) = _FullRoom;
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool operator ==(Object other) =>
|
||||||
|
other.runtimeType == runtimeType &&
|
||||||
|
other is FullRoom &&
|
||||||
|
other.avatar == avatar &&
|
||||||
|
other.title == title;
|
||||||
|
|
||||||
|
@override
|
||||||
|
int get hashCode => Object.hash(runtimeType, title, avatar);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import "package:fast_immutable_collections/fast_immutable_collections.dart";
|
||||||
import "package:flutter/widgets.dart";
|
import "package:flutter/widgets.dart";
|
||||||
import "package:freezed_annotation/freezed_annotation.dart";
|
import "package:freezed_annotation/freezed_annotation.dart";
|
||||||
import "package:matrix/matrix.dart";
|
import "package:matrix/matrix.dart";
|
||||||
|
|
@ -6,13 +7,26 @@ part "space.freezed.dart";
|
||||||
|
|
||||||
@freezed
|
@freezed
|
||||||
abstract class Space with _$Space {
|
abstract class Space with _$Space {
|
||||||
|
const Space._();
|
||||||
const factory Space({
|
const factory Space({
|
||||||
required String title,
|
required String title,
|
||||||
required String id,
|
required String id,
|
||||||
required List<FullRoom> children,
|
required IList<FullRoom> children,
|
||||||
required Client client,
|
required Client client,
|
||||||
Room? roomData,
|
Room? roomData,
|
||||||
Uri? avatar,
|
Uri? avatar,
|
||||||
Icon? icon,
|
Icon? icon,
|
||||||
}) = _Space;
|
}) = _Space;
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool operator ==(Object other) =>
|
||||||
|
other.runtimeType == runtimeType &&
|
||||||
|
other is Space &&
|
||||||
|
other.title == title &&
|
||||||
|
other.id == id &&
|
||||||
|
other.icon == icon &&
|
||||||
|
other.avatar == avatar;
|
||||||
|
|
||||||
|
@override
|
||||||
|
int get hashCode => Object.hash(runtimeType, title, id, icon, avatar);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,6 @@ class Html extends ConsumerWidget {
|
||||||
return SpoilerText(text: element.text);
|
return SpoilerText(text: element.text);
|
||||||
}
|
}
|
||||||
return switch (element.localName) {
|
return switch (element.localName) {
|
||||||
"mx-reply" => SizedBox.shrink(),
|
|
||||||
|
|
||||||
"code" => CodeBlock(
|
"code" => CodeBlock(
|
||||||
element.text,
|
element.text,
|
||||||
lang: element.className.replaceAll("language-", ""),
|
lang: element.className.replaceAll("language-", ""),
|
||||||
|
|
|
||||||
|
|
@ -172,9 +172,7 @@ class RoomChat extends HookConsumerWidget {
|
||||||
ChatAnimatedList(
|
ChatAnimatedList(
|
||||||
itemBuilder: itemBuilder,
|
itemBuilder: itemBuilder,
|
||||||
onEndReached: notifier.loadOlder,
|
onEndReached: notifier.loadOlder,
|
||||||
onStartReached: () async {
|
onStartReached: notifier.markRead,
|
||||||
notifier.markRead();
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
composerBuilder: (_) => ChatBox(
|
composerBuilder: (_) => ChatBox(
|
||||||
replyToMessage: replyToMessage.value,
|
replyToMessage: replyToMessage.value,
|
||||||
|
|
|
||||||
|
|
@ -97,7 +97,6 @@ class Sidebar extends HookConsumerWidget {
|
||||||
),
|
),
|
||||||
IconButton(
|
IconButton(
|
||||||
onPressed: () => Navigator.of(context).push(
|
onPressed: () => Navigator.of(context).push(
|
||||||
// TODO: explore public rooms/spaces
|
|
||||||
MaterialPageRoute(builder: (_) => SettingsPage()),
|
MaterialPageRoute(builder: (_) => SettingsPage()),
|
||||||
),
|
),
|
||||||
icon: Icon(Icons.settings),
|
icon: Icon(Icons.settings),
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,9 @@ class TopWidget extends ConsumerWidget {
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
: null;
|
: null;
|
||||||
final replyText = (smallerText == null)
|
final replyText =
|
||||||
|
(smallerText == null ||
|
||||||
|
smallerText.length == replyMessage.text.length)
|
||||||
? replyMessage.text
|
? replyMessage.text
|
||||||
: "$smallerText...";
|
: "$smallerText...";
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue