/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "nsISupports.idl"
#include "prplIConversation.idl"
#include "imIContactsService.idl"

interface prplIMessage;

[scriptable, uuid(a09faf46-bb9d-402f-b460-89f8d7827ff1)]
interface imIConversation: prplIConversation {
  // Will be null for MUCs and IMs from people not in the contacts list.
  readonly attribute imIContact contact;

  // Write a system message into the conversation.
  // Note: this will not be logged.
  void systemMessage(in AUTF8String aMessage, [optional] in boolean aIsError);

  attribute prplIConversation target;

  // Number of unread messages (all messages, including system
  // messages are counted).
  readonly attribute unsigned long unreadMessageCount;
  // Number of unread incoming messages targeted at the user (= IMs or
  // message containing the user's nick in MUCs).
  readonly attribute unsigned long unreadTargetedMessageCount;
  // Number of unread incoming messages (both targeted and untargeted
  // messages are counted).
  readonly attribute unsigned long unreadIncomingMessageCount;
  // Reset all unread message counts.
  void markAsRead();

  // Call this to give the core an opportunity to close an inactive
  // conversation.  If the conversation is a left MUC or an IM
  // conversation without unread message, the implementation will call
  // close().
  // The returned value indicates if the conversation was closed.
  boolean checkClose();

  // Get an array of all messages of the conversation.
  void getMessages([optional] out unsigned long messageCount,
                   [retval, array, size_is(messageCount)] out prplIMessage messages);
};

[scriptable, uuid(984e182c-d395-4fba-ba6e-cc80c71f57bf)]
interface imIConversationsService: nsISupports {
  void initConversations();
  void unInitConversations();

  // register a conversation. This will create a unique id for the
  // conversation and set it.
  void addConversation(in prplIConversation aConversation);
  void removeConversation(in prplIConversation aConversation);

  void getUIConversations([optional] out unsigned long conversationCount,
                          [retval, array, size_is(conversationCount)] out imIConversation conversations);
  imIConversation getUIConversation(in prplIConversation aConversation);
  imIConversation getUIConversationByContactId(in long aId);

  nsISimpleEnumerator getConversations();
  prplIConversation getConversationById(in unsigned long aId);
  prplIConversation getConversationByNameAndAccount(in AUTF8String aName,
                                                      in imIAccount aAccount,
                                                      in boolean aIsChat);
};
