Chat Room and Messages - TapCore

If you are using core implementation method, you can use the methods from the TapCoreChatRoomManager and TapCoreMessageManager class to manage chat room and messages.

TapTalk Chat Method

Description

Returns the room model of the currently active chat room.

Create new personal chat room with recipient user, or obtain chat room data if it already exists

Create new personal chat room with recipient user ID, or obtain chat room data if it already exists.

Obtain locally saved chat room details with a roomID.

Create a new group chat room with selected group name.

Create a new group chat room with selected group name and group picture.

Get room details from selected room ID.

Update existing group chat room data.

Update group picture with current selected image.

Delete group chat room from the device's local storage.

Delete group chat room and clear all chat data and participants.

Leave from selected group chat.

Add selected member(s) to current group chat room.

Remove selected member(s) from current group chat room.

Promote selected member(s) as admin(s) to the current group chat room.

Demote selected admin(s) to member(s) to the current group chat room.

Obtain Saved Messages chat room data

Notify that the active user has started typing in the selected room.

Notify that the active user has stopped typing in the selected room.

Send a new text message to the selected chat room.

Send a new message with location to the selected chat room.

Send a new image message to the selected chat room.

Send a new video message to the selected chat room.

Send a new file message to the selected chat room.

Send a new voice message to the selected chat room.

Send a new link message to the selected chat room.

Forward existing messages to the selected chat room.

Construct a customized TapTalk.io message model.

Send a new custom message to the room defined in the message model.

Edit the contents of the selected message.

Delete the selected message from the server.

Delete the selected message from local storage.

Cancel image, video, or file upload on the selected pending message.

Start a file download from the selected file, image, or video message.

Cancel image, video, or file download on the selected message.

Upload an image file to TapTalk.io server without sending message.

Upload a video file to TapTalk.io server without sending message.

Upload a document to TapTalk.io server without sending message.

Mark message as delivered by the active user.

Mark message as read by the active user.

Mark all unread messages in a chat room as read.

Retrieve messages from chat room that are already stored in the device's local storage.

Retrieve messages that are older than the provided timestamp from the server to the selected chat room.

Retrieve newer messages from the server to the selected chat room

Retrieve all available messages from the selected chat room.

Retrieve unread messages from the device's local storage.

Retrieve media messages from the device's local storage.

Call this method to search messages from the device's local storage with a keyword.

Set message as starred or remove star from message for the active user.

Retrieve list of messages marked as starred in a chat room.

Set message as pinned or remove pin from message for all room participants.

Retrieve list of pinned messages in a chat room.

Retrieve image, video, file, and link messages from a chat room.

Clear all existing messages in a selected chat room for the active user.

Schedule a message to be delivered at a specified time.

Retrieve list of created scheduled messages in a chat room.

Send a previously created scheduled message immediately to the recipient.

Change the deliver time of a previously created scheduled message.

Update the contents of a scheduled message that has not been delivered.

Delete a scheduled message that has not been delivered.

Retrieve info about a message's recipients that has read or received the message.

Retrieve a message's total read count from a non-personal room.

Get Active Chat Room

Returns the room model (TAPRoomModel) of the currently active chat room.

TAPRoomModel activeRoom = TapCoreChatRoomManager.getInstance().getActiveChatRoom();

Get Personal Chat Room with Recipient User

Create new personal chat room with recipient user, or obtain chat room data if it already exists.

TapCoreChatRoomManager.getInstance().getPersonalChatRoom(RECIPIENT_USER, new TapCoreGetRoomListener() {
    @Override
    public void onSuccess(TAPRoomModel room) {
        // Open chat room here
    }

    @Override
    public void onError(String errorCode, String errorMessage) {

    }
});

Parameters RECIPIENT_USER: (TAPUserModel) recipient user data

Get Personal Chat Room with Recipient User ID

Create new personal chat room with recipient user ID, or obtain chat room data if it already exists.

TapCoreChatRoomManager.getInstance().getPersonalChatRoom(RECIPIENT_ID, new TapCoreGetRoomListener() {
    @Override
    public void onSuccess(TAPRoomModel room) {
        // Open chat room here
    }

    @Override
    public void onError(String errorCode, String errorMessage) {

    }
});

Parameters RECIPIENT_ID: (String) user ID of recipient

Get Local Chat Room Data

Obtain locally saved chat room details with a roomID. Returns the saved room model or null if it does not exist.

TAPRoomModel room = TapCoreChatRoomManager.getInstance().getLocalChatRoomData(ROOM_ID);

Parameters ROOM_ID: (String) selected room's ID

Create Group Chat Room

Create a new group chat room with selected group name.

TapCoreChatRoomManager.getInstance().createGroupChatRoom(GROUP_NAME, PARTICIPANT_LIST, new TapCoreGetRoomListener() {
    @Override
    public void onSuccess(TAPRoomModel room) {
        // Group chat room created successfully            
    }

    @Override
    public void onError(String errorCode, String errorMessage) {

    }
});

Parameters GROUP_NAME: (String) your group name PARTICIPANT_LIST: (List) list of the group participant's user IDs

Create Group Chat Room

Create a new group chat room with selected group name and group picture.

TapCoreChatRoomManager.getInstance().createGroupChatRoomWithPicture(GROUP_NAME, PARTICIPANT_LIST, IMAGE_URI, new TapCoreCreateGroupWithPictureListener() {
    @Override
    public void onSuccess(TAPRoomModel room, boolean isPictureUploadSuccess) {
        // Group chat room created successfully            
    }

    @Override
    public void onError(String errorCode, String errorMessage) {

    }
});

Parameters GROUP_NAME: (String) name of the group chat room to create PARTICIPANT_LIST: (List) list of the group participant's user IDs IMAGE_URI: (Uri) picture to be uploaded as the group's profile

Get Chat Room Data

Get room details from selected room ID.

TapCoreChatRoomManager.getInstance().getChatRoomData(ROOM_ID,  new TapCoreGetRoomListener() {
    @Override
    public void onSuccess(TAPRoomModel room) {
        // Open chat room here
    }

    @Override
    public void onError(String errorCode, String errorMessage) {

    }
});

Parameters ROOM_ID: (String) selected room's ID

Update Group Chat Room Details

Create a new Update existing group chat room data.

TapCoreChatRoomManager.getInstance().updateGroupChatRoomDetails(GROUP_ID, GROUP_NAME, new TapCoreGetRoomListener() {
    @Override
    public void onSuccess(TAPRoomModel room) {
        // Updated group chat room successfully         
    }

    @Override
    public void onError(String errorCode, String errorMessage) {

    }
});

Parameters GROUP_ID: (String) room ID of group GROUP_NAME: (String) name of group

Update Group Image

Update group picture with current selected image.

TapCoreChatRoomManager.getInstance().updateGroupPicture(GROUP_ID, IMAGE_URI, new TapCoreGetRoomListener() {
    @Override
    public void onSuccess(TAPRoomModel room) {
        // Updated group chat room successfully
    }

    @Override
    public void onError(String errorCode, String errorMessage) {

    }
});

Parameters GROUP_ID: (String) room ID of the selected group IMAGE_URI: (Uri) new picture for the group's profile

Delete Local Group Chat Room

Delete group chat room from the device's local storage and clear all chat data and participants. Locally deleted room data will still be accessible from the server if the user remains a participant in the room.

TapCoreChatRoomManager.getInstance().deleteLocalGroupChatRoom(ROOM_ID, new TapCommonListener() {
    @Override
    public void onSuccess(String successMessage) {
        // Deleted group chat room successfully
    }

    @Override
    public void onError(String errorCode, String errorMessage) {

    }
});

Parameters ROOM_ID: (String) group room ID to be deleted

Delete Group Chat Room

Delete group chat room and clear all chat data and participants.

TapCoreChatRoomManager.getInstance().deleteGroupChatRoom(GROUP_CHAT_MODEL, new TapCommonListener() {
    @Override
    public void onSuccess(String successMessage) {
        // Deleted group chat room successfully
    }

    @Override
    public void onError(String errorCode, String errorMessage) {

    }
});

Parameters GROUP_CHAT_MODEL: (TAPRoomModel) a room model of the group to delete

Leave Group Chat

Leave from selected group chat.

TapCoreChatRoomManager.getInstance().leaveGroupChatRoom(GROUP_ID, new TapCommonListener() {
    @Override
    public void onSuccess(String successMessage) {
        // Left chat room successfully
    }

    @Override
    public void onError(String errorCode, String errorMessage) {

    }
});

Parameters GROUP_ID: (String) room ID of the selected group

Add Members to Group Chat

Add selected member(s) to current group chat room.

TapCoreChatRoomManager.getInstance().addGroupChatMembers(GROUP_ID, USER_IDs, new TapCoreGetRoomListener() {
    @Override
    public void onSuccess(TAPRoomModel room) {
        // Added group members successfully
    }

    @Override
    public void onError(String errorCode, String errorMessage) {

    }
});

Parameters GROUP_ID: (String) room ID of the selected group USER_IDs: (List) list of the user IDs to add to the group

Remove Members from Group Chat

Remove selected member(s) from current group chat room.

TapCoreChatRoomManager.getInstance().removeGroupChatMembers(GROUP_ID, USER_IDs, new TapCoreGetRoomListener() {
    @Override
    public void onSuccess(TAPRoomModel room) {
        // Removed members successfully    
    }

    @Override
    public void onError(String errorCode, String errorMessage) {

    }
});

Parameters GROUP_ID: (String) room ID of the selected group USER_IDs: (List) list of the user IDs to add to the group

Promote Group Admin

Promote selected member(s) as admin(s) to the current group chat room.

TapCoreChatRoomManager.getInstance().promoteGroupAdmins(GROUP_ID, USER_IDs, new TapCoreGetRoomListener() {
    @Override
    public void onSuccess(TAPRoomModel room) {
        // Promoted admins successfully 
    }

    @Override
    public void onError(String errorCode, String errorMessage) {

    }
});

Parameters GROUP_ID: (String) room ID of the selected group USER_IDs: (List) list of the user IDs to add to the group

Demote Group Admin

Demote selected admin(s) to member(s) to the current group chat room.

 TapCoreChatRoomManager.getInstance().demoteGroupAdmins(GROUP_ID, USER_IDs, new TapCoreGetRoomListener() {
    @Override
    public void onSuccess(TAPRoomModel room) {
        // Demoted admins successfully 
    }

    @Override
    public void onError(String errorCode, String errorMessage) {

    }
});

Parameters GROUP_ID: (String) room ID of the selected group USER_IDs: (List) list of the user IDs to add to the group

Get Saved Messages Chat Room

Obtain Saved Messages chat room data.

TapCoreChatRoomManager.getInstance(instanceKey).getSavedMessagesChatRoom(new TapCoreGetRoomListener() {
    @Override
    public void onSuccess(TAPRoomModel room) {
        // Open chat room here
    }
    
    @Override
    public void onError(String errorCode, String errorMessage) {

    }
});

Send Start Typing

Notify that the active user has started typing in the selected room.

TapCoreChatRoomManager.getInstance().sendStartTypingEmit(ROOM_ID);

Parameters ROOM_ID: (String) ID of the room where the user starts typing in

Send Stop Typing

Notify that the active user has stopped typing in the selected room.

TapCoreChatRoomManager.getInstance().sendStopTypingEmit(ROOM_ID);

Parameters ROOM_ID: (String) ID of the room where the user starts typing in

Send Text Message

To send a text message to a chat room, use the sendTextMessage() method from the TapCoreMessageManager class.

TapCoreMessageManager.getInstance().sendTextMessage(MESSAGE_BODY, ROOM, new TapCoreSendMessageListener() {
    @Override
    public void onStart(TAPMessageModel message) {
        // Message was constructed
    }

    @Override
    public void onSuccess(TAPMessageModel message) {
        // Message was sent successfully
    }

    @Override
    public void onError(@Nullable TAPMessageModel message, String errorCode, String errorMessage) {
      
    }
});

Use the sendTextMessage() method with extra parameter to send a text message with quote.

TapCoreMessageManager.getInstance().sendTextMessage(MESSAGE_BODY, ROOM, QUOTED_MESSAGE, new TapCoreSendMessageListener() {
    @Override
    public void onStart(TAPMessageModel message) {
        // Message was constructed
    }

    @Override
    public void onSuccess(TAPMessageModel message) {
        // Message was sent successfully
    }

    @Override
    public void onError(@Nullable TAPMessageModel message, String errorCode, String errorMessage) {
      
    }
});

Parameters MESSAGE_BODY: (String) content of the message ROOM: (TAPRoomModel) the destination room where the message will be sent QUOTED_MESSAGE: (TAPMessageModel) quote containing another existing message

Send Location Message

You can send a location embedded in a chat message using sendLocationMessage(). This method takes latitude, longitude, and address text as parameters.

TapCoreMessageManager.getInstance().sendLocationMessage(LATITUDE, LONGITUDE, ADDRESS, ROOM, new TapCoreSendMessageListener() {
    @Override
    public void onStart(TAPMessageModel message) {
        // Message was constructed
    }

    @Override
    public void onSuccess(TAPMessageModel message) {
        // Message was sent successfully
    }

    @Override
    public void onError(@Nullable TAPMessageModel message, String errorCode, String errorMessage) {
      
    }
});

Use the sendLocationMessage() method with extra parameter to send a location message with quote.

TapCoreMessageManager.getInstance().sendLocationMessage(LATITUDE, LONGITUDE, ADDRESS, ROOM, QUOTED_MESSAGE, new TapCoreSendMessageListener() {
    @Override
    public void onStart(TAPMessageModel message) {
        // Message was constructed
    }

    @Override
    public void onSuccess(TAPMessageModel message) {
        // Message was sent successfully
    }

    @Override
    public void onError(@Nullable TAPMessageModel message, String errorCode, String errorMessage) {
      
    }
});

Parameters LATITUDE: (Double) latitude of the shared location LONGITUDE: (Double) longitude of the shared location ADDRESS: (String) text data containing the location address ROOM: (TAPRoomModel) the destination room where the message will be sent QUOTED_MESSAGE: (TAPMessageModel) quote containing another existing message

Send Image Message

To send an image to a chat room, you can use sendImageMessage() method by providing either IMAGE_URI, BITMAP, or IMAGE_URL as parameter.

// Send image with file Uri
TapCoreMessageManager.getInstance().sendImageMessage(IMAGE_URI, CAPTION, ROOM, new TapCoreSendMessageListener() {
    @Override
    public void onStart(TAPMessageModel message) {
        // Message was constructed
    }
  
    @Override
    public void onProgress(TAPMessageModel message, int percentage, long bytes) {
        // Image upload is in progress
    }

    @Override
    public void onSuccess(TAPMessageModel message) {
        // Message was sent successfully
    }

    @Override
    public void onError(@Nullable TAPMessageModel message, String errorCode, String errorMessage) {
      
    }
});
// Send image with Bitmap
TapCoreMessageManager.getInstance().sendImageMessage(BITMAP, CAPTION, ROOM, new TapCoreSendMessageListener() {
    @Override
    public void onStart(TAPMessageModel message) {
        // Message was constructed
    }
  
    @Override
    public void onProgress(TAPMessageModel message, int percentage, long bytes) {
        // Image upload is in progress
    }

    @Override
    public void onSuccess(TAPMessageModel message) {
        // Message was sent successfully
    }

    @Override
    public void onError(@Nullable TAPMessageModel message, String errorCode, String errorMessage) {
      
    }
});
// Send image with remote image URL
TapCoreMessageManager.getInstance().sendImageMessage(IMAGE_URL, CAPTION, ROOM, FETCH_METADATA, new TapCoreSendMessageListener() {
    @Override
    public void onTemporaryMessageCreated(TAPMessageModel message) {
        // Temporary message was created while fetching metadata
        // This callback will be called when FETCH_METADATA is true
    }
    
    @Override
    public void onStart(TAPMessageModel message) {
        // Message was constructed
    }
  
    // onProgress is not called when remote URL is provided

    @Override
    public void onSuccess(TAPMessageModel message) {
        // Message was sent successfully
    }

    @Override
    public void onError(@Nullable TAPMessageModel message, String errorCode, String errorMessage) {
      
    }
});

Use the sendImageMessage() method with extra parameter to send an image message with quote.

// Send image with file Uri
TapCoreMessageManager.getInstance().sendImageMessage(IMAGE_URI, CAPTION, ROOM, QUOTED_MESSAGE, new TapCoreSendMessageListener() {
    @Override
    public void onStart(TAPMessageModel message) {
        // Message was constructed
    }
  
    @Override
    public void onProgress(TAPMessageModel message, int percentage, long bytes) {
        // Image upload is in progress
    }

    @Override
    public void onSuccess(TAPMessageModel message) {
        // Message was sent successfully
    }

    @Override
    public void onError(@Nullable TAPMessageModel message, String errorCode, String errorMessage) {
      
    }
});
// Send image with Bitmap
TapCoreMessageManager.getInstance().sendImageMessage(BITMAP, CAPTION, ROOM, QUOTED_MESSAGE, new TapCoreSendMessageListener() {
    @Override
    public void onStart(TAPMessageModel message) {
        // Message was constructed
    }
  
    @Override
    public void onProgress(TAPMessageModel message, int percentage, long bytes) {
        // Image upload is in progress
    }

    @Override
    public void onSuccess(TAPMessageModel message) {
        // Message was sent successfully
    }

    @Override
    public void onError(@Nullable TAPMessageModel message, String errorCode, String errorMessage) {
      
    }
});
// Send image with remote image URL
TapCoreMessageManager.getInstance().sendImageMessage(IMAGE_URL, CAPTION, ROOM, QUOTED_MESSAGE, FETCH_METADATA, new TapCoreSendMessageListener() {
    @Override
    public void onTemporaryMessageCreated(TAPMessageModel message) {
        // Temporary message was created while fetching metadata
        // This callback will be called when FETCH_METADATA is true
    }
    
    @Override
    public void onStart(TAPMessageModel message) {
        // Message was constructed
    }
  
    // onProgress is not called when remote URL is provided

    @Override
    public void onSuccess(TAPMessageModel message) {
        // Message was sent successfully
    }

    @Override
    public void onError(@Nullable TAPMessageModel message, String errorCode, String errorMessage) {
      
    }
});

Parameters IMAGE_URI: (Uri) local Uri of the image file BITMAP: (Bitmap) bitmap file of the image IMAGE_URL: (String) remote URL of the image file CAPTION: (String) caption for the image ROOM: (TAPRoomModel) the destination room where the message will be sent QUOTED_MESSAGE: (TAPMessageModel) quote containing another existing message FETCH_METADATA: (boolean) inserts metadata from remote URL to the constructed message when true

Send Video Message

To send a video to a chat room, you can use sendVideoMessage() method by providing VIDEO_URI or VIDEO_URL.

// Send video with file Uri
TapCoreMessageManager.getInstance().sendVideoMessage(VIDEO_URI, CAPTION, ROOM, new TapCoreSendMessageListener() {
    @Override
    public void onStart(TAPMessageModel message) {
        // Message was constructed
    }
  
    @Override
    public void onProgress(TAPMessageModel message, int percentage, long bytes) {
        // Video upload is in progress
    }

    @Override
    public void onSuccess(TAPMessageModel message) {
        // Message was sent successfully
    }

    @Override
    public void onError(@Nullable TAPMessageModel message, String errorCode, String errorMessage) {
      
    }
});
// Send video with remote video URL
TapCoreMessageManager.getInstance().sendVideoMessage(CONTEXT, VIDEO_URL, CAPTION, ROOM, FETCH_METADATA, new TapCoreSendMessageListener() {
    @Override
    public void onTemporaryMessageCreated(TAPMessageModel message) {
        // Temporary message was created while fetching metadata
        // This callback will be called when FETCH_METADATA is true
    }
    
    @Override
    public void onStart(TAPMessageModel message) {
        // Message was constructed