mirror of
https://gitlab.com/veilid/veilidchat.git
synced 2025-08-17 10:20:34 -04:00
clean up context locators
This commit is contained in:
parent
751022e743
commit
2ccad50f9a
31 changed files with 603 additions and 542 deletions
|
@ -3,9 +3,9 @@ import 'dart:async';
|
|||
import 'package:bloc_advanced_tools/bloc_advanced_tools.dart';
|
||||
import 'package:fast_immutable_collections/fast_immutable_collections.dart';
|
||||
import 'package:fixnum/fixnum.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:veilid_support/veilid_support.dart';
|
||||
|
||||
import '../../account_manager/account_manager.dart';
|
||||
import '../../chat/chat.dart';
|
||||
import '../../proto/proto.dart' as proto;
|
||||
import '../../tools/tools.dart';
|
||||
|
@ -19,21 +19,17 @@ typedef ChatListCubitState = DHTShortArrayBusyState<proto.Chat>;
|
|||
class ChatListCubit extends DHTShortArrayCubit<proto.Chat>
|
||||
with StateMapFollowable<ChatListCubitState, TypedKey, proto.Chat> {
|
||||
ChatListCubit({
|
||||
required UnlockedAccountInfo unlockedAccountInfo,
|
||||
required proto.Account account,
|
||||
required this.activeChatCubit,
|
||||
}) : super(
|
||||
open: () => _open(unlockedAccountInfo, account),
|
||||
required Locator locator,
|
||||
required TypedKey accountRecordKey,
|
||||
required OwnedDHTRecordPointer chatListRecordPointer,
|
||||
}) : _locator = locator,
|
||||
super(
|
||||
open: () => _open(locator, accountRecordKey, chatListRecordPointer),
|
||||
decodeElement: proto.Chat.fromBuffer);
|
||||
|
||||
static Future<DHTShortArray> _open(
|
||||
UnlockedAccountInfo activeAccountInfo, proto.Account account) async {
|
||||
final accountRecordKey =
|
||||
activeAccountInfo.userLogin.accountRecordInfo.accountRecord.recordKey;
|
||||
|
||||
final chatListRecordKey = account.chatList.toVeilid();
|
||||
|
||||
final dhtRecord = await DHTShortArray.openOwned(chatListRecordKey,
|
||||
static Future<DHTShortArray> _open(Locator locator, TypedKey accountRecordKey,
|
||||
OwnedDHTRecordPointer chatListRecordPointer) async {
|
||||
final dhtRecord = await DHTShortArray.openOwned(chatListRecordPointer,
|
||||
debugName: 'ChatListCubit::_open::ChatList', parent: accountRecordKey);
|
||||
|
||||
return dhtRecord;
|
||||
|
@ -41,11 +37,11 @@ class ChatListCubit extends DHTShortArrayCubit<proto.Chat>
|
|||
|
||||
Future<proto.ChatSettings> getDefaultChatSettings(
|
||||
proto.Contact contact) async {
|
||||
final pronouns = contact.editedProfile.pronouns.isEmpty
|
||||
final pronouns = contact.profile.pronouns.isEmpty
|
||||
? ''
|
||||
: ' (${contact.editedProfile.pronouns})';
|
||||
: ' [${contact.profile.pronouns}])';
|
||||
return proto.ChatSettings()
|
||||
..title = '${contact.editedProfile.name}$pronouns'
|
||||
..title = '${contact.displayName}$pronouns'
|
||||
..description = ''
|
||||
..defaultExpiration = Int64.ZERO;
|
||||
}
|
||||
|
@ -99,6 +95,7 @@ class ChatListCubit extends DHTShortArrayCubit<proto.Chat>
|
|||
final deletedItem =
|
||||
// Ensure followers get their changes before we return
|
||||
await syncFollowers(() => operateWrite((writer) async {
|
||||
final activeChatCubit = _locator<ActiveChatCubit>();
|
||||
if (activeChatCubit.state == localConversationRecordKey) {
|
||||
activeChatCubit.setActiveChat(null);
|
||||
}
|
||||
|
@ -142,5 +139,5 @@ class ChatListCubit extends DHTShortArrayCubit<proto.Chat>
|
|||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
final ActiveChatCubit activeChatCubit;
|
||||
final Locator _locator;
|
||||
}
|
||||
|
|
|
@ -28,13 +28,31 @@ class ChatSingleContactItemWidget extends StatelessWidget {
|
|||
_contact.localConversationRecordKey.toVeilid();
|
||||
final selected = activeChatCubit.state == localConversationRecordKey;
|
||||
|
||||
late final String title;
|
||||
late final String subtitle;
|
||||
if (_contact.nickname.isNotEmpty) {
|
||||
title = _contact.nickname;
|
||||
if (_contact.profile.pronouns.isNotEmpty) {
|
||||
subtitle = '${_contact.profile.name} (${_contact.profile.pronouns})';
|
||||
} else {
|
||||
subtitle = _contact.profile.name;
|
||||
}
|
||||
} else {
|
||||
title = _contact.profile.name;
|
||||
if (_contact.profile.pronouns.isNotEmpty) {
|
||||
subtitle = '(${_contact.profile.pronouns})';
|
||||
} else {
|
||||
subtitle = '';
|
||||
}
|
||||
}
|
||||
|
||||
return SliderTile(
|
||||
key: ObjectKey(_contact),
|
||||
disabled: _disabled,
|
||||
selected: selected,
|
||||
tileScale: ScaleKind.secondary,
|
||||
title: _contact.editedProfile.name,
|
||||
subtitle: _contact.editedProfile.pronouns,
|
||||
title: title,
|
||||
subtitle: subtitle,
|
||||
icon: Icons.chat,
|
||||
onTap: () {
|
||||
singleFuture(activeChatCubit, () async {
|
||||
|
|
|
@ -53,10 +53,13 @@ class ChatSingleContactListWidget extends StatelessWidget {
|
|||
if (contact == null) {
|
||||
return false;
|
||||
}
|
||||
return contact.editedProfile.name
|
||||
return contact.nickname
|
||||
.toLowerCase()
|
||||
.contains(lowerValue) ||
|
||||
contact.editedProfile.pronouns
|
||||
contact.profile.name
|
||||
.toLowerCase()
|
||||
.contains(lowerValue) ||
|
||||
contact.profile.pronouns
|
||||
.toLowerCase()
|
||||
.contains(lowerValue);
|
||||
}).toList();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue