clearThread method
Future<void>
clearThread(
- String path,
- MeshDocument thread, {
- bool useAgentMessages = false,
- String? participantName,
})
Implementation
Future<void> clearThread(String path, MeshDocument thread, {bool useAgentMessages = false, String? participantName}) async {
if (useAgentMessages) {
final room = _requireRoom('Clearing an agent thread');
await Future.wait([
for (final participant in getAgentParticipants(thread, participantName: participantName))
room.messaging.sendMessage(
to: participant,
type: agentRoomMessageType,
message: {"type": agentThreadClearType, "thread_id": path},
),
]);
return;
}
final room = _requireRoom('Clearing a thread');
final normalizedParticipantName = participantName?.trim();
final participant = room.messaging.remoteParticipants.firstWhereOrNull((x) {
if (normalizedParticipantName == null || normalizedParticipantName.isEmpty) {
return true;
}
return x.getAttribute("name") == normalizedParticipantName;
});
if (participant != null) {
await room.messaging.sendMessage(to: participant, type: "clear", message: {"path": path});
}
}