public class QBChatDialog extends QBEntity
QBChatDialog model describes a chat dialog entity between users (1-1 chat or group chat).
QBChatDialog is responsible for all chat related operations - send/receive messages, join, typing statuses etc.
Use DialogUtils for simple building QBChatDialog.
To listen for messages, typing notifications or "sent" status of your message just add
appropriate listeners: addIsTypingListener(QBChatDialogTypingListener), addMessageListener(QBChatDialogMessageListener), addMessageSentListener(QBChatDialogMessageSentListener).
To listen for "delivered" or "read" statuses of your message use QBMessageStatusesManager.
To handle these statuses you should mark sending message as markable QBChatMessage.setMarkable(boolean)
To notify opponent you've read message use readMessage(com.quickblox.chat.model.QBChatMessage) method.
Using of QBChatDialog:
ArrayListoccupantIdsList = ...; QBChatDialog dialog = new QBChatDialog(); dialog.setName("Chat with Garry and John"); dialog.setPhoto("1786"); dialog.setType(QBDialogType.GROUP); dialog.setOccupantsIds(occupantIdsList); //creating chat dialog on server QBRestChatService.createChatDialog(dialog).performAsync( new QBEntityCallback () { @Override public void onSuccess(QBChatDialog resultChatDialog, Bundle params) { //dialog was created successfully resultChatDialog.join(null); ... resultChatDialog.sendMessage("Hello All"); } @Override public void onError(QBResponseException responseException) { } });
| Constructor and Description |
|---|
QBChatDialog()
Constructs a new QBDialog object
|
QBChatDialog(java.lang.String id)
Constructs a new QBDialog object with ID
|
| Modifier and Type | Method and Description |
|---|---|
void |
addIsTypingListener(QBChatDialogTypingListener listener)
Adds the 'is typing' listener.
|
void |
addMessageListener(QBChatDialogMessageListener listener)
Adds the incoming messages listener.
|
void |
addMessageSentListener(QBChatDialogMessageSentListener listener)
Adds the 'message sent' listener.
|
void |
addParticipantListener(QBChatDialogParticipantListener participantListener)
Adds a listener that will be notified of any new Presence packets
sent to the group chat.
|
void |
deliverMessage(QBChatMessage message)
Delivers the message.
|
void |
deliverMessage(QBChatMessage message,
QBEntityCallback callback) |
boolean |
equals(java.lang.Object o) |
QBDialogCustomData |
getCustomData()
Gets the custom data.
|
java.lang.String |
getDialogId()
Gets the dialog's ID
|
java.util.Collection<QBChatDialogTypingListener> |
getIsTypingListeners()
Gets the list of 'is typing' listeners
|
java.lang.String |
getLastMessage()
Gets the last sent message
|
long |
getLastMessageDateSent()
Gets the last message date sent
|
java.lang.Integer |
getLastMessageUserId()
Gets the last sent message user ID
|
java.util.Collection<QBChatDialogMessageListener> |
getMessageListeners()
Gets the list of message listeners.
|
java.util.Collection<QBChatDialogMessageSentListener> |
getMessageSentListeners()
Gets the list of 'message sent' listeners
For using QBChatDialogMessageSentListener's features need enable Stream Management
before logging into the chat.
|
java.lang.String |
getName()
Gets the name
|
java.util.List<java.lang.Integer> |
getOccupants()
Gets the occupants IDs array
|
java.util.Collection<java.lang.Integer> |
getOnlineUsers()
Deprecated.
since 3.3.3, see
requestOnlineUsers() |
java.util.Collection<QBChatDialogParticipantListener> |
getParticipantListeners()
Gets the list of participant listeners.
|
java.lang.String |
getPhoto()
Gets the photo.
|
java.lang.Integer |
getRecipientId()
Returns the ID of a recipient if type = QBDialogType.PRIVATE. -1 otherwise.
|
java.lang.String |
getRoomJid()
Gets the XMPP room JID.
|
QBDialogType |
getType()
Gets the type
|
java.lang.Integer |
getUnreadMessageCount()
Gets the unread message count in this dialog
|
java.lang.Integer |
getUserId()
Gets the creator's ID of a dialog
|
int |
hashCode() |
void |
initForChat(QBChatService chatService)
Initializing current dialog for using chat functions.
|
void |
initForChat(java.lang.String dialogId,
QBDialogType type,
QBChatService chatService)
Initializing current dialog for using chat functions.
|
boolean |
isJoined()
Returns true if the user currently is in the group chat (after calling the join method).
|
boolean |
isPrivate() |
void |
join(DiscussionHistory discussionHistory)
Joins the group chat (synchronous).
|
void |
join(DiscussionHistory discussionHistory,
QBEntityCallback callback)
Joins the group chat.
|
void |
leave()
Leaves the group chat.
|
void |
readMessage(QBChatMessage message)
Reads the message.
|
void |
readMessage(QBChatMessage message,
QBEntityCallback callback) |
void |
removeIsTypingListener(QBChatDialogTypingListener listener)
Removes the 'is typing' listener.
|
void |
removeMessageListrener(QBChatDialogMessageListener listener)
Removes the incoming messages listener.
|
void |
removeMessageSentListener(QBChatDialogMessageSentListener listener)
Removes the 'message sent' listener.
|
void |
removeParticipantListener(QBChatDialogParticipantListener participantListener)
Removes a packet listener that was being notified of any new Presence packets sent to the group chat.
|
java.util.Collection<java.lang.Integer> |
requestOnlineUsers()
Returns a collection of online users IDs in the group chat.
|
void |
sendIsTypingNotification()
Sends 'is typing' notification.
|
void |
sendIsTypingNotification(QBEntityCallback<java.lang.Void> callback) |
void |
sendMessage(QBChatMessage message)
Sends a chat message to the chat.
|
void |
sendMessage(QBChatMessage message,
QBEntityCallback<java.lang.Void> callback) |
void |
sendMessage(java.lang.String text)
Sends a chat message to the chat.
|
void |
sendMessageWithoutJoin(QBChatMessage message)
Sends a chat message to the group chat without join it before
|
void |
sendMessageWithoutJoin(QBChatMessage message,
QBEntityCallback<java.lang.Void> callback) |
void |
sendPresence(java.util.Map<java.lang.String,java.lang.String> extendedParameters)
Sends the presence with custom parameters to the group chat.
|
void |
sendStopTypingNotification()
Sends 'stop typing' notification.
|
void |
sendStopTypingNotification(QBEntityCallback<java.lang.Void> callback) |
void |
setCustomData(QBDialogCustomData customData)
Sets the custom data.
|
void |
setDialogId(java.lang.String dialogId)
Sets the dialog's ID
|
void |
setLastMessage(java.lang.String lastMessage)
Sets the last sent message
|
void |
setLastMessageDateSent(long lastMessageDateSent)
Sets the last message date sent
|
void |
setLastMessageUserId(java.lang.Integer lastMessageUserId)
Sets the last sent message user ID
|
void |
setName(java.lang.String name)
Sets the name
|
void |
setOccupantsIds(java.util.List<java.lang.Integer> occupantsIds)
Sets the occupants IDs
|
void |
setPhoto(java.lang.String photo)
Sets the photo.
|
void |
setRoomJid(java.lang.String roomJid)
Sets the XMPP room JID.
|
void |
setType(QBDialogType type)
Sets the type
|
void |
setUnreadMessageCount(java.lang.Integer unreadMessageCount)
Sets the unread message count in this dialog
|
void |
setUserId(java.lang.Integer userId)
Sets the creator's ID of a dialog
|
java.lang.String |
toString() |
copyFieldsTo, getCreatedAt, getFCreatedAt, getFUpdatedAt, getId, getUpdatedAt, setCreatedAt, setId, setUpdatedAtpublic QBChatDialog()
public QBChatDialog(java.lang.String id)
id - ID of a dialogpublic java.lang.String getDialogId()
public void setDialogId(java.lang.String dialogId)
dialogId - the ID to setpublic java.lang.String getName()
public void setName(java.lang.String name)
name - The name to setpublic QBDialogType getType()
QBDialogTypepublic void setType(QBDialogType type)
type - The type to setQBDialogTypepublic java.lang.Integer getUserId()
public void setUserId(java.lang.Integer userId)
userId - The creator's ID to setpublic java.util.List<java.lang.Integer> getOccupants()
public void setOccupantsIds(java.util.List<java.lang.Integer> occupantsIds)
occupantsIds - An array of occupants IDs to setpublic java.lang.String getLastMessage()
public void setLastMessage(java.lang.String lastMessage)
lastMessage - The last sent messagepublic java.lang.Integer getLastMessageUserId()
public void setLastMessageUserId(java.lang.Integer lastMessageUserId)
lastMessageUserId - The last sent message user IDpublic long getLastMessageDateSent()
public void setLastMessageDateSent(long lastMessageDateSent)
lastMessageDateSent - The last message date sent to setpublic java.lang.Integer getUnreadMessageCount()
public void setUnreadMessageCount(java.lang.Integer unreadMessageCount)
unreadMessageCount - The unread message count to setpublic java.lang.String getRoomJid()
public void setRoomJid(java.lang.String roomJid)
roomJid - The XMPP room JID.public java.lang.String getPhoto()
public void setPhoto(java.lang.String photo)
photo - The photo to setpublic QBDialogCustomData getCustomData()
public void setCustomData(QBDialogCustomData customData)
customData - The data object to setpublic java.lang.Integer getRecipientId()
public void initForChat(QBChatService chatService)
chatService - Instance of QBChatService for initializing chat functions.public void initForChat(java.lang.String dialogId,
QBDialogType type,
QBChatService chatService)
dialogId - The current dialog's Id. Can't be empty of null.type - The type of current dialog. Can't be null.chatService - Instance of QBChatService for initializing chat functions.java.lang.IllegalArgumentExceptionpublic void sendMessage(java.lang.String text)
throws SmackException.NotConnectedException
text - The text of the message to send.SmackException.NotConnectedExceptionpublic void sendMessage(QBChatMessage message) throws SmackException.NotConnectedException
message - The message to send.SmackException.NotConnectedExceptionpublic void sendMessage(QBChatMessage message, QBEntityCallback<java.lang.Void> callback)
public void addMessageListener(QBChatDialogMessageListener listener)
listener - The listener to set.QBChatDialogMessageListenerpublic void removeMessageListrener(QBChatDialogMessageListener listener)
listener - The listener to remove.QBChatDialogMessageListenerpublic java.util.Collection<QBChatDialogMessageListener> getMessageListeners()
QBChatDialogMessageListenerpublic void sendIsTypingNotification()
throws XMPPException,
SmackException.NotConnectedException
SmackException.NotConnectedExceptionXMPPExceptionpublic void sendIsTypingNotification(QBEntityCallback<java.lang.Void> callback)
public void sendStopTypingNotification()
throws XMPPException,
SmackException.NotConnectedException
XMPPExceptionSmackException.NotConnectedExceptionpublic void sendStopTypingNotification(QBEntityCallback<java.lang.Void> callback)
public void addIsTypingListener(QBChatDialogTypingListener listener)
listener - The listener to set.QBChatDialogTypingListenerpublic void removeIsTypingListener(QBChatDialogTypingListener listener)
listener - The listener to remove.QBChatDialogTypingListenerpublic java.util.Collection<QBChatDialogTypingListener> getIsTypingListeners()
QBChatDialogTypingListenerpublic void addMessageSentListener(QBChatDialogMessageSentListener listener)
listener - The listener to set.QBChatService.setUseStreamManagement(boolean),
QBChatDialogMessageSentListenerpublic void removeMessageSentListener(QBChatDialogMessageSentListener listener)
listener - The listener to remove.QBChatService.setUseStreamManagement(boolean),
QBChatDialogMessageSentListenerpublic java.util.Collection<QBChatDialogMessageSentListener> getMessageSentListeners()
QBChatService.setUseStreamManagement(boolean),
QBChatDialogMessageSentListenerpublic void readMessage(QBChatMessage message) throws XMPPException, SmackException.NotConnectedException
message - The origin messageXMPPExceptionSmackException.NotConnectedExceptionpublic void readMessage(QBChatMessage message, QBEntityCallback callback)
public void deliverMessage(QBChatMessage message) throws XMPPException, SmackException.NotConnectedException
message - The origin messageXMPPExceptionSmackException.NotConnectedExceptionpublic void deliverMessage(QBChatMessage message, QBEntityCallback callback)
public boolean isPrivate()
QBDialogType.PRIVATE or false otherwise.QBDialogTypepublic boolean isJoined()
public void join(DiscussionHistory discussionHistory,
QBEntityCallback callback)
discussionHistory - history config which controls the number of characters or messages to receive
when entering a room. The room will decide the amount of history to return if you don't
specify a DiscussionHistory while joining a room.callback - A generic object for callback, must implement QBEntityCallback interface.public void join(DiscussionHistory discussionHistory)
throws XMPPException,
SmackException
discussionHistory - history config which controls the number of characters or messages to receive
when entering a room. The room will decide the amount of history to return if you don't
specify a DiscussionHistory while joining a room.XMPPException.XMPPErrorExceptionSmackExceptionXMPPExceptionpublic void leave()
throws XMPPException,
SmackException.NotConnectedException
XMPPExceptionSmackException.NotConnectedExceptionpublic void sendMessageWithoutJoin(QBChatMessage message) throws SmackException.NotConnectedException
message - The message to send.SmackException.NotConnectedExceptionpublic void sendMessageWithoutJoin(QBChatMessage message, QBEntityCallback<java.lang.Void> callback)
public void addParticipantListener(QBChatDialogParticipantListener participantListener)
participantListener - A listener that will be notified of any presence packets sent to the group chat.QBChatDialogParticipantListenerpublic void removeParticipantListener(QBChatDialogParticipantListener participantListener)
participantListener - - A QBChatDialogParticipantListener instanceQBChatDialogParticipantListenerpublic java.util.Collection<QBChatDialogParticipantListener> getParticipantListeners()
QBChatDialogParticipantListener@Deprecated
public java.util.Collection<java.lang.Integer> getOnlineUsers()
throws XMPPException,
SmackException.NotConnectedException
requestOnlineUsers()XMPPException.XMPPErrorException - if you don't have enough privileges to get this information.XMPPExceptionSmackException.NotConnectedExceptionpublic java.util.Collection<java.lang.Integer> requestOnlineUsers()
throws XMPPException.XMPPErrorException,
SmackException.NotConnectedException,
SmackException.NoResponseException
XMPPException.XMPPErrorException - if the operation failed for some reason.SmackException.NotConnectedException - if current user not connected to the chat.SmackException.NoResponseException - if didn't get response for a specified reply timeout.public void sendPresence(java.util.Map<java.lang.String,java.lang.String> extendedParameters)
throws XMPPException,
SmackException.NotConnectedException,
java.lang.IllegalStateException
extendedParameters - The map of parameters.XMPPExceptionSmackException.NotConnectedExceptionjava.lang.IllegalStateException