mirror of
https://gitlab.com/veilid/veilidchat.git
synced 2025-12-15 08:19:03 -05:00
busy handling
This commit is contained in:
parent
43b01c7555
commit
c6f017b0d1
23 changed files with 307 additions and 179 deletions
|
|
@ -36,7 +36,9 @@ typedef ActiveConversationsBlocMapState
|
|||
// Automatically follows the state of a ChatListCubit.
|
||||
class ActiveConversationsBlocMapCubit extends BlocMapCubit<TypedKey,
|
||||
AsyncValue<ActiveConversationState>, ActiveConversationCubit>
|
||||
with StateFollower<AsyncValue<IList<proto.Chat>>, TypedKey, proto.Chat> {
|
||||
with
|
||||
StateFollower<BlocBusyState<AsyncValue<IList<proto.Chat>>>, TypedKey,
|
||||
proto.Chat> {
|
||||
ActiveConversationsBlocMapCubit(
|
||||
{required ActiveAccountInfo activeAccountInfo,
|
||||
required ContactListCubit contactListCubit})
|
||||
|
|
@ -73,8 +75,9 @@ class ActiveConversationsBlocMapCubit extends BlocMapCubit<TypedKey,
|
|||
/// StateFollower /////////////////////////
|
||||
|
||||
@override
|
||||
IMap<TypedKey, proto.Chat> getStateMap(AsyncValue<IList<proto.Chat>> state) {
|
||||
final stateValue = state.data?.value;
|
||||
IMap<TypedKey, proto.Chat> getStateMap(
|
||||
BlocBusyState<AsyncValue<IList<proto.Chat>>> state) {
|
||||
final stateValue = state.state.data?.value;
|
||||
if (stateValue == null) {
|
||||
return IMap();
|
||||
}
|
||||
|
|
@ -88,7 +91,7 @@ class ActiveConversationsBlocMapCubit extends BlocMapCubit<TypedKey,
|
|||
|
||||
@override
|
||||
Future<void> updateState(TypedKey key, proto.Chat value) async {
|
||||
final contactList = _contactListCubit.state.data?.value;
|
||||
final contactList = _contactListCubit.state.state.data?.value;
|
||||
if (contactList == null) {
|
||||
await addState(key, const AsyncValue.loading());
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:bloc_tools/bloc_tools.dart';
|
||||
import 'package:veilid_support/veilid_support.dart';
|
||||
|
||||
import '../../account_manager/account_manager.dart';
|
||||
|
|
@ -44,7 +42,9 @@ class ChatListCubit extends DHTShortArrayCubit<proto.Chat> {
|
|||
|
||||
// Add Chat to account's list
|
||||
// if this fails, don't keep retrying, user can try again later
|
||||
if (await shortArray.tryAddItem(chat.writeToBuffer()) == false) {
|
||||
final added = await operate(
|
||||
(shortArray) => shortArray.tryAddItem(chat.writeToBuffer()));
|
||||
if (!added) {
|
||||
throw Exception('Failed to add chat');
|
||||
}
|
||||
}
|
||||
|
|
@ -57,17 +57,18 @@ class ChatListCubit extends DHTShortArrayCubit<proto.Chat> {
|
|||
|
||||
// Remove Chat from account's list
|
||||
// if this fails, don't keep retrying, user can try again later
|
||||
|
||||
for (var i = 0; i < shortArray.length; i++) {
|
||||
final cbuf = await shortArray.getItem(i);
|
||||
if (cbuf == null) {
|
||||
throw Exception('Failed to get chat');
|
||||
await operate((shortArray) async {
|
||||
for (var i = 0; i < shortArray.length; i++) {
|
||||
final cbuf = await shortArray.getItem(i);
|
||||
if (cbuf == null) {
|
||||
throw Exception('Failed to get chat');
|
||||
}
|
||||
final c = proto.Chat.fromBuffer(cbuf);
|
||||
if (c.remoteConversationKey == remoteConversationKey) {
|
||||
await shortArray.tryRemoveItem(i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
final c = proto.Chat.fromBuffer(cbuf);
|
||||
if (c.remoteConversationKey == remoteConversationKey) {
|
||||
await shortArray.tryRemoveItem(i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,10 +10,15 @@ import '../../theme/theme.dart';
|
|||
import '../chat_list.dart';
|
||||
|
||||
class ChatSingleContactItemWidget extends StatelessWidget {
|
||||
const ChatSingleContactItemWidget({required proto.Contact contact, super.key})
|
||||
: _contact = contact;
|
||||
const ChatSingleContactItemWidget({
|
||||
required proto.Contact contact,
|
||||
required bool disabled,
|
||||
super.key,
|
||||
}) : _contact = contact,
|
||||
_disabled = disabled;
|
||||
|
||||
final proto.Contact _contact;
|
||||
final bool _disabled;
|
||||
|
||||
@override
|
||||
// ignore: prefer_expression_function_bodies
|
||||
|
|
@ -43,12 +48,14 @@ class ChatSingleContactItemWidget extends StatelessWidget {
|
|||
motion: const DrawerMotion(),
|
||||
children: [
|
||||
SlidableAction(
|
||||
onPressed: (context) async {
|
||||
final chatListCubit = context.read<ChatListCubit>();
|
||||
await chatListCubit.deleteChat(
|
||||
remoteConversationRecordKey:
|
||||
remoteConversationRecordKey);
|
||||
},
|
||||
onPressed: _disabled
|
||||
? null
|
||||
: (context) async {
|
||||
final chatListCubit = context.read<ChatListCubit>();
|
||||
await chatListCubit.deleteChat(
|
||||
remoteConversationRecordKey:
|
||||
remoteConversationRecordKey);
|
||||
},
|
||||
backgroundColor: scale.tertiaryScale.background,
|
||||
foregroundColor: scale.tertiaryScale.text,
|
||||
icon: Icons.delete,
|
||||
|
|
@ -67,11 +74,14 @@ class ChatSingleContactItemWidget extends StatelessWidget {
|
|||
// The child of the Slidable is what the user sees when the
|
||||
// component is not dragged.
|
||||
child: ListTile(
|
||||
onTap: () {
|
||||
singleFuture(activeChatCubit, () async {
|
||||
activeChatCubit.setActiveChat(remoteConversationRecordKey);
|
||||
});
|
||||
},
|
||||
onTap: _disabled
|
||||
? null
|
||||
: () {
|
||||
singleFuture(activeChatCubit, () async {
|
||||
activeChatCubit
|
||||
.setActiveChat(remoteConversationRecordKey);
|
||||
});
|
||||
},
|
||||
title: Text(_contact.editedProfile.name),
|
||||
|
||||
/// xxx show last message here
|
||||
|
|
|
|||
|
|
@ -45,7 +45,8 @@ class ChatSingleContactListWidget extends StatelessWidget {
|
|||
return const Text('...');
|
||||
}
|
||||
return ChatSingleContactItemWidget(
|
||||
contact: contact);
|
||||
contact: contact,
|
||||
disabled: contactListV.busy);
|
||||
},
|
||||
filter: (value) {
|
||||
final lowerValue = value.toLowerCase();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue