Skip to content

Commit

Permalink
feat: refactor codes
Browse files Browse the repository at this point in the history
  • Loading branch information
kosukesaigusa committed Sep 27, 2023
1 parent 89fba5f commit 36b9acf
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 125 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,6 @@ class ChatMessageRepository {
)
.orderBy('createdAt', descending: true)
.limit(limit)
: query.orderBy('createAt', descending: true).limit(limit),
: query.orderBy('createdAt', descending: true).limit(limit),
);
}
3 changes: 2 additions & 1 deletion packages/mottai_flutter_app/lib/chat/chat_room.dart
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,8 @@ class StartChat {
await _chatMessageRepository.addChatMessage(
chatRoomId: chatRoomId,
senderId: workerId,
chatMessageType: ChatMessageType.host,
// メッセージを始めるのは常にワーカー。
chatMessageType: ChatMessageType.worker,
content: content,
);
return chatRoomId;
Expand Down
3 changes: 2 additions & 1 deletion packages/mottai_flutter_app/lib/chat/chat_rooms.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ const _maxUnReadCount = 10;
/// 取得する [StreamProvider].
final _unReadCountStreamProvider =
StreamProvider.autoDispose.family<int, ReadChatRoom>((ref, readChatRoom) {
final readStatus = ref.watch(myReadStatusStreamProvider(readChatRoom)).value;
final readStatus =
ref.watch(myReadStatusStreamProvider(readChatRoom)).valueOrNull;
final lastReadAt = readStatus?.lastReadAt;
return ref
.watch(chatMessageRepositoryProvider)
Expand Down
145 changes: 23 additions & 122 deletions packages/mottai_flutter_app/lib/chat/ui/chat_room.dart
Original file line number Diff line number Diff line change
Expand Up @@ -103,45 +103,32 @@ class _ChatRoomPageState extends ConsumerState<ChatRoomPage> {
)) {
return const Unavailable('そのチャットルームは表示できません。');
}
return Stack(
return Column(
children: [
Column(
children: [
Expanded(
child: ListView.builder(
itemCount: state.readChatMessages.length,
reverse: true,
controller: _scrollController,
itemBuilder: (context, index) {
final readChatMessage = state.readChatMessages[index];
return Padding(
padding: const EdgeInsets.only(bottom: 24),
child: _ChatMessageItem(
readChatRoom: readChatRoom,
readChatMessage: readChatMessage,
isMyMessage: readChatMessage.senderId == userId,
chatRoomId: widget.chatRoomId,
),
);
},
),
),
_MessageTextField(
chatRoomId: widget.chatRoomId,
userId: userId,
),
const Gap(24),
],
),
Positioned(
child: Align(
alignment: Alignment.topCenter,
child: _DebugIndicator(
chatRoomId: widget.chatRoomId,
readChatRoom: readChatRoom,
),
Expanded(
child: ListView.builder(
itemCount: state.readChatMessages.length,
reverse: true,
controller: _scrollController,
itemBuilder: (context, index) {
final readChatMessage = state.readChatMessages[index];
return Padding(
padding: const EdgeInsets.only(bottom: 24),
child: _ChatMessageItem(
readChatRoom: readChatRoom,
readChatMessage: readChatMessage,
isMyMessage: readChatMessage.senderId == userId,
chatRoomId: widget.chatRoomId,
),
);
},
),
),
_MessageTextField(
chatRoomId: widget.chatRoomId,
userId: userId,
),
const Gap(24),
],
);
},
Expand Down Expand Up @@ -436,89 +423,3 @@ class _MessageTextFieldState extends ConsumerState<_MessageTextField> {
}
}
}

// TODO: 後で消す
/// 開発時のみ表示する、無限スクロールのデバッグ用ウィジェット。
class _DebugIndicator extends ConsumerWidget {
const _DebugIndicator({
required this.chatRoomId,
required this.readChatRoom,
});

final String chatRoomId;

final ReadChatRoom readChatRoom;

@override
Widget build(BuildContext context, WidgetRef ref) {
final state = ref.watch(chatRoomStateNotifierProvider(chatRoomId));
final readChatMessages = state.readChatMessages;
final lastReadChatMessageId = state.lastReadChatMessageId;
final partnerLastReadAt = ref.watch(
chatPartnerLastReadAtProvider(
readChatRoom,
),
);
return Container(
width: double.infinity,
margin: const EdgeInsets.only(top: 16, left: 16, right: 16),
padding: const EdgeInsets.all(16),
decoration: const BoxDecoration(
color: Colors.black38,
borderRadius: BorderRadius.all(Radius.circular(8)),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Text(
'デバッグウィンドウ',
style: Theme.of(context)
.textTheme
.titleSmall!
.copyWith(color: Colors.white),
),
const Gap(4),
Text(
'取得したメッセージ:${readChatMessages.length.withComma} 件',
style: Theme.of(context)
.textTheme
.bodySmall!
.copyWith(color: Colors.white),
),
Text(
'取得中?:${state.fetching}',
style: Theme.of(context)
.textTheme
.bodySmall!
.copyWith(color: Colors.white),
),
Text(
'まだ取得できる?:${state.hasMore}',
style: Theme.of(context)
.textTheme
.bodySmall!
.copyWith(color: Colors.white),
),
if (lastReadChatMessageId != null)
Text(
'最後に取得したドキュメント ID:$lastReadChatMessageId',
style: Theme.of(context)
.textTheme
.bodySmall!
.copyWith(color: Colors.white),
),
Text(
'パートナーの既読時間:$partnerLastReadAt',
style: Theme.of(context)
.textTheme
.bodySmall!
.copyWith(color: Colors.white),
),
const Gap(8),
],
),
);
}
}

0 comments on commit 36b9acf

Please sign in to comment.