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.

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
    }
  
    // 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 sendVideoMessage() method with extra parameter to send a video message with quote.

// Send video with file Uri
TapCoreMessageManager.getInstance().sendVideoMessage(VIDEO_URI, CAPTION, ROOM, QUOTED_MESSAGE, new TapCoreSendMessageListener() {
    @Override
    public void onStart(TAPMessageModel message) {
        // Message was constructed
    }
  
    @Override