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 23, 2024
1 parent 1ad04aa commit 577462b
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 39 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;
}
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
2 changes: 1 addition & 1 deletion 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
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"

0 comments on commit 577462b

Please sign in to comment.