The Methods below are available for Group chat:
Method | Description |
---|---|
createGroup | Allows logged-in user to create a group |
renameGroup | Allows Group Creator or Moderator to rename the group |
inviteUser | Allows logged-in user to invite other user to the group |
joinGroup | Allows logged-in user to join a group |
getGroupMembers | Gets list of the Group Members |
getAllGroup | Gets list of all the groups accessible to currently opened group chat |
sendMessage | Allows logged-in user to send a message to currently opened group chat |
sendImage | Allows logged-in user to send an image to currently opened group chat |
sendVideo | Allows logged-in user to send a video to currently opened group chat |
sendAudioFile | Allows logged-in user to send an audio file to currently opened group chat |
sendSticker | Allows logged-in user to send a sticker to currently opened group chat |
sendFile | Allows logged-in user to send a file to the group |
getGroupHistory | Gets the previous messages in currently opened group chat |
getCurrentGroup | Gets the id of in currently opened group chat |
leaveGroup | Allows logged-in user to leave currently opened group chat |
deleteGroup | Allows logged-in user to delete a group if he is creator or moderator of the group |
createGroup
Allows logged-in user to create a group Method Signature:
createGroup(String groupName, String groupPassword, GroupType type, Callbacks callback)
Example:
cometChat.createGroup("Night's Watch", "", GroupType.PUBLIC_GROUP, new Callbacks(){
@Override
public void successCallback(JSONObject response){ /* Code Block */ }
@Override
public void failCallback(JSONObject response){ /* Code Block */ }
});
Arguments:
Argument | Description |
---|---|
groupName | Name of the group |
groupPassword | Password for password-protected group |
type | 1 indicates public group and 2 indecates password-protected group |
callback | Success and failure callback |
Response for successCallback:
{
group_id: 7
}
Description:
Response Property | Description |
---|---|
group_id | id of the created group |
renameGroup
Allows Group Creator or Moderator to rename the group Method Signature:
renameGroup(String groupId, String groupName, Callbacks callbacks)
Example:
cometChat.renameGroup("5", "Starks", new Callbacks(){
@Override
public void successCallback(JSONObject response){ /* Code Block */ }
@Override
public void failCallback(JSONObject response){ /* Code Block */ }
});
Arguments:
Argument | Description |
---|---|
groupId | id of the group to rename |
groupname | New name for the group |
callback | success and failure callback |
Response for successCallback:
{
group_id: 5
}
inviteUser
Allows logged-in user to invite other user to the group Method Signature:
inviteUser(JSONArray userArray,String groupId,String groupName, Callbacks callback)
Example:
JSONArray users = new JSONArray();
users.put(1);
users.put(2);
cometChat.inviteUser(users,"11","Test Group" new Callbacks(){
@Override
public void successCallback(JSONObject response){ /* Code Block */ }
@Override
public void failCallback(JSONObject response){ /* Code Block */ }
});
Arguments:
Argument | Description |
---|---|
users | JSONArray containing id of the users to invite |
groupid | id of the group |
groupName | name of the group |
callback | success and failure callbacks |
Response for successCallback:
{
group_id: 15
}
Description:
Response Property | Description |
---|---|
group_id | id of the deleted group |
joinGroup
Allows logged-in user to join a group
joinGroup(String groupId, String groupName, String groupPassword, Callbacks callback )
Example:
cometChat.joinGroup("5", "Starks", "", new Callbacks(){
@Override
public void successCallback(JSONObject response){ /* Code Block */ }
@Override
public void failCallback(JSONObject response){ /* Code Block */ }
});
Agruments:
Argument | Description |
---|---|
groupId | id of a group to join |
groupName | name of the group to join |
groupPassword | password for password-protected group |
callback | success and failure callbacks |
Response for successCallback:
{
"group_id": "5",
"push_channel": "C_c49602157105d9d6383bb30695f771e8"
}
Description:
Response Property | Description |
---|---|
group_id | id of the joined group |
push_channel | a unique channel to receive the mobile push notification for the joined group |
getGroupMembers
Gets list of the Group Members Method Signature:
getGroupMembers(String groupid, Callbacks callbacks)
Example:
cometChat.getGroupMembers("5", new Callbacks(){
@Override
public void successCallback(JSONObject response){ /* Code Block */ }
@Override
public void failCallback(JSONObject response){ /* Code Block */ }
});
Arguments:
Argument | Description |
---|---|
groupid | id of a group |
callback | success and failure callbacks |
getAllGroup
Gets list of all the groups accessible to currently opened group chat Method Signature:
getAllGroup(Callbacks callback)
Example:
cometChat.getAllGroup(new Callbacks(){
@Override
public void successCallback(JSONObject response){ /* Code Block */ }
@Override
public void failCallback(JSONObject response){ /* Code Block */ }
});
Arguments:
Argument | Description |
---|---|
callback | success and failure callbacks |
Response for successCallback:
{
"_4":{
"id":"4", "name":"group1", "online":"1", "type":"0", "i":"", "s":0
},
"_2":{
"id":"2", "name":"group2", "online":"0", "type":"0","i":"","s":0
}
}
Description:
Response Property | Description |
---|---|
id | id of a group |
name | name of a group |
online | number of group participants |
type | type of a group. 1 indicates public group |
i | represents password for password protected group |
s | 1 indicates Owner, 2 indicates Moderator and 0 Indicates logged-in user is neither Owner nor Moderator for the group |
getCurrentGroup
Gets the id of in currently opened group chat Method Signature:
getCurrentGroup()
leaveGroup
Allows logged-in user to leave currently opened group chat Method Signature:
leaveGroup(String groupId,Callbacks callback)
Example:
cometChat.leaveGroup("21", new Callbacks(){
@Override
public void successCallback(JSONObject response){ /* Code Block */ }
@Override
public void failCallback(JSONObject response){ /* Code Block */ }
});
Arguments:
Argument | Description |
---|---|
groupId | id of the group to be left |
callback | success and failure callbacks |
deleteGroup
Allows logged-in user to delete a group if he is creator or moderator of the group Method Signature:
deleteGroup(String groupId, Callbacks callback)
Example:
cometChat.deleteGroup("15", new Callbacks(){
@Override
public void successCallback(JSONObject response){ /* Code Block */ }
@Override
public void failCallback(JSONObject response){ /* Code Block */ }
});
Arguments:
Argument | Description |
---|---|
groupId | id of a group to delete |
callback | success and failure callbacks |
Response for successCallback:
{
group_id: 15
}
Description:
Response Property | Description |
---|---|
group_id | id of the deleted group |
sendMessage
Allows logged-in user to send message to other users. Method Signature:
sendMessage(long localId, String toId, String message, boolean isGroup, Callbacks callbacks)
Example:
cometChat.sendMessage(100, "5", "When you play a game of thrones you win or you die.", true, new Callbacks(){
@Override
public void successCallback(JSONObject response){ /* Code Block */ }
@Override
public void failCallback(JSONObject response){ /* Code Block */ }
});
Arguments:
Argument | Description |
---|---|
localId | a parameter which is returned to you with the response to keep track of the status of the message sent |
toId | recipient’s user id |
message | text message |
isGroup | is recipient group or user |
callback | success and failure callbacks |
Response for successCallback:
{
"id": 71,
"localmessageid":100,
"m": "When you play a game of thrones you win or you die."
}
Description:
Response type | Description |
---|---|
id | id of the message |
m | The message received from the server |
sendImage
Allows logged-in user to send an image using Bitmap or filepath Method Signature:
sendImage(long localId, Bitmap bitmap, String toId, boolean isGroup, Callbacks callbacks)
Example:
cometChat.sendImage(101,bitmap, "5", true, new Callbacks(){
@Override
public void successCallback(JSONObject response){ /* Code Block */ }
@Override
public void failCallback(JSONObject response){ /* Code Block */ }
});
Arguments:
Argument | Description |
---|---|
localId | a parameter which is returned to you with the response to keep track of the status of the message sent |
bitmap | bitmap of the image |
toId | recipient’s user id |
isGroup | is recipient group or user |
callback | success and failure callbacks |
Response for successCallback:
{
"id": 23,
"localmessageid" : 101,
"original_file": "/storage/sdcard0/IMG20140929182949.jpg"
}
sendVideo
Allows logged-in user to send a video Method Signature:
sendVideo(long localId, String filePath, String toId, boolean isGroup, Callbacks callbacks)
Example:
cometChat.sendVideo(102,"/storage/sdcard0/video1.mp4", "5", true, new Callbacks(){
@Override
public void successCallback(JSONObject response){ /* Code Block */ }
@Override
public void failCallback(JSONObject response){ /* Code Block */ }
});
Arguments:
Argument | Description |
---|---|
localId | a parameter which is returned to you with the response to keep track of the status of the message sent |
filepath | path of the file |
toId | recipient’s user id |
isGroup | is recipient group or user |
callback | success and failure callbacks |
Response for successCallback:
{
"id": 23,
"localmessageid:102,
"original_file": "/storage/sdcard0/video1.mp4"
}
sendAudioFile
Allows logged-in user to send an audio file or recorded audio notes Method Signature:
sendAudioFile(long localId, File audioFile, String toId, boolean isGroup, Callbacks callbacks)
Example:
cometChat.sendAudioFile(104, new File("/storage/sdcard0/audio1.aac"), "5", true, new Callbacks(){
@Override
public void successCallback(JSONObject response){ /* Code Block */ }
@Override
public void failCallback(JSONObject response){ /* Code Block */ }
});
Arguments:
Argument | Description |
---|---|
localId | a parameter which is returned to you with the response to keep track of the status of the message sent |
audioFile | audio file from storage |
toId | recipient’s user id |
isGroup | is recipient group or user |
callback | success and failure callbacks |
Response for successCallback:
{
"id": 23,
"localmessageid" : 104,
"original_file": "/storage/sdcard0/audio1.aac"
}
sendSticker
Allows the user to send a sticker.
Method signature:
sendSticker(long localId, String message, String id, boolean isGroup, Callbacks callback)
Example:
cometChat.sendSticker(601,"bear_2", "15", true, new Callbacks() {
@Override
public void successCallback(JSONObject response){ /* Code Block */ }
@Override
public void failCallback(JSONObject response){ /* Code Block */ }
});
Arguments:
Argument | Description |
---|---|
localId | A unique value that is returned to you in the response to keep track of the status of the message |
message | Sticker name |
toId | recipient’s user id |
isGroup | true if recipient is a group, else false |
callback | success and failure callbacks |
sendFile
Allows the logged in user to send a file to a group.
Method Signature:
sendFile(long localId, File file, String id, boolean isGroup, Callbacks callback)
Example:
cometChat.sendFile(701,file, "15", true, new Callbacks() {
@Override
public void successCallback(JSONObject response){ /* Code Block */ }
@Override
public void failCallback(JSONObject response){ /* Code Block */ }
});
Argument | Description |
---|---|
localId | A unique value that is returned to you in the response to keep track of the status of the message |
file | file to be sent |
toId | recipient’s user id |
isGroup | true if recipient is a group, else false |
callback | success and failure callbacks |