Interface ChatMessage


public interface ChatMessage
An chat message is the object that is sent or received through a ChatRoom
.

To create a ChatMessage, use ChatRoom.createEmptyMessage(), then
either add text using addUtf8TextContent(java.lang.String) or a Content with
file informations using addFileContent(org.linphone.core.Content). A valid Content for
file transfer must contain a type and subtype, the name of the file and it's
size. Finally call send() to send it.
To send files through a ChatMessage, you need to have configured a file
transfer server URL with Core.setFileTransferServer(java.lang.String). On the receiving
side, either use downloadContent(org.linphone.core.Content) to download received files or enable
auto-download in the Core using Core.setMaxSizeForAutoDownloadIncomingFiles(int)
, -1 disabling the feature and 0 always downloading files no matter it's size.
Keep in mind a ChatMessage created by a {@link ChatRoom#Backend#Basic}
ChatRoom can only contain one Content, either text or file.
  • Method Details

    • getAppdata

      @Nullable String getAppdata()
      Linphone message has an app-specific field that can store a text.

      The application might want to use it for keeping data over restarts, like
      thumbnail image path.
      Returns:
      the application-specific data or null if none has been stored.
    • setAppdata

      void setAppdata(@Nullable String data)
      Linphone message has an app-specific field that can store a text.

      The application might want to use it for keeping data over restarts, like
      thumbnail image path.
      Invoking this function will attempt to update the message storage to reflect
      the change if it is enabled.
      Parameters:
      data - the data to store into the message.
    • getCallId

      @NonNull String getCallId()
      Gets the callId accociated with the message.

      Returns:
      the call Id
    • getChatRoom

      @NonNull ChatRoom getChatRoom()
      Returns the chatroom this message belongs to.

      Returns:
      the ChatRoom in which this message has been sent or received.
    • getContentType

      @NonNull String getContentType()
      Get the content type of a chat message.

      Returns:
      The content type of the chat message
    • setContentType

      void setContentType(@NonNull String contentType)
      Set the content type of a chat message.

      This content type must match a content that is text representable, such as
      text/plain, text/html or image/svg+xml.
      Parameters:
      contentType - The new content type of the chat message
    • getContents

      @NonNull Content[] getContents()
      Returns the list of contents in the message.

      Returns:
      The list of Content.
    • getCore

      @NonNull Core getCore()
      Returns back pointer to Core object.

      Returns:
      the Core object associated with this message.
    • getEphemeralExpireTime

      long getEphemeralExpireTime()
      Returns the real time at which an ephemeral message expires and will be
      deleted.

      see: isEphemeral()
      Returns:
      the time at which an ephemeral message expires. 0 means the message has
      not been read.
    • getEphemeralLifetime

      long getEphemeralLifetime()
      Returns lifetime of an ephemeral message.

      The lifetime is the duration after which the ephemeral message will disappear
      once viewed. see: isEphemeral()
      Returns:
      the lifetime of an ephemeral message, by default 0 (disabled).
    • getErrorInfo

      @NonNull ErrorInfo getErrorInfo()
      Get full details about delivery error of a chat message.

      Returns:
      a ErrorInfo describing the details.
    • getExternalBodyUrl

      @Nullable String getExternalBodyUrl()
      Linphone message can carry external body as defined by rfc2017.

      Returns:
      external body url or null if not present.
    • setExternalBodyUrl

      void setExternalBodyUrl(@Nullable String externalBodyUrl)
      Linphone message can carry external body as defined by rfc2017.

      Parameters:
      externalBodyUrl - ex: access-type=URL; URL="http://www.foo.com/file"
    • getFileTransferInformation

      @Nullable Content getFileTransferInformation()
      Get the file_transfer_information (used by call backs to recover informations
      during a rcs file transfer)

      Returns:
      a pointer to the Content structure or null if not present.
    • getForwardInfo

      @Nullable String getForwardInfo()
      Gets the forward info if available as a string.

      Returns:
      the original sender of the message if it has been forwarded, null
      otherwise.
    • getFromAddress

      @NonNull Address getFromAddress()
      Get origin of the message.

      Returns:
      the Address of the sender.
    • isEphemeral

      boolean isEphemeral()
      Returns wether the chat message is an ephemeral message or not.

      An ephemeral message will automatically disappear from the recipient's screen
      after the message has been viewed.
      Returns:
      true if it is an ephemeral message, false otherwise
    • isFileTransfer

      @Deprecated boolean isFileTransfer()
      Deprecated.
      06/07/2020 check if getContents() contains a Content
      for which Content.isFileTransfer() returns true.
      Return whether or not a chat message is a file transfer.

      Returns:
      Whether or not the message is a file transfer
    • isFileTransferInProgress

      boolean isFileTransferInProgress()
      Gets whether or not a file is currently being downloaded or uploaded.

      Returns:
      true if download or upload is in progress, false otherwise
    • isForward

      boolean isForward()
      Returns wether the chat message is a forward message or not.

      Returns:
      true if it is a forward message, false otherwise
    • isOutgoing

      boolean isOutgoing()
      Returns wehther the message has been sent or received.

      Returns:
      true if message has been sent, false if it has been received.
    • isRead

      boolean isRead()
      Returns wether the message has been read or not.

      Returns:
      true if message has been marked as read, false otherwise.
    • isReply

      boolean isReply()
      Returns wether the chat message is a reply message or not.

      Returns:
      true if it is a reply message, false otherwise
    • isSecured

      boolean isSecured()
      Get if the message was encrypted when transfered.

      Returns:
      true if the message was encrypted when transfered, false otherwise.
    • isText

      @Deprecated boolean isText()
      Deprecated.
      06/07/2020 check if getContents() contains a Content
      with a PlainText content type.
      Return whether or not a chat message is a text.

      Returns:
      Whether or not the message is a text
    • getLocalAddress

      @NonNull Address getLocalAddress()
      Returns the local address the message was sent or received with.

      Returns:
      the Address of the local address used to send/receive this
      message.
    • getMessageId

      @NonNull String getMessageId()
      Get the message identifier.

      It is used to identify a message so that it can be notified as delivered and/or
      displayed.
      Returns:
      The message identifier.
    • getOwnReaction

      @Nullable ChatMessageReaction getOwnReaction()
      Returns our own reaction for a given chat message, if any.

      Returns:
      Our own ChatMessageReaction for that message if any, null
      otherwise.
    • getReactions

      @NonNull ChatMessageReaction[] getReactions()
      Gets the list of reactions received for this chat message.

      Warning: list is ordered by content of reaction message, not by received
      timestamp!
      Returns:
      The sorted list of reaction if any.
    • getReplyMessage

      @Nullable ChatMessage getReplyMessage()
      Returns the ChatMessage this message is a reply to.

      Returns:
      the original message ChatMessage.
    • getReplyMessageId

      @Nullable String getReplyMessageId()
      Returns the ID of the message this is a reply to.

      Returns:
      the original message id.
    • getReplyMessageSenderAddress

      @Nullable Address getReplyMessageSenderAddress()
      Returns the address of the sender of the message this is a reply to.

      Returns:
      the original message sender Address.
    • getState

      ChatMessage.State getState()
      Get the state of the message.

      Returns:
      the current ChatMessage.State of the message.
    • getTextContent

      @Deprecated @Nullable String getTextContent()
      Deprecated.
      01/07/2020. Use getUtf8Text() instead.
      Gets the text content if available as a string.

      Returns:
      the Content buffer if available in System Locale, null
      otherwise.
    • getTime

      long getTime()
      Get the time the message was sent.

      Returns:
      the timestamp of when the message was sent.
    • getToAddress

      @NonNull Address getToAddress()
      Get destination of the message.

      Returns:
      the Address of the recipient.
    • getToBeStored

      boolean getToBeStored()
      Get if a chat message is to be stored.

      Returns:
      Whether or not the message is to be stored
    • setToBeStored

      void setToBeStored(boolean toBeStored)
      Set if a chat message is to be stored.

      This content type must match a content that is text representable, such as
      text/plain, text/html or image/svg+xml.
      Parameters:
      toBeStored - Whether or not the chat message is to be stored
    • getUtf8Text

      @Nullable String getUtf8Text()
      Get text part of this message.

      Introduced in 01/07/2020
      Returns:
      The text in UTF8 or null if no text.
    • setUtf8Text

      int setUtf8Text(@Nullable String text)
      Set a chat message text to be sent by linphone_chat_room_send_message.

      Introduced in 01/07/2020
      Parameters:
      text - The text in UTF8 to set.
      Returns:
      0 if succeed.
    • addContent

      void addContent(@NonNull Content content)
      Adds a content to the ChatMessage.

      Parameters:
      content - the Content object to add.
    • addCustomHeader

      void addCustomHeader(@NonNull String headerName, @Nullable String headerValue)
      Add custom headers to the message.

      Parameters:
      headerName - name of the header
      headerValue - header value
    • addFileContent

      void addFileContent(@NonNull Content content)
      Adds a file content to the ChatMessage.

      Parameters:
      content - the Content object to add.
    • addTextContent

      @Deprecated void addTextContent(@NonNull String text)
      Deprecated.
      01/07/2020. Use addUtf8TextContent(java.lang.String) instead.
      Creates a Content of type PlainText with the given text as body.

      Parameters:
      text - The text in System Locale to add to the message.
    • addUtf8TextContent

      void addUtf8TextContent(@NonNull String text)
      Creates a Content of type PlainText with the given text as body.

      Introduced in 01/07/2020
      Parameters:
      text - The text in UTF8 to add to the message.
    • cancelFileTransfer

      void cancelFileTransfer()
      Cancel an ongoing file transfer attached to this message.

      (upload or download)
    • createReaction

      @NonNull ChatMessageReaction createReaction(@NonNull String utf8Reaction)
      Creates a emoji reaction for the given chat mesage.

      To send it, use ChatMessageReaction.send().
      Parameters:
      utf8Reaction - the emoji character(s) as UTF-8.
      Returns:
      a ChatMessageReaction object.
    • downloadContent

      boolean downloadContent(@NonNull Content content)
      Start the download of the Content referenced in the ChatMessage
      from remote server.

      Parameters:
      content - the Content object to download (must have the Content.isFileTransfer()
      method return true).
      Returns:
      false if there is an error, true otherwise.
    • getCustomHeader

      @Nullable String getCustomHeader(@NonNull String headerName)
      Retrieve a custom header value given its name.

      Parameters:
      headerName - header name searched
      Returns:
      the custom header value or null if not found.
    • getParticipantsByImdnState

      @NonNull ParticipantImdnState[] getParticipantsByImdnState(ChatMessage.State state)
      Gets the list of participants for which the imdn state has reached the
      specified state and the time at which they did.

      Parameters:
      state - The LinphoneChatMessageState the imdn have reached (only use
      LinphoneChatMessageStateDelivered, LinphoneChatMessageStateDeliveredToUser,
      LinphoneChatMessageStateDisplayed and LinphoneChatMessageStateNotDelivered)
      Returns:
      The list of participants.
    • hasConferenceInvitationContent

      boolean hasConferenceInvitationContent()
      Returns wether the chat message has a conference invitation content or not.

      Returns:
      true if it has one, false otherwise.
    • hasTextContent

      @Deprecated boolean hasTextContent()
      Deprecated.
      27/10/2020. Check if getContents() contains a Content
      for which it's content type is PlainText.
      Returns wether the chat message has a text content or not.

      Returns:
      true if it has one, false otherwise.
    • putChar

      int putChar(int character)
      Fulfill a chat message char by char.

      Message linked to a Real Time Text Call send char in realtime following RFC
      4103/T.140 To commit a message, use linphone_chat_room_send_message
      Parameters:
      character - T.140 char
      Returns:
      0 if succeed.
    • removeContent

      void removeContent(@NonNull Content content)
      Removes a content from the ChatMessage.

      Parameters:
      content - the Content object to remove.
    • removeCustomHeader

      void removeCustomHeader(@NonNull String headerName)
      Removes a custom header from the message.

      Parameters:
      headerName - name of the header to remove
    • send

      void send()
      Send a chat message.

    • addListener

      void addListener(ChatMessageListener listener)
    • removeListener

      void removeListener(ChatMessageListener listener)
    • setUserData

      void setUserData(Object data)
      Sets the object to store in this object user's data
      Parameters:
      data - the object to store
    • getUserData

      Object getUserData()
      Gets the object stored in this object user's data
      Returns:
      the object store if any, null otherwise
    • getNativePointer

      long getNativePointer()
      Gets the native pointer used by this class to make native method calls.
      Returns:
      the nativer pointer, as long
    • toString

      String toString()
      Overrides:
      toString in class Object