Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chat messages pagination #51

Merged
merged 2 commits into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
import 'package:cloud_firestore/cloud_firestore.dart';

import '../firestore_documents/chat_message.dart';

class ChatMessageRepository {
final _query = ChatMessageQuery();

/// 指定したチャットルームのメッセージの、指定した [lastReadQueryDocumentSnapshot]
/// 以降のメッセージを [limit] 件だけ取得する。
/// Dart 3 以降の [Record] を用いて、取得した [ReadChatMessage] 一覧に加え、
/// 最後に取得した [QueryDocumentSnapshot] も返す。
Future<(List<ReadChatMessage>, QueryDocumentSnapshot<ReadChatMessage>?)>
loadMessagesWithCursor({
required String chatRoomId,
required int limit,
required QueryDocumentSnapshot<ReadChatMessage>?
lastReadQueryDocumentSnapshot,
}) async {
var query = readChatMessageCollectionReference(chatRoomId: chatRoomId)
.orderBy('createdAt', descending: true);
final qds = lastReadQueryDocumentSnapshot;
if (qds != null) {
query = query.startAfterDocument(qds);
}
final qs = await query.limit(limit).get();
final readChatMessages = qs.docs.map((qds) => qds.data()).toList();
return (readChatMessages, qs.docs.lastOrNull);
Comment on lines +12 to +27
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Muhyun-Kim

チャット機能の実装にあたって必要ならこれをいい感じに書き換えてください!

}
}
54 changes: 27 additions & 27 deletions packages/mottai_flutter_app/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ packages:
dependency: transitive
description:
name: _flutterfire_internals
sha256: a742f71d7f3484253a623b30e19256aa4668ecbb3de6ad1beb0bcf8d4777ecd8
sha256: "5dce45a06d386358334eb1689108db6455d90ceb0d75848d5f4819283d4ee2b8"
url: "https://pub.dev"
source: hosted
version: "1.3.3"
version: "1.3.4"
analyzer:
dependency: transitive
description:
Expand Down Expand Up @@ -138,29 +138,29 @@ packages:
source: hosted
version: "1.1.1"
cloud_firestore:
dependency: transitive
dependency: "direct main"
description:
name: cloud_firestore
sha256: "5bbc1f5bffa79af54ca035b92b57f81c6fb35ee5471ead67e29c8e12de8432f8"
sha256: "035b91f66b60dab5eefcc217accc734020234f79d963b075699920b95334a755"
url: "https://pub.dev"
source: hosted
version: "4.8.2"
version: "4.8.3"
cloud_firestore_platform_interface:
dependency: transitive
description:
name: cloud_firestore_platform_interface
sha256: "8e0aafeb727087f84710275d59a101b2acf2290ffbb3b111aab70423f8350d5d"
sha256: "86bd1865abbeb09a7d09da3e70364a09f894937270651fc611a1c6d6a9f7b02c"
url: "https://pub.dev"
source: hosted
version: "5.15.2"
version: "5.15.3"
cloud_firestore_web:
dependency: transitive
description:
name: cloud_firestore_web
sha256: bbf0ebb9d1e9251caa00e8727389313c64cb4240c1c31f895971c52d0c782316
sha256: ac2eeb2a7ab1928c3aacc30eed750fa839d6f620e112a5459e321df217be2f47
url: "https://pub.dev"
source: hosted
version: "3.6.2"
version: "3.6.3"
code_builder:
dependency: transitive
description:
Expand Down Expand Up @@ -260,26 +260,26 @@ packages:
dependency: "direct main"
description:
name: firebase_auth
sha256: f693c0aa998b1101453878951b171b69f0db5199003df1c943b33493a1de7917
sha256: "87216661b409575ecb1a7849da38604a0abfcb6497146b66d4832cb97a4c9e0f"
url: "https://pub.dev"
source: hosted
version: "4.6.3"
version: "4.7.0"
firebase_auth_platform_interface:
dependency: transitive
description:
name: firebase_auth_platform_interface
sha256: "689ae048b78ad088ba31acdec45f5badb56201e749ed8b534947a7303ddb32aa"
sha256: "4ab0a8997994db2b76bf0652689d7908ca935a99314857c683251bc23d31c287"
url: "https://pub.dev"
source: hosted
version: "6.15.3"
version: "6.16.0"
firebase_auth_web:
dependency: transitive
description:
name: firebase_auth_web
sha256: f35d637a1707afd51f30090bb5234b381d5071ccbfef09b8c393bc7c65e440cd
sha256: c74c5753855896b31536b9e151e34bf7eea143f0d9c209947b5f7ddc8e111989
url: "https://pub.dev"
source: hosted
version: "5.5.3"
version: "5.6.0"
firebase_common:
dependency: "direct main"
description:
Expand All @@ -291,10 +291,10 @@ packages:
dependency: "direct main"
description:
name: firebase_core
sha256: a4a99204da264a0aa9d54a332ea0315ce7b0768075139c77abefe98093dd98be
sha256: "2e9324f719e90200dc7d3c4f5d2abc26052f9f2b995d3b6626c47a0dfe1c8192"
url: "https://pub.dev"
source: hosted
version: "2.14.0"
version: "2.15.0"
firebase_core_platform_interface:
dependency: transitive
description:
Expand All @@ -315,42 +315,42 @@ packages:
dependency: "direct main"
description:
name: firebase_dynamic_links
sha256: "9b984d0abd227a702451a997abcca763f4dbf67e260dad60e5506d55e3eff244"
sha256: "4872f4d7e94736041398bc3490c2ddd87ee159d6b051ba01ca2708e5260a7ebe"
url: "https://pub.dev"
source: hosted
version: "5.3.3"
version: "5.3.4"
firebase_dynamic_links_platform_interface:
dependency: transitive
description:
name: firebase_dynamic_links_platform_interface
sha256: "6ef00a0be18f3231e9727f7c4b31db89dbfa16792098beb850603c30854560ff"
sha256: "946fccfefb67e26bf63e392f1b3917d79ea031d3071488f0c5e8ab72de8219ab"
url: "https://pub.dev"
source: hosted
version: "0.2.6+3"
version: "0.2.6+4"
firebase_messaging:
dependency: "direct main"
description:
name: firebase_messaging
sha256: "7a09d8c21147f009882a27c96de1918ea283f974d73cb6fae1d234bb9ec18d8b"
sha256: "8ac91d83a028eef050de770f1dc98421e215714d245f34de7b154d436676fbd0"
url: "https://pub.dev"
source: hosted
version: "14.6.4"
version: "14.6.5"
firebase_messaging_platform_interface:
dependency: transitive
description:
name: firebase_messaging_platform_interface
sha256: e9e9dc48a3d8ffa67aaba3d6b1ebf74bc7d7d8c83d10b1458ff97878b9d8a2b0
sha256: b2995e3640efb646e9ebf0e2fa50dea84895f0746a31d7e3af0e5e009a533a1a
url: "https://pub.dev"
source: hosted
version: "4.5.3"
version: "4.5.4"
firebase_messaging_web:
dependency: transitive
description:
name: firebase_messaging_web
sha256: "381f217e41e0e407baf8df21787b97e46fabfacefd6a953425be3a6cdf2269f4"
sha256: "5d8446a28339124a2cb4f57a6ca454a3aca7d0c5c0cdfa5707afb192f7c830a7"
url: "https://pub.dev"
source: hosted
version: "3.5.3"
version: "3.5.4"
firebase_storage:
dependency: transitive
description:
Expand Down
9 changes: 5 additions & 4 deletions packages/mottai_flutter_app/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ environment:

dependencies:
auto_route: ^7.7.0
cloud_firestore: ^4.8.3
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

本当は追加したくなかったけれど、仕方なく。

mottai_flutter_app のチャット機能で最後に読み込んだ QueryDocumentSnapshot を保持する必要があるため。

dart_flutter_common:
path: ../dart_flutter_common
firebase_auth: ^4.6.3
firebase_auth: ^4.7.0
firebase_common:
path: ../firebase_common
firebase_core: ^2.14.0
firebase_dynamic_links: ^5.3.3
firebase_messaging: ^14.6.4
firebase_core: ^2.15.0
firebase_dynamic_links: ^5.3.4
firebase_messaging: ^14.6.5
flutter:
sdk: flutter
flutter_image_compress: ^2.0.3
Expand Down