Skip to content

Commit

Permalink
fix permission denied error while creating and deleting thread
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-ishita-g committed Jul 22, 2024
1 parent 949b7f2 commit 5863db3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
19 changes: 10 additions & 9 deletions data/lib/api/message/api_message_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,22 @@ class ApiMessageService {
.map((snapshot) => snapshot.docs.map((doc) => doc.data()).toList());
}

Stream<List<ApiThreadMessage>> getLatestMessages(String threadId, {int limit = 20}) {
print('called in api message service file');
Stream<List<ApiThreadMessage>> streamLatestMessages(String threadId, {int limit = 20}) {
return threadMessageRef(threadId)
.orderBy("created_at", descending: true)
.limit(limit)
.snapshots()
.map((snapshot) => snapshot.docs.map((doc) => ApiThreadMessage.fromJson(doc.data() as Map<String, dynamic>)).toList());
}

Future<List<ApiThreadMessage>> getLatestMessages(String threadId, {int limit = 20}) async {
final snapshot = await threadMessageRef(threadId)
.orderBy("created_at", descending: true)
.limit(limit)
.get();
return snapshot.docs.map((doc) => ApiThreadMessage.fromJson(doc.data() as Map<String, dynamic>)).toList();
}

Stream<List<ApiUserInfo>> getLatestMessagesMembers(ApiThread thread) async* {
final List<ApiUserInfo?> memberInfoList = [];
for (String memberId in thread.member_ids) {
Expand Down Expand Up @@ -130,12 +137,6 @@ class ApiMessageService {
if (threads.isEmpty) return Stream.value([]);

final futures = threads.map((thread) async {
final List<ApiThreadMessage> messages = [];

getLatestMessages(thread.id, limit: 20).listen((messageList) {
messages.addAll(messageList);
});

final List<ApiUserInfo?> memberInfoList = [];
for (String memberId in thread.member_ids) {
final user = await userService.getUser(memberId);
Expand All @@ -147,7 +148,7 @@ class ApiMessageService {

return ThreadInfo(
thread: thread,
threadMessage: messages,
threadMessage: await getLatestMessages(thread.id, limit: 20),
members: filteredMemberInfoList,
);
}).toList();
Expand Down
2 changes: 1 addition & 1 deletion data/lib/service/message_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class MessageService {
}

Stream<List<ApiThreadMessage>> getLatestMessages(String threadId, {int limit = 20}) {
return messageService.getLatestMessages(threadId, limit: limit);
return messageService.streamLatestMessages(threadId, limit: limit);
}

Stream<List<ApiUserInfo>> getLatestMessageMember(ApiThread thread) {
Expand Down

0 comments on commit 5863db3

Please sign in to comment.