Skip to content

Commit

Permalink
Brush off a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
nielsenko committed Feb 24, 2024
1 parent 1ad04aa commit a7ccefa
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 47 deletions.
4 changes: 2 additions & 2 deletions kilochat/lib/chat_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class ChatScreen extends ConsumerWidget {
],
),
body: DisplayToast(
stream: repository.x,
stream: repository.notifications,
builder: (message, animation) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
Expand All @@ -73,7 +73,7 @@ class ChatScreen extends ConsumerWidget {
color: Colors.yellow,
padding: const EdgeInsets.all(8),
width: double.infinity,
child: Text('in channel "${message.channel!.name}"'),
child: Text('in channel "${message.channel?.name ?? 'unknown'}"'),
),
MessageTile(message: message, animation: animation),
],
Expand Down
6 changes: 3 additions & 3 deletions kilochat/lib/display_toast.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import 'package:flutter/material.dart';

class DisplayToast<T> extends StatefulWidget {
const DisplayToast({
Key? key,
super.key,
required this.child,
required this.stream,
required this.builder,
}) : super(key: key);
});

final Widget child;
final Stream<T> stream;
Expand Down Expand Up @@ -59,7 +59,7 @@ class _DisplayToastState<T> extends State<DisplayToast<T>>
borderRadius: BorderRadius.circular(10),
border: Border.all(color: Colors.black),
boxShadow: kElevationToShadow[4],
color: Colors.white,
color: Colors.grey.withAlpha(100),
),
child: widget.builder(event, _controller),
),
Expand Down
7 changes: 6 additions & 1 deletion kilochat/lib/providers.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:async';

import 'package:corbado_auth/corbado_auth.dart';
import 'package:realm/realm.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';

import 'model.dart';
Expand Down Expand Up @@ -35,6 +36,10 @@ Stream<Repository> repository(RepositoryRef ref) async* {
Stream<Channel?> focusedChannel(FocusedChannelRef ref) async* {
final repository = await ref.watch(repositoryProvider.future);
await for (final channel in repository.focusedChannelChanges) {
yield channel;
yield channel?.nullIfInvalid;
}
}

extension<T extends RealmObject> on T {
T? get nullIfInvalid => isValid ? this : null;
}
1 change: 1 addition & 0 deletions kilochat/lib/realm_ui/realm_animated_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class _RealmAnimatedListState<E> extends State<RealmAnimatedList<E>> {
@override
void dispose() {
_subscription?.cancel();
_subscription = null;
super.dispose();
}

Expand Down
13 changes: 8 additions & 5 deletions kilochat/lib/repository.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'dart:async';
import 'dart:io';

import 'package:cancellation_token/cancellation_token.dart';
import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:kilochat/settings.dart';
import 'package:realm/realm.dart';
Expand Down Expand Up @@ -141,10 +140,14 @@ class Repository extends Disposable {
);
}

late Stream<Message> x =
allMessages.changes.where((c) => c.inserted.isNotEmpty).map((c) {
return c.results[c.inserted.last];
});
late Stream<Message> notifications = allMessages.changes.asyncExpand((c) async* {
final idx = c.inserted.lastOrNull ?? c.modified.lastOrNull ?? -1;
if (idx >= 0) { // not a delete
final message = c.results[idx];
if (message.owner != userProfile && message.channel != focusedChannel) {
yield message;
}
}});

void postNewMessage(Channel channel, String text) {
// messages are sorted latest first
Expand Down
11 changes: 5 additions & 6 deletions kilochat/lib/tiles.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class MessageTile extends ConsumerWidget {
),
const SizedBox(height: 8),
SizedBox(
height: 30,
height: 32,
child: RealmAnimatedList(
results: message.reactions,
scrollDirection: Axis.horizontal,
Expand All @@ -92,12 +92,11 @@ class MessageTile extends ConsumerWidget {
visualDensity: VisualDensity.compact,
avatar: MyAvatar(user: reaction.owner),
label: AnimatedEmoji(
AnimatedEmojiData(
'u${reaction.emojiUnicode.toRadixString(16)}',
name: 'n/a',
AnimatedEmojis.fromId(
reaction.emojiUnicode.toRadixString(16),
),
repeat: false,
size: 20,
size: 16,
errorWidget: Text(reaction.emoji),
),
onDeleted:
Expand All @@ -113,7 +112,7 @@ class MessageTile extends ConsumerWidget {
icon: const Icon(Icons.add),
onPressed: () {
(ref.read(repositoryProvider.future)).then((repository) {
repository.addReaction(message, '\u{1f605}'); //'👍');
repository.addReaction(message, '👍');
});
},
),
Expand Down
4 changes: 2 additions & 2 deletions kilochat/lib/workspace_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class WorkspaceView extends ConsumerWidget {
}

class WorkspaceScreen extends StatelessWidget {
const WorkspaceScreen({Key? key}) : super(key: key);
const WorkspaceScreen({super.key});

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -79,11 +79,11 @@ class _WorkspaceFormState extends State<WorkspaceForm> {

@override
void initState() {
super.initState();
workspace = Workspace(
widget.initialWorkspace?.appId ?? '',
widget.initialWorkspace?.name ?? '',
);
super.initState();
}

@override
Expand Down
14 changes: 0 additions & 14 deletions kilochat/macos/Runner/DebugProfile.entitlements

This file was deleted.

10 changes: 0 additions & 10 deletions kilochat/macos/Runner/Release.entitlements

This file was deleted.

6 changes: 3 additions & 3 deletions kilochat/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -370,10 +370,10 @@ packages:
dependency: "direct main"
description:
name: flutter_markdown
sha256: "5b24061317f850af858ef7151dadbb6eb77c1c449c954c7bb064e8a5e0e7d81f"
sha256: a64c5323ac83ed2b7940d2b6288d160aa1753ff271ba9d9b2a86770414aa3eab
url: "https://pub.dev"
source: hosted
version: "0.6.20"
version: "0.6.20+1"
flutter_riverpod:
dependency: "direct main"
description:
Expand Down Expand Up @@ -1087,4 +1087,4 @@ packages:
version: "3.1.2"
sdks:
dart: ">=3.3.0 <4.0.0"
flutter: ">=3.16.0"
flutter: ">=3.19.0"
2 changes: 1 addition & 1 deletion kilochat/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
version: 0.1.0

environment:
sdk: ^3.0.0
sdk: ^3.3.0

dependencies:
flutter:
Expand Down

0 comments on commit a7ccefa

Please sign in to comment.