Skip to content
Open
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
1 change: 1 addition & 0 deletions lib/database/io/chat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,7 @@ class Chat {
chatId: chat.id!,
chatGuid: chat.guid,
participantsData: chat.handles.map((e) => e.toMap()).toList(),
chatStyle: chat.style ?? 0,
offset: offset,
limit: limit,
includeDeleted: includeDeleted,
Expand Down
28 changes: 19 additions & 9 deletions lib/services/backend/actions/chat_actions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,9 @@ class ChatActions {

static Future<List<int>> getMessagesAsync(dynamic data) async {
final chatId = data['chatId'] as int;
// chatStyle == 43 means iMessage group chat; a more reliable group indicator
// than participants.length when the local participant list is stale.
final chatStyle = data['chatStyle'] as int? ?? 0;
final participantsData = (data['participantsData'] as List).cast<Map<String, dynamic>>();
final offset = data['offset'] as int? ?? 0;
final limit = data['limit'] as int? ?? 25;
Expand Down Expand Up @@ -764,15 +767,22 @@ class ChatActions {
afterQuery.close();
}

// Handle matching - filter out messages that don't match participant requirements
for (int i = 0; i < messages.length; i++) {
Message message = messages[i];
if (participants.isNotEmpty && !message.isFromMe! && message.handleId != null && message.handleId != 0) {
Handle? handle =
participants.firstWhereOrNull((e) => e.originalROWID == message.handleId) ?? message.getHandle();
if (handle == null && message.originalROWID != null) {
messages.remove(message);
i--;
// 1:1 only: drop messages whose sender doesn't match the sole participant.
// Group messages are already chat-linked; filtering them here hides valid
// messages when the local participant list is stale (the "infinite spinner" /
// missing group messages bug). chatStyle == 43 is iMessage group; keep the
// participant-count check as a fallback for SMS groups (style != 43).
final isGroupChat = chatStyle == 43 || participants.length > 1;
if (!isGroupChat) {
for (int i = 0; i < messages.length; i++) {
Message message = messages[i];
if (participants.isNotEmpty && !message.isFromMe! && message.handleId != null && message.handleId != 0) {
final Handle? handle =
participants.firstWhereOrNull((e) => e.originalROWID == message.handleId) ?? message.getHandle();
if (handle == null && message.originalROWID != null) {
messages.remove(message);
i--;
}
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions lib/services/backend/interfaces/chat_interface.dart
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ class ChatInterface {
required int chatId,
required String chatGuid,
required List<Map<String, dynamic>> participantsData,
int chatStyle = 0,
int offset = 0,
int limit = 25,
bool includeDeleted = false,
Expand All @@ -255,6 +256,7 @@ class ChatInterface {
'chatId': chatId,
'chatGuid': chatGuid,
'participantsData': participantsData,
'chatStyle': chatStyle,
'offset': offset,
'limit': limit,
'includeDeleted': includeDeleted,
Expand Down