Chat listing

This commit is contained in:
LittleSheep 2024-11-16 21:15:55 +08:00
parent 835203706d
commit e9fbd0c65f
14 changed files with 385 additions and 147 deletions

View File

@ -47,6 +47,8 @@ PODS:
- Flutter - Flutter
- image_picker_ios (0.0.1): - image_picker_ios (0.0.1):
- Flutter - Flutter
- isar_flutter_libs (1.0.0):
- Flutter
- path_provider_foundation (0.0.1): - path_provider_foundation (0.0.1):
- Flutter - Flutter
- FlutterMacOS - FlutterMacOS
@ -72,6 +74,7 @@ DEPENDENCIES:
- flutter_native_splash (from `.symlinks/plugins/flutter_native_splash/ios`) - flutter_native_splash (from `.symlinks/plugins/flutter_native_splash/ios`)
- flutter_secure_storage (from `.symlinks/plugins/flutter_secure_storage/ios`) - flutter_secure_storage (from `.symlinks/plugins/flutter_secure_storage/ios`)
- image_picker_ios (from `.symlinks/plugins/image_picker_ios/ios`) - image_picker_ios (from `.symlinks/plugins/image_picker_ios/ios`)
- isar_flutter_libs (from `.symlinks/plugins/isar_flutter_libs/ios`)
- path_provider_foundation (from `.symlinks/plugins/path_provider_foundation/darwin`) - path_provider_foundation (from `.symlinks/plugins/path_provider_foundation/darwin`)
- shared_preferences_foundation (from `.symlinks/plugins/shared_preferences_foundation/darwin`) - shared_preferences_foundation (from `.symlinks/plugins/shared_preferences_foundation/darwin`)
- sqflite_darwin (from `.symlinks/plugins/sqflite_darwin/darwin`) - sqflite_darwin (from `.symlinks/plugins/sqflite_darwin/darwin`)
@ -101,6 +104,8 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/flutter_secure_storage/ios" :path: ".symlinks/plugins/flutter_secure_storage/ios"
image_picker_ios: image_picker_ios:
:path: ".symlinks/plugins/image_picker_ios/ios" :path: ".symlinks/plugins/image_picker_ios/ios"
isar_flutter_libs:
:path: ".symlinks/plugins/isar_flutter_libs/ios"
path_provider_foundation: path_provider_foundation:
:path: ".symlinks/plugins/path_provider_foundation/darwin" :path: ".symlinks/plugins/path_provider_foundation/darwin"
shared_preferences_foundation: shared_preferences_foundation:
@ -121,6 +126,7 @@ SPEC CHECKSUMS:
flutter_native_splash: edf599c81f74d093a4daf8e17bd7a018854bc778 flutter_native_splash: edf599c81f74d093a4daf8e17bd7a018854bc778
flutter_secure_storage: d33dac7ae2ea08509be337e775f6b59f1ff45f12 flutter_secure_storage: d33dac7ae2ea08509be337e775f6b59f1ff45f12
image_picker_ios: c560581cceedb403a6ff17f2f816d7fea1421fc1 image_picker_ios: c560581cceedb403a6ff17f2f816d7fea1421fc1
isar_flutter_libs: b69f437aeab9c521821c3f376198c4371fa21073
path_provider_foundation: 2b6b4c569c0fb62ec74538f866245ac84301af46 path_provider_foundation: 2b6b4c569c0fb62ec74538f866245ac84301af46
SDWebImage: 8a6b7b160b4d710e2a22b6900e25301075c34cb3 SDWebImage: 8a6b7b160b4d710e2a22b6900e25301075c34cb3
shared_preferences_foundation: fcdcbc04712aee1108ac7fda236f363274528f78 shared_preferences_foundation: fcdcbc04712aee1108ac7fda236f363274528f78

View File

@ -7,6 +7,7 @@ import 'package:hive_flutter/hive_flutter.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:relative_time/relative_time.dart'; import 'package:relative_time/relative_time.dart';
import 'package:responsive_framework/responsive_framework.dart'; import 'package:responsive_framework/responsive_framework.dart';
import 'package:surface/providers/channel.dart';
import 'package:surface/providers/navigation.dart'; import 'package:surface/providers/navigation.dart';
import 'package:surface/providers/sn_attachment.dart'; import 'package:surface/providers/sn_attachment.dart';
import 'package:surface/providers/sn_network.dart'; import 'package:surface/providers/sn_network.dart';
@ -14,12 +15,14 @@ import 'package:surface/providers/theme.dart';
import 'package:surface/providers/userinfo.dart'; import 'package:surface/providers/userinfo.dart';
import 'package:surface/providers/websocket.dart'; import 'package:surface/providers/websocket.dart';
import 'package:surface/router.dart'; import 'package:surface/router.dart';
import 'package:surface/types/chat.dart';
void main() async { void main() async {
WidgetsFlutterBinding.ensureInitialized(); WidgetsFlutterBinding.ensureInitialized();
await EasyLocalization.ensureInitialized(); await EasyLocalization.ensureInitialized();
await Hive.initFlutter(); await Hive.initFlutter();
Hive.registerAdapter(SnChannelImplAdapter());
if (!kReleaseMode) { if (!kReleaseMode) {
debugInvertOversizedImages = true; debugInvertOversizedImages = true;
@ -52,6 +55,7 @@ class SolianApp extends StatelessWidget {
Provider(create: (ctx) => SnAttachmentProvider(ctx)), Provider(create: (ctx) => SnAttachmentProvider(ctx)),
ChangeNotifierProvider(create: (ctx) => UserProvider(ctx)), ChangeNotifierProvider(create: (ctx) => UserProvider(ctx)),
ChangeNotifierProvider(create: (ctx) => WebSocketProvider(ctx)), ChangeNotifierProvider(create: (ctx) => WebSocketProvider(ctx)),
ChangeNotifierProvider(create: (ctx) => ChatChannelProvider(ctx)),
], ],
child: AppMainContent(), child: AppMainContent(),
), ),
@ -72,6 +76,7 @@ class AppMainContent extends StatelessWidget {
Widget build(BuildContext context) { Widget build(BuildContext context) {
context.read<NavigationProvider>(); context.read<NavigationProvider>();
context.read<WebSocketProvider>(); context.read<WebSocketProvider>();
context.read<ChatChannelProvider>();
final th = context.watch<ThemeProvider>(); final th = context.watch<ThemeProvider>();

View File

@ -0,0 +1,80 @@
import 'package:flutter/material.dart';
import 'package:hive_flutter/hive_flutter.dart';
import 'package:provider/provider.dart';
import 'package:surface/providers/sn_network.dart';
import 'package:surface/types/chat.dart';
import 'package:surface/types/realm.dart';
class ChatChannelProvider extends ChangeNotifier {
static const kChatChannelBoxName = 'nex_chat_channels';
late final SnNetworkProvider _sn;
Box<SnChannel>? get _channelBox => Hive.box<SnChannel>(kChatChannelBoxName);
ChatChannelProvider(BuildContext context) {
_sn = context.read<SnNetworkProvider>();
_initializeLocalData();
}
Future<void> _initializeLocalData() async {
await Hive.openBox<SnChannel>(kChatChannelBoxName);
}
Future<void> _saveChannelToLocal(Iterable<SnChannel> channels) async {
if (_channelBox == null) return;
await _channelBox!.putAll({
for (final channel in channels) channel.key: channel,
});
}
Future<List<SnChannel>> _fetchChannelsFromServer(
{scope = 'global', direct = false}) async {
final resp = await _sn.client.get(
'/cgi/im/channels/$scope/me/available',
queryParameters: {
'direct': direct,
},
);
final out = List<SnChannel>.from(
resp.data?.map((e) => SnChannel.fromJson(e)) ?? [],
);
_saveChannelToLocal(out);
return out;
}
// The fetch channel method return a stream, which will emit twice.
// The first time is when the data was fetched from the local storage.
// And the second time is when the data was fetched from the server.
// But there is some exception that will only cause one of them to be emitted.
// Like the local storage is broken or the server is down.
Stream<List<SnChannel>> fetchChannels() async* {
if (_channelBox != null) yield _channelBox!.values.toList();
var resp = await _sn.client.get('/cgi/id/realms/me/available');
final realms = List<SnRealm>.from(
resp.data?.map((e) => SnRealm.fromJson(e)) ?? [],
);
final scopeToFetch = {'global', ...realms.map((e) => e.alias)};
final List<SnChannel> result = List.empty(growable: true);
final dm =
await _fetchChannelsFromServer(scope: scopeToFetch.first, direct: true);
result.addAll(dm);
for (final scope in scopeToFetch) {
final channel =
await _fetchChannelsFromServer(scope: scope, direct: false);
result.addAll(channel);
}
yield result;
}
@override
void dispose() {
_channelBox?.close();
super.dispose();
}
}

View File

@ -3,10 +3,9 @@ import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart'; import 'package:go_router/go_router.dart';
import 'package:material_symbols_icons/symbols.dart'; import 'package:material_symbols_icons/symbols.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:surface/providers/sn_network.dart'; import 'package:surface/providers/channel.dart';
import 'package:surface/types/chat.dart'; import 'package:surface/types/chat.dart';
import 'package:surface/widgets/account/account_image.dart'; import 'package:surface/widgets/account/account_image.dart';
import 'package:surface/widgets/dialog.dart';
import 'package:surface/widgets/loading_indicator.dart'; import 'package:surface/widgets/loading_indicator.dart';
class ChatScreen extends StatefulWidget { class ChatScreen extends StatefulWidget {
@ -17,36 +16,23 @@ class ChatScreen extends StatefulWidget {
} }
class _ChatScreenState extends State<ChatScreen> { class _ChatScreenState extends State<ChatScreen> {
bool _isBusy = false; bool _isBusy = true;
List<SnChannel>? _channels; List<SnChannel>? _channels;
Future<void> _fetchChannels({scope = 'global', direct = false}) async {
setState(() => _isBusy = true);
try {
final sn = context.read<SnNetworkProvider>();
final resp = await sn.client.get(
'/cgi/im/channels/$scope/me/available',
queryParameters: {
'direct': direct,
},
);
_channels = List<SnChannel>.from(
resp.data?.map((e) => SnChannel.fromJson(e)) ?? [],
);
} catch (err) {
if (!mounted) return;
context.showErrorDialog(err);
} finally {
setState(() => _isBusy = false);
}
}
@override @override
void initState() { void initState() {
super.initState(); super.initState();
_fetchChannels(); final chan = context.read<ChatChannelProvider>();
chan.fetchChannels().listen((channels) {
if (mounted) setState(() => _channels = channels);
})
..onError((_) {
setState(() => _isBusy = false);
})
..onDone(() {
setState(() => _isBusy = false);
});
} }
@override @override
@ -71,7 +57,11 @@ class _ChatScreenState extends State<ChatScreen> {
final channel = _channels![idx]; final channel = _channels![idx];
return ListTile( return ListTile(
title: Text(channel.name), title: Text(channel.name),
subtitle: Text(channel.description), subtitle: Text(
channel.description,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
contentPadding: const EdgeInsets.symmetric(horizontal: 16), contentPadding: const EdgeInsets.symmetric(horizontal: 16),
leading: AccountImage( leading: AccountImage(
content: null, content: null,

View File

@ -1,4 +1,5 @@
import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:hive_flutter/hive_flutter.dart';
import 'package:surface/types/realm.dart'; import 'package:surface/types/realm.dart';
part 'chat.freezed.dart'; part 'chat.freezed.dart';
@ -6,25 +7,30 @@ part 'chat.g.dart';
@freezed @freezed
class SnChannel with _$SnChannel { class SnChannel with _$SnChannel {
const SnChannel._();
@HiveType(typeId: 2)
const factory SnChannel({ const factory SnChannel({
required int id, @HiveField(0) required int id,
required DateTime createdAt, @HiveField(1) required DateTime createdAt,
required DateTime updatedAt, @HiveField(2) required DateTime updatedAt,
required dynamic deletedAt, @HiveField(3) required dynamic deletedAt,
required String alias, @HiveField(4) required String alias,
required String name, @HiveField(5) required String name,
required String description, @HiveField(6) required String description,
required List<dynamic> members, @HiveField(7) required List<dynamic> members,
required dynamic messages, dynamic messages,
required dynamic calls, dynamic calls,
required int type, @HiveField(8) required int type,
required int accountId, @HiveField(9) required int accountId,
required bool isPublic, @HiveField(10) required SnRealm? realm,
required bool isCommunity, @HiveField(11) required int? realmId,
required SnRealm? realm, @HiveField(12) required bool isPublic,
required int? realmId, @HiveField(13) required bool isCommunity,
}) = _SnChannel; }) = _SnChannel;
factory SnChannel.fromJson(Map<String, dynamic> json) => factory SnChannel.fromJson(Map<String, dynamic> json) =>
_$SnChannelFromJson(json); _$SnChannelFromJson(json);
String get key => '${realm?.alias ?? 'global'}:$alias';
} }

View File

@ -20,22 +20,36 @@ SnChannel _$SnChannelFromJson(Map<String, dynamic> json) {
/// @nodoc /// @nodoc
mixin _$SnChannel { mixin _$SnChannel {
@HiveField(0)
int get id => throw _privateConstructorUsedError; int get id => throw _privateConstructorUsedError;
@HiveField(1)
DateTime get createdAt => throw _privateConstructorUsedError; DateTime get createdAt => throw _privateConstructorUsedError;
@HiveField(2)
DateTime get updatedAt => throw _privateConstructorUsedError; DateTime get updatedAt => throw _privateConstructorUsedError;
@HiveField(3)
dynamic get deletedAt => throw _privateConstructorUsedError; dynamic get deletedAt => throw _privateConstructorUsedError;
@HiveField(4)
String get alias => throw _privateConstructorUsedError; String get alias => throw _privateConstructorUsedError;
@HiveField(5)
String get name => throw _privateConstructorUsedError; String get name => throw _privateConstructorUsedError;
@HiveField(6)
String get description => throw _privateConstructorUsedError; String get description => throw _privateConstructorUsedError;
@HiveField(7)
List<dynamic> get members => throw _privateConstructorUsedError; List<dynamic> get members => throw _privateConstructorUsedError;
dynamic get messages => throw _privateConstructorUsedError; dynamic get messages => throw _privateConstructorUsedError;
dynamic get calls => throw _privateConstructorUsedError; dynamic get calls => throw _privateConstructorUsedError;
@HiveField(8)
int get type => throw _privateConstructorUsedError; int get type => throw _privateConstructorUsedError;
@HiveField(9)
int get accountId => throw _privateConstructorUsedError; int get accountId => throw _privateConstructorUsedError;
bool get isPublic => throw _privateConstructorUsedError; @HiveField(10)
bool get isCommunity => throw _privateConstructorUsedError;
SnRealm? get realm => throw _privateConstructorUsedError; SnRealm? get realm => throw _privateConstructorUsedError;
@HiveField(11)
int? get realmId => throw _privateConstructorUsedError; int? get realmId => throw _privateConstructorUsedError;
@HiveField(12)
bool get isPublic => throw _privateConstructorUsedError;
@HiveField(13)
bool get isCommunity => throw _privateConstructorUsedError;
/// Serializes this SnChannel to a JSON map. /// Serializes this SnChannel to a JSON map.
Map<String, dynamic> toJson() => throw _privateConstructorUsedError; Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
@ -53,22 +67,22 @@ abstract class $SnChannelCopyWith<$Res> {
_$SnChannelCopyWithImpl<$Res, SnChannel>; _$SnChannelCopyWithImpl<$Res, SnChannel>;
@useResult @useResult
$Res call( $Res call(
{int id, {@HiveField(0) int id,
DateTime createdAt, @HiveField(1) DateTime createdAt,
DateTime updatedAt, @HiveField(2) DateTime updatedAt,
dynamic deletedAt, @HiveField(3) dynamic deletedAt,
String alias, @HiveField(4) String alias,
String name, @HiveField(5) String name,
String description, @HiveField(6) String description,
List<dynamic> members, @HiveField(7) List<dynamic> members,
dynamic messages, dynamic messages,
dynamic calls, dynamic calls,
int type, @HiveField(8) int type,
int accountId, @HiveField(9) int accountId,
bool isPublic, @HiveField(10) SnRealm? realm,
bool isCommunity, @HiveField(11) int? realmId,
SnRealm? realm, @HiveField(12) bool isPublic,
int? realmId}); @HiveField(13) bool isCommunity});
$SnRealmCopyWith<$Res>? get realm; $SnRealmCopyWith<$Res>? get realm;
} }
@ -100,10 +114,10 @@ class _$SnChannelCopyWithImpl<$Res, $Val extends SnChannel>
Object? calls = freezed, Object? calls = freezed,
Object? type = null, Object? type = null,
Object? accountId = null, Object? accountId = null,
Object? isPublic = null,
Object? isCommunity = null,
Object? realm = freezed, Object? realm = freezed,
Object? realmId = freezed, Object? realmId = freezed,
Object? isPublic = null,
Object? isCommunity = null,
}) { }) {
return _then(_value.copyWith( return _then(_value.copyWith(
id: null == id id: null == id
@ -154,14 +168,6 @@ class _$SnChannelCopyWithImpl<$Res, $Val extends SnChannel>
? _value.accountId ? _value.accountId
: accountId // ignore: cast_nullable_to_non_nullable : accountId // ignore: cast_nullable_to_non_nullable
as int, as int,
isPublic: null == isPublic
? _value.isPublic
: isPublic // ignore: cast_nullable_to_non_nullable
as bool,
isCommunity: null == isCommunity
? _value.isCommunity
: isCommunity // ignore: cast_nullable_to_non_nullable
as bool,
realm: freezed == realm realm: freezed == realm
? _value.realm ? _value.realm
: realm // ignore: cast_nullable_to_non_nullable : realm // ignore: cast_nullable_to_non_nullable
@ -170,6 +176,14 @@ class _$SnChannelCopyWithImpl<$Res, $Val extends SnChannel>
? _value.realmId ? _value.realmId
: realmId // ignore: cast_nullable_to_non_nullable : realmId // ignore: cast_nullable_to_non_nullable
as int?, as int?,
isPublic: null == isPublic
? _value.isPublic
: isPublic // ignore: cast_nullable_to_non_nullable
as bool,
isCommunity: null == isCommunity
? _value.isCommunity
: isCommunity // ignore: cast_nullable_to_non_nullable
as bool,
) as $Val); ) as $Val);
} }
@ -197,22 +211,22 @@ abstract class _$$SnChannelImplCopyWith<$Res>
@override @override
@useResult @useResult
$Res call( $Res call(
{int id, {@HiveField(0) int id,
DateTime createdAt, @HiveField(1) DateTime createdAt,
DateTime updatedAt, @HiveField(2) DateTime updatedAt,
dynamic deletedAt, @HiveField(3) dynamic deletedAt,
String alias, @HiveField(4) String alias,
String name, @HiveField(5) String name,
String description, @HiveField(6) String description,
List<dynamic> members, @HiveField(7) List<dynamic> members,
dynamic messages, dynamic messages,
dynamic calls, dynamic calls,
int type, @HiveField(8) int type,
int accountId, @HiveField(9) int accountId,
bool isPublic, @HiveField(10) SnRealm? realm,
bool isCommunity, @HiveField(11) int? realmId,
SnRealm? realm, @HiveField(12) bool isPublic,
int? realmId}); @HiveField(13) bool isCommunity});
@override @override
$SnRealmCopyWith<$Res>? get realm; $SnRealmCopyWith<$Res>? get realm;
@ -243,10 +257,10 @@ class __$$SnChannelImplCopyWithImpl<$Res>
Object? calls = freezed, Object? calls = freezed,
Object? type = null, Object? type = null,
Object? accountId = null, Object? accountId = null,
Object? isPublic = null,
Object? isCommunity = null,
Object? realm = freezed, Object? realm = freezed,
Object? realmId = freezed, Object? realmId = freezed,
Object? isPublic = null,
Object? isCommunity = null,
}) { }) {
return _then(_$SnChannelImpl( return _then(_$SnChannelImpl(
id: null == id id: null == id
@ -297,14 +311,6 @@ class __$$SnChannelImplCopyWithImpl<$Res>
? _value.accountId ? _value.accountId
: accountId // ignore: cast_nullable_to_non_nullable : accountId // ignore: cast_nullable_to_non_nullable
as int, as int,
isPublic: null == isPublic
? _value.isPublic
: isPublic // ignore: cast_nullable_to_non_nullable
as bool,
isCommunity: null == isCommunity
? _value.isCommunity
: isCommunity // ignore: cast_nullable_to_non_nullable
as bool,
realm: freezed == realm realm: freezed == realm
? _value.realm ? _value.realm
: realm // ignore: cast_nullable_to_non_nullable : realm // ignore: cast_nullable_to_non_nullable
@ -313,51 +319,69 @@ class __$$SnChannelImplCopyWithImpl<$Res>
? _value.realmId ? _value.realmId
: realmId // ignore: cast_nullable_to_non_nullable : realmId // ignore: cast_nullable_to_non_nullable
as int?, as int?,
isPublic: null == isPublic
? _value.isPublic
: isPublic // ignore: cast_nullable_to_non_nullable
as bool,
isCommunity: null == isCommunity
? _value.isCommunity
: isCommunity // ignore: cast_nullable_to_non_nullable
as bool,
)); ));
} }
} }
/// @nodoc /// @nodoc
@JsonSerializable() @JsonSerializable()
class _$SnChannelImpl implements _SnChannel { @HiveType(typeId: 2)
class _$SnChannelImpl extends _SnChannel {
const _$SnChannelImpl( const _$SnChannelImpl(
{required this.id, {@HiveField(0) required this.id,
required this.createdAt, @HiveField(1) required this.createdAt,
required this.updatedAt, @HiveField(2) required this.updatedAt,
required this.deletedAt, @HiveField(3) required this.deletedAt,
required this.alias, @HiveField(4) required this.alias,
required this.name, @HiveField(5) required this.name,
required this.description, @HiveField(6) required this.description,
required final List<dynamic> members, @HiveField(7) required final List<dynamic> members,
required this.messages, this.messages,
required this.calls, this.calls,
required this.type, @HiveField(8) required this.type,
required this.accountId, @HiveField(9) required this.accountId,
required this.isPublic, @HiveField(10) required this.realm,
required this.isCommunity, @HiveField(11) required this.realmId,
required this.realm, @HiveField(12) required this.isPublic,
required this.realmId}) @HiveField(13) required this.isCommunity})
: _members = members; : _members = members,
super._();
factory _$SnChannelImpl.fromJson(Map<String, dynamic> json) => factory _$SnChannelImpl.fromJson(Map<String, dynamic> json) =>
_$$SnChannelImplFromJson(json); _$$SnChannelImplFromJson(json);
@override @override
@HiveField(0)
final int id; final int id;
@override @override
@HiveField(1)
final DateTime createdAt; final DateTime createdAt;
@override @override
@HiveField(2)
final DateTime updatedAt; final DateTime updatedAt;
@override @override
@HiveField(3)
final dynamic deletedAt; final dynamic deletedAt;
@override @override
@HiveField(4)
final String alias; final String alias;
@override @override
@HiveField(5)
final String name; final String name;
@override @override
@HiveField(6)
final String description; final String description;
final List<dynamic> _members; final List<dynamic> _members;
@override @override
@HiveField(7)
List<dynamic> get members { List<dynamic> get members {
if (_members is EqualUnmodifiableListView) return _members; if (_members is EqualUnmodifiableListView) return _members;
// ignore: implicit_dynamic_type // ignore: implicit_dynamic_type
@ -369,21 +393,27 @@ class _$SnChannelImpl implements _SnChannel {
@override @override
final dynamic calls; final dynamic calls;
@override @override
@HiveField(8)
final int type; final int type;
@override @override
@HiveField(9)
final int accountId; final int accountId;
@override @override
final bool isPublic; @HiveField(10)
@override
final bool isCommunity;
@override
final SnRealm? realm; final SnRealm? realm;
@override @override
@HiveField(11)
final int? realmId; final int? realmId;
@override
@HiveField(12)
final bool isPublic;
@override
@HiveField(13)
final bool isCommunity;
@override @override
String toString() { String toString() {
return 'SnChannel(id: $id, createdAt: $createdAt, updatedAt: $updatedAt, deletedAt: $deletedAt, alias: $alias, name: $name, description: $description, members: $members, messages: $messages, calls: $calls, type: $type, accountId: $accountId, isPublic: $isPublic, isCommunity: $isCommunity, realm: $realm, realmId: $realmId)'; return 'SnChannel(id: $id, createdAt: $createdAt, updatedAt: $updatedAt, deletedAt: $deletedAt, alias: $alias, name: $name, description: $description, members: $members, messages: $messages, calls: $calls, type: $type, accountId: $accountId, realm: $realm, realmId: $realmId, isPublic: $isPublic, isCommunity: $isCommunity)';
} }
@override @override
@ -407,12 +437,12 @@ class _$SnChannelImpl implements _SnChannel {
(identical(other.type, type) || other.type == type) && (identical(other.type, type) || other.type == type) &&
(identical(other.accountId, accountId) || (identical(other.accountId, accountId) ||
other.accountId == accountId) && other.accountId == accountId) &&
(identical(other.realm, realm) || other.realm == realm) &&
(identical(other.realmId, realmId) || other.realmId == realmId) &&
(identical(other.isPublic, isPublic) || (identical(other.isPublic, isPublic) ||
other.isPublic == isPublic) && other.isPublic == isPublic) &&
(identical(other.isCommunity, isCommunity) || (identical(other.isCommunity, isCommunity) ||
other.isCommunity == isCommunity) && other.isCommunity == isCommunity));
(identical(other.realm, realm) || other.realm == realm) &&
(identical(other.realmId, realmId) || other.realmId == realmId));
} }
@JsonKey(includeFromJson: false, includeToJson: false) @JsonKey(includeFromJson: false, includeToJson: false)
@ -431,10 +461,10 @@ class _$SnChannelImpl implements _SnChannel {
const DeepCollectionEquality().hash(calls), const DeepCollectionEquality().hash(calls),
type, type,
accountId, accountId,
isPublic,
isCommunity,
realm, realm,
realmId); realmId,
isPublic,
isCommunity);
/// Create a copy of SnChannel /// Create a copy of SnChannel
/// with the given fields replaced by the non-null parameter values. /// with the given fields replaced by the non-null parameter values.
@ -452,60 +482,75 @@ class _$SnChannelImpl implements _SnChannel {
} }
} }
abstract class _SnChannel implements SnChannel { abstract class _SnChannel extends SnChannel {
const factory _SnChannel( const factory _SnChannel(
{required final int id, {@HiveField(0) required final int id,
required final DateTime createdAt, @HiveField(1) required final DateTime createdAt,
required final DateTime updatedAt, @HiveField(2) required final DateTime updatedAt,
required final dynamic deletedAt, @HiveField(3) required final dynamic deletedAt,
required final String alias, @HiveField(4) required final String alias,
required final String name, @HiveField(5) required final String name,
required final String description, @HiveField(6) required final String description,
required final List<dynamic> members, @HiveField(7) required final List<dynamic> members,
required final dynamic messages, final dynamic messages,
required final dynamic calls, final dynamic calls,
required final int type, @HiveField(8) required final int type,
required final int accountId, @HiveField(9) required final int accountId,
required final bool isPublic, @HiveField(10) required final SnRealm? realm,
required final bool isCommunity, @HiveField(11) required final int? realmId,
required final SnRealm? realm, @HiveField(12) required final bool isPublic,
required final int? realmId}) = _$SnChannelImpl; @HiveField(13) required final bool isCommunity}) = _$SnChannelImpl;
const _SnChannel._() : super._();
factory _SnChannel.fromJson(Map<String, dynamic> json) = factory _SnChannel.fromJson(Map<String, dynamic> json) =
_$SnChannelImpl.fromJson; _$SnChannelImpl.fromJson;
@override @override
@HiveField(0)
int get id; int get id;
@override @override
@HiveField(1)
DateTime get createdAt; DateTime get createdAt;
@override @override
@HiveField(2)
DateTime get updatedAt; DateTime get updatedAt;
@override @override
@HiveField(3)
dynamic get deletedAt; dynamic get deletedAt;
@override @override
@HiveField(4)
String get alias; String get alias;
@override @override
@HiveField(5)
String get name; String get name;
@override @override
@HiveField(6)
String get description; String get description;
@override @override
@HiveField(7)
List<dynamic> get members; List<dynamic> get members;
@override @override
dynamic get messages; dynamic get messages;
@override @override
dynamic get calls; dynamic get calls;
@override @override
@HiveField(8)
int get type; int get type;
@override @override
@HiveField(9)
int get accountId; int get accountId;
@override @override
bool get isPublic; @HiveField(10)
@override
bool get isCommunity;
@override
SnRealm? get realm; SnRealm? get realm;
@override @override
@HiveField(11)
int? get realmId; int? get realmId;
@override
@HiveField(12)
bool get isPublic;
@override
@HiveField(13)
bool get isCommunity;
/// Create a copy of SnChannel /// Create a copy of SnChannel
/// with the given fields replaced by the non-null parameter values. /// with the given fields replaced by the non-null parameter values.

View File

@ -2,6 +2,83 @@
part of 'chat.dart'; part of 'chat.dart';
// **************************************************************************
// TypeAdapterGenerator
// **************************************************************************
class SnChannelImplAdapter extends TypeAdapter<_$SnChannelImpl> {
@override
final int typeId = 2;
@override
_$SnChannelImpl read(BinaryReader reader) {
final numOfFields = reader.readByte();
final fields = <int, dynamic>{
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
};
return _$SnChannelImpl(
id: fields[0] as int,
createdAt: fields[1] as DateTime,
updatedAt: fields[2] as DateTime,
deletedAt: fields[3] as dynamic,
alias: fields[4] as String,
name: fields[5] as String,
description: fields[6] as String,
members: (fields[7] as List).cast<dynamic>(),
type: fields[8] as int,
accountId: fields[9] as int,
realm: fields[10] as SnRealm?,
realmId: fields[11] as int?,
isPublic: fields[12] as bool,
isCommunity: fields[13] as bool,
);
}
@override
void write(BinaryWriter writer, _$SnChannelImpl obj) {
writer
..writeByte(14)
..writeByte(0)
..write(obj.id)
..writeByte(1)
..write(obj.createdAt)
..writeByte(2)
..write(obj.updatedAt)
..writeByte(3)
..write(obj.deletedAt)
..writeByte(4)
..write(obj.alias)
..writeByte(5)
..write(obj.name)
..writeByte(6)
..write(obj.description)
..writeByte(8)
..write(obj.type)
..writeByte(9)
..write(obj.accountId)
..writeByte(10)
..write(obj.realm)
..writeByte(11)
..write(obj.realmId)
..writeByte(12)
..write(obj.isPublic)
..writeByte(13)
..write(obj.isCommunity)
..writeByte(7)
..write(obj.members);
}
@override
int get hashCode => typeId.hashCode;
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is SnChannelImplAdapter &&
runtimeType == other.runtimeType &&
typeId == other.typeId;
}
// ************************************************************************** // **************************************************************************
// JsonSerializableGenerator // JsonSerializableGenerator
// ************************************************************************** // **************************************************************************
@ -20,12 +97,12 @@ _$SnChannelImpl _$$SnChannelImplFromJson(Map<String, dynamic> json) =>
calls: json['calls'], calls: json['calls'],
type: (json['type'] as num).toInt(), type: (json['type'] as num).toInt(),
accountId: (json['account_id'] as num).toInt(), accountId: (json['account_id'] as num).toInt(),
isPublic: json['is_public'] as bool,
isCommunity: json['is_community'] as bool,
realm: json['realm'] == null realm: json['realm'] == null
? null ? null
: SnRealm.fromJson(json['realm'] as Map<String, dynamic>), : SnRealm.fromJson(json['realm'] as Map<String, dynamic>),
realmId: (json['realm_id'] as num?)?.toInt(), realmId: (json['realm_id'] as num?)?.toInt(),
isPublic: json['is_public'] as bool,
isCommunity: json['is_community'] as bool,
); );
Map<String, dynamic> _$$SnChannelImplToJson(_$SnChannelImpl instance) => Map<String, dynamic> _$$SnChannelImplToJson(_$SnChannelImpl instance) =>
@ -42,8 +119,8 @@ Map<String, dynamic> _$$SnChannelImplToJson(_$SnChannelImpl instance) =>
'calls': instance.calls, 'calls': instance.calls,
'type': instance.type, 'type': instance.type,
'account_id': instance.accountId, 'account_id': instance.accountId,
'is_public': instance.isPublic,
'is_community': instance.isCommunity,
'realm': instance.realm?.toJson(), 'realm': instance.realm?.toJson(),
'realm_id': instance.realmId, 'realm_id': instance.realmId,
'is_public': instance.isPublic,
'is_community': instance.isCommunity,
}; };

View File

@ -8,6 +8,7 @@
#include <file_selector_linux/file_selector_plugin.h> #include <file_selector_linux/file_selector_plugin.h>
#include <flutter_secure_storage_linux/flutter_secure_storage_linux_plugin.h> #include <flutter_secure_storage_linux/flutter_secure_storage_linux_plugin.h>
#include <isar_flutter_libs/isar_flutter_libs_plugin.h>
#include <url_launcher_linux/url_launcher_plugin.h> #include <url_launcher_linux/url_launcher_plugin.h>
void fl_register_plugins(FlPluginRegistry* registry) { void fl_register_plugins(FlPluginRegistry* registry) {
@ -17,6 +18,9 @@ void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) flutter_secure_storage_linux_registrar = g_autoptr(FlPluginRegistrar) flutter_secure_storage_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "FlutterSecureStorageLinuxPlugin"); fl_plugin_registry_get_registrar_for_plugin(registry, "FlutterSecureStorageLinuxPlugin");
flutter_secure_storage_linux_plugin_register_with_registrar(flutter_secure_storage_linux_registrar); flutter_secure_storage_linux_plugin_register_with_registrar(flutter_secure_storage_linux_registrar);
g_autoptr(FlPluginRegistrar) isar_flutter_libs_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "IsarFlutterLibsPlugin");
isar_flutter_libs_plugin_register_with_registrar(isar_flutter_libs_registrar);
g_autoptr(FlPluginRegistrar) url_launcher_linux_registrar = g_autoptr(FlPluginRegistrar) url_launcher_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "UrlLauncherPlugin"); fl_plugin_registry_get_registrar_for_plugin(registry, "UrlLauncherPlugin");
url_launcher_plugin_register_with_registrar(url_launcher_linux_registrar); url_launcher_plugin_register_with_registrar(url_launcher_linux_registrar);

View File

@ -5,6 +5,7 @@
list(APPEND FLUTTER_PLUGIN_LIST list(APPEND FLUTTER_PLUGIN_LIST
file_selector_linux file_selector_linux
flutter_secure_storage_linux flutter_secure_storage_linux
isar_flutter_libs
url_launcher_linux url_launcher_linux
) )

View File

@ -8,6 +8,7 @@ import Foundation
import connectivity_plus import connectivity_plus
import file_selector_macos import file_selector_macos
import flutter_secure_storage_macos import flutter_secure_storage_macos
import isar_flutter_libs
import path_provider_foundation import path_provider_foundation
import shared_preferences_foundation import shared_preferences_foundation
import sqflite_darwin import sqflite_darwin
@ -17,6 +18,7 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
ConnectivityPlusPlugin.register(with: registry.registrar(forPlugin: "ConnectivityPlusPlugin")) ConnectivityPlusPlugin.register(with: registry.registrar(forPlugin: "ConnectivityPlusPlugin"))
FileSelectorPlugin.register(with: registry.registrar(forPlugin: "FileSelectorPlugin")) FileSelectorPlugin.register(with: registry.registrar(forPlugin: "FileSelectorPlugin"))
FlutterSecureStoragePlugin.register(with: registry.registrar(forPlugin: "FlutterSecureStoragePlugin")) FlutterSecureStoragePlugin.register(with: registry.registrar(forPlugin: "FlutterSecureStoragePlugin"))
IsarFlutterLibsPlugin.register(with: registry.registrar(forPlugin: "IsarFlutterLibsPlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin")) SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
SqflitePlugin.register(with: registry.registrar(forPlugin: "SqflitePlugin")) SqflitePlugin.register(with: registry.registrar(forPlugin: "SqflitePlugin"))

View File

@ -818,6 +818,22 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "1.0.4" version: "1.0.4"
isar:
dependency: "direct main"
description:
name: isar
sha256: "99165dadb2cf2329d3140198363a7e7bff9bbd441871898a87e26914d25cf1ea"
url: "https://pub.dev"
source: hosted
version: "3.1.0+1"
isar_flutter_libs:
dependency: "direct main"
description:
name: isar_flutter_libs
sha256: bc6768cc4b9c61aabff77152e7f33b4b17d2fc93134f7af1c3dd51500fe8d5e8
url: "https://pub.dev"
source: hosted
version: "3.1.0+1"
jni: jni:
dependency: transitive dependency: transitive
description: description:

View File

@ -74,6 +74,8 @@ dependencies:
collection: ^1.18.0 collection: ^1.18.0
mime: ^2.0.0 mime: ^2.0.0
web_socket_channel: ^3.0.1 web_socket_channel: ^3.0.1
isar: ^3.1.0+1
isar_flutter_libs: ^3.1.0+1
hive: ^2.2.3 hive: ^2.2.3
hive_flutter: ^1.1.0 hive_flutter: ^1.1.0

View File

@ -9,6 +9,7 @@
#include <connectivity_plus/connectivity_plus_windows_plugin.h> #include <connectivity_plus/connectivity_plus_windows_plugin.h>
#include <file_selector_windows/file_selector_windows.h> #include <file_selector_windows/file_selector_windows.h>
#include <flutter_secure_storage_windows/flutter_secure_storage_windows_plugin.h> #include <flutter_secure_storage_windows/flutter_secure_storage_windows_plugin.h>
#include <isar_flutter_libs/isar_flutter_libs_plugin.h>
#include <url_launcher_windows/url_launcher_windows.h> #include <url_launcher_windows/url_launcher_windows.h>
void RegisterPlugins(flutter::PluginRegistry* registry) { void RegisterPlugins(flutter::PluginRegistry* registry) {
@ -18,6 +19,8 @@ void RegisterPlugins(flutter::PluginRegistry* registry) {
registry->GetRegistrarForPlugin("FileSelectorWindows")); registry->GetRegistrarForPlugin("FileSelectorWindows"));
FlutterSecureStorageWindowsPluginRegisterWithRegistrar( FlutterSecureStorageWindowsPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("FlutterSecureStorageWindowsPlugin")); registry->GetRegistrarForPlugin("FlutterSecureStorageWindowsPlugin"));
IsarFlutterLibsPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("IsarFlutterLibsPlugin"));
UrlLauncherWindowsRegisterWithRegistrar( UrlLauncherWindowsRegisterWithRegistrar(
registry->GetRegistrarForPlugin("UrlLauncherWindows")); registry->GetRegistrarForPlugin("UrlLauncherWindows"));
} }

View File

@ -6,6 +6,7 @@ list(APPEND FLUTTER_PLUGIN_LIST
connectivity_plus connectivity_plus
file_selector_windows file_selector_windows
flutter_secure_storage_windows flutter_secure_storage_windows
isar_flutter_libs
url_launcher_windows url_launcher_windows
) )