wip mentions
This commit is contained in:
parent
819512c737
commit
541933a939
11 changed files with 145 additions and 86 deletions
|
|
@ -10,6 +10,11 @@ import "package:nexus/controllers/secure_storage_controller.dart";
|
|||
import "package:nexus/models/session_backup.dart";
|
||||
|
||||
class ClientController extends AsyncNotifier<Client> {
|
||||
@override
|
||||
bool updateShouldNotify(
|
||||
AsyncValue<Client> previous,
|
||||
AsyncValue<Client> next,
|
||||
) => previous.hasValue != next.hasValue;
|
||||
static const sessionBackupKey = "sessionBackup";
|
||||
|
||||
@override
|
||||
|
|
@ -81,7 +86,7 @@ class ClientController extends AsyncNotifier<Client> {
|
|||
).toJson(),
|
||||
),
|
||||
);
|
||||
ref.invalidateSelf();
|
||||
ref.invalidateSelf(asReload: true);
|
||||
return true;
|
||||
} catch (_) {
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -92,11 +92,18 @@ class RoomChatController extends AsyncNotifier<ChatController> {
|
|||
Future<void> updateMessage(Message message, Message newMessage) async =>
|
||||
(await future).updateMessage(message, newMessage);
|
||||
|
||||
Future<void> send(String message, {Message? replyTo}) async =>
|
||||
Future<void> send(Message message, {Message? replyTo}) async {
|
||||
final controller = await future;
|
||||
controller.insertMessage(message);
|
||||
|
||||
if (message is TextMessage) {
|
||||
await room.sendTextEvent(
|
||||
message,
|
||||
message.text,
|
||||
inReplyTo: replyTo == null ? null : await room.getEventById(replyTo.id),
|
||||
);
|
||||
}
|
||||
// TODO: Handle other types of message
|
||||
}
|
||||
|
||||
Future<chat.User> resolveUser(String id) async {
|
||||
final user = await room.client.getUserProfile(id);
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ extension EventToMessage on Event {
|
|||
id: eventId,
|
||||
authorId: senderId,
|
||||
text:
|
||||
"${content["displayname"]} ${switch (Membership.values.firstWhereOrNull((membership) => membership.name == content["membership"])) {
|
||||
"${sender.displayName} ${switch (Membership.values.firstWhereOrNull((membership) => membership.name == content["membership"])) {
|
||||
Membership.invite => "was invited to",
|
||||
Membership.join => "joined",
|
||||
Membership.leave => "left",
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import "package:flutter/foundation.dart";
|
||||
import "package:flutter_riverpod/flutter_riverpod.dart";
|
||||
import "package:nexus/controllers/client_controller.dart";
|
||||
import "package:nexus/controllers/shared_prefs_controller.dart";
|
||||
|
|
@ -13,7 +14,23 @@ import "package:window_size/window_size.dart";
|
|||
|
||||
final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
|
||||
|
||||
final class Logger extends ProviderObserver {
|
||||
@override
|
||||
void didUpdateProvider(
|
||||
ProviderObserverContext context,
|
||||
Object? previousValue,
|
||||
Object? newValue,
|
||||
) {
|
||||
print('''{
|
||||
"provider": "${context.provider}",
|
||||
"changed": ${previousValue != newValue}
|
||||
"type": ${previousValue.runtimeType}
|
||||
}''');
|
||||
}
|
||||
}
|
||||
|
||||
void showError(Object error, [StackTrace? stackTrace]) {
|
||||
if (error.toString().contains("ParentDataWidget")) return;
|
||||
if (error.toString().contains("DioException")) return;
|
||||
if (error.toString().contains("UTF-16")) return;
|
||||
|
||||
|
|
@ -43,7 +60,9 @@ void main() async {
|
|||
|
||||
setWindowMinSize(const Size.square(500));
|
||||
|
||||
runApp(ProviderScope(child: const App()));
|
||||
runApp(
|
||||
ProviderScope(observers: [if (kDebugMode) Logger()], child: const App()),
|
||||
);
|
||||
}
|
||||
|
||||
class App extends ConsumerWidget {
|
||||
|
|
|
|||
|
|
@ -10,14 +10,4 @@ abstract class FullRoom with _$FullRoom {
|
|||
required String title,
|
||||
required Uri? avatar,
|
||||
}) = _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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,16 +17,4 @@ abstract class Space with _$Space {
|
|||
Uri? avatar,
|
||||
Icon? icon,
|
||||
}) = _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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,64 +1,101 @@
|
|||
import "package:flutter/material.dart";
|
||||
import "package:flutter_chat_core/flutter_chat_core.dart";
|
||||
import "package:flutter_chat_ui/flutter_chat_ui.dart";
|
||||
import "package:flutter_hooks/flutter_hooks.dart";
|
||||
import "package:fluttertagger/fluttertagger.dart";
|
||||
import "package:matrix/matrix.dart";
|
||||
import "package:nexus/helpers/extensions/get_headers.dart";
|
||||
import "package:nexus/widgets/form_text_input.dart";
|
||||
|
||||
class ChatBox extends StatelessWidget {
|
||||
class ChatBox extends HookWidget {
|
||||
final Message? replyToMessage;
|
||||
final VoidCallback onDismiss;
|
||||
final Map<String, String> headers;
|
||||
final Room room;
|
||||
const ChatBox({
|
||||
required this.replyToMessage,
|
||||
required this.onDismiss,
|
||||
required this.headers,
|
||||
required this.room,
|
||||
super.key,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => Composer(
|
||||
sigmaX: 0,
|
||||
sigmaY: 0,
|
||||
sendIconColor: Theme.of(context).colorScheme.primary,
|
||||
sendOnEnter: true,
|
||||
topWidget: replyToMessage == null
|
||||
? null
|
||||
: ColoredBox(
|
||||
color: Theme.of(context).colorScheme.surfaceContainer,
|
||||
child: Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16, vertical: 4),
|
||||
child: Row(
|
||||
spacing: 8,
|
||||
children: [
|
||||
Avatar(
|
||||
userId: replyToMessage!.authorId,
|
||||
headers: headers,
|
||||
size: 16,
|
||||
),
|
||||
Text(
|
||||
replyToMessage!.metadata?["displayName"] ??
|
||||
replyToMessage!.authorId,
|
||||
style: Theme.of(context).textTheme.labelMedium?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: (replyToMessage is TextMessage)
|
||||
? Text(
|
||||
(replyToMessage as TextMessage).text,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: Theme.of(context).textTheme.labelMedium,
|
||||
maxLines: 1,
|
||||
)
|
||||
: SizedBox(),
|
||||
),
|
||||
IconButton(
|
||||
onPressed: onDismiss,
|
||||
icon: Icon(Icons.close),
|
||||
iconSize: 20,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
autofocus: true,
|
||||
);
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final controller = useRef(FlutterTaggerController());
|
||||
final trigger = useState<String?>(null);
|
||||
final style = TextStyle(
|
||||
color: theme.colorScheme.primary,
|
||||
fontWeight: FontWeight.bold,
|
||||
);
|
||||
|
||||
return Column(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
FlutterTagger(
|
||||
overlay: SizedBox(),
|
||||
controller: controller.value,
|
||||
onSearch: (query, triggerCharacter) {
|
||||
triggerCharacter == "#";
|
||||
if (controller.value.tags.isEmpty)
|
||||
controller.value.addTag(id: "id", name: "name");
|
||||
},
|
||||
triggerCharacterAndStyles: {"@": style, "#": style},
|
||||
builder: (context, key) => TextFormField(controller: controller.value, key: key,autofocus: true,onFieldSubmitted: (_) {
|
||||
|
||||
},)
|
||||
// Composer(
|
||||
// textEditingController: controller.value,
|
||||
// key: key,
|
||||
// sigmaY: 0,
|
||||
// sendIconColor: theme.colorScheme.primary,
|
||||
// sendOnEnter: true,
|
||||
// topWidget: replyToMessage == null
|
||||
// ? null
|
||||
// : ColoredBox(
|
||||
// color: theme.colorScheme.surfaceContainer,
|
||||
// child: Padding(
|
||||
// padding: EdgeInsets.symmetric(
|
||||
// horizontal: 16,
|
||||
// vertical: 4,
|
||||
// ),
|
||||
// child: Row(
|
||||
// spacing: 8,
|
||||
// children: [
|
||||
// Avatar(
|
||||
// userId: replyToMessage!.authorId,
|
||||
// headers: room.client.headers,
|
||||
// size: 16,
|
||||
// ),
|
||||
// Text(
|
||||
// replyToMessage!.metadata?["displayName"] ??
|
||||
// replyToMessage!.authorId,
|
||||
// style: theme.textTheme.labelMedium?.copyWith(
|
||||
// fontWeight: FontWeight.bold,
|
||||
// ),
|
||||
// ),
|
||||
// Expanded(
|
||||
// child: (replyToMessage is TextMessage)
|
||||
// ? Text(
|
||||
// (replyToMessage as TextMessage).text,
|
||||
// overflow: TextOverflow.ellipsis,
|
||||
// style: theme.textTheme.labelMedium,
|
||||
// maxLines: 1,
|
||||
// )
|
||||
// : SizedBox(),
|
||||
// ),
|
||||
// IconButton(
|
||||
// onPressed: onDismiss,
|
||||
// icon: Icon(Icons.close),
|
||||
// iconSize: 20,
|
||||
// ),
|
||||
// ],
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// autofocus: true,
|
||||
// ),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -85,7 +85,9 @@ class Html extends ConsumerWidget {
|
|||
headers: client.headers,
|
||||
errorBuilder: (_, error, _) => Text(
|
||||
"Image Failed to Load",
|
||||
style: TextStyle(color: Colors.red),
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).colorScheme.error,
|
||||
),
|
||||
),
|
||||
height: height.toDouble(),
|
||||
width: width?.toDouble(),
|
||||
|
|
|
|||
|
|
@ -177,7 +177,7 @@ class RoomChat extends HookConsumerWidget {
|
|||
composerBuilder: (_) => ChatBox(
|
||||
replyToMessage: replyToMessage.value,
|
||||
onDismiss: () => replyToMessage.value = null,
|
||||
headers: room.roomData.client.headers,
|
||||
room: room.roomData,
|
||||
),
|
||||
textMessageBuilder:
|
||||
(
|
||||
|
|
@ -296,13 +296,6 @@ class RoomChat extends HookConsumerWidget {
|
|||
),
|
||||
),
|
||||
),
|
||||
onMessageSend: (message) {
|
||||
notifier.send(
|
||||
message,
|
||||
replyTo: replyToMessage.value,
|
||||
);
|
||||
replyToMessage.value = null;
|
||||
},
|
||||
resolveUser: notifier.resolveUser,
|
||||
chatController: controller,
|
||||
),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue