tagConversation static method

Future<Conversation?> tagConversation(
  1. String conversationWith,
  2. String conversationType,
  3. List<String> tags, {
  4. required dynamic onSuccess(
    1. Conversation conversation
    )?,
  5. required dynamic onError(
    1. CometChatException excep
    )?,
})

Tag a conversation

conversationWith The id of conversation

conversationType The user or group

Tag a conversation with custom tags.

Migration Note: Migrated from platform channels to native Dart implementation. Uses ConversationRepository for tagging conversations. Behavior and signature remain identical for backward compatibility.

Android Reference: CometChat.tagConversation(String conversationWith, String conversationType, List<String> tags, CallbackListener<Conversation>)

method could throw PlatformException with error codes specifying the cause

Implementation

static Future<Conversation?> tagConversation(
  String conversationWith,
  String conversationType,
  List<String> tags, {
  required Function(Conversation conversation)? onSuccess,
  required Function(CometChatException excep)? onError,
}) async {
  try {
    // Get SDK instance
    final sdk = SdkRegistry.getInstance();

    // Call native Dart conversation repository
    final conversation = await sdk.conversations.tagConversation(
      conversationWith,
      conversationType,
      tags,
    );

    // Offline: merge the new tags into the cached conversation (tags-only, so
    // the cached preview / unread / LRU / window state survive). Otherwise a
    // cache-first read would keep returning the OLD tags until the next sync.
    await OfflineRuntime.instance.onConversationTagged(conversation);

    // Call success callback
    if (onSuccess != null) onSuccess(conversation);
    return conversation;
  } on SdkException catch (sdkEx) {
    // Convert SdkException to CometChatException
    final cometChatEx = CometChatException(
      sdkEx.code,
      sdkEx.details ?? sdkEx.message,
      sdkEx.message,
    );
    _errorCallbackHandler(cometChatEx, null, null, onError);
  } catch (e) {
    _errorCallbackHandler(null, null, e, onError);
  }
  return null;
}