public final class Room extends Object
Modifier and Type | Method and Description |
---|---|
<T> void |
addEventListener(EventType<T> event,
Consumer<T> listener)
Adds a listener for the given event.
|
CompletionStage<Void> |
delete(long messageId)
Deletes asynchronously the message having the given id.
|
CompletionStage<Long> |
edit(long messageId,
String message)
Edits asynchronously the message having the given id with the new given content.
|
List<User> |
getCurrentUsers()
Returns the list of all the current users of this room.
|
ChatHost |
getHost()
Returns the host of this room.
|
Message |
getMessage(long messageId)
Retrieves the
Message having the given id. |
List<User> |
getPingableUsers()
Returns the list of all the pingable users of this room.
|
int |
getRoomId()
Returns the id of this room.
|
RoomThumbs |
getThumbs()
Returns the thumbs for this chat room.
|
User |
getUser(long userId)
Retrieves the
User having the given id. |
boolean |
isEditable(long messageId)
Returns whether this message can be edited as of now.
|
void |
leave()
Causes the current logged user to leave the room.
|
CompletionStage<Long> |
replyTo(long messageId,
String message)
Sends a reply message to the given message id.
|
CompletionStage<Long> |
send(String message)
Sends the given message asynchronously.
|
CompletionStage<Void> |
togglePin(long messageId)
Pins or unpins the given message.
|
CompletionStage<Void> |
toggleStar(long messageId)
Stars or unstars the given message.
|
CompletionStage<String> |
uploadImage(Path path)
Uploads the given file and returns the HTTP URL to the file hosted on imgur.
|
CompletionStage<String> |
uploadImage(String fileName,
InputStream inputStream)
Uploads the given file and returns the HTTP URL to the file hosted on imgur.
|
public <T> void addEventListener(EventType<T> event, Consumer<T> listener)
EventType
class.
All listeners bound to a specific event will be called when the corresponding event is raised.
T
- type of the event.event
- Event to listen to.listener
- Listener to add to this event.public CompletionStage<Long> send(String message)
message
- Content of the message to send.public CompletionStage<String> uploadImage(Path path)
path
- Path of the file to upload.public CompletionStage<String> uploadImage(String fileName, InputStream inputStream)
This method is asynchronous, thus, if the given input stream needs to be closed, make sure to properly close it in a
CompletionStage.whenComplete(java.util.function.BiConsumer)
callback on the returned stage.
fileName
- Name of the file to upload.inputStream
- Data.public CompletionStage<Long> replyTo(long messageId, String message)
messageId
- Id of the message to reply to.message
- Message consisting of the reply.public CompletionStage<Long> edit(long messageId, String message)
messageId
- Id of the message to edit.message
- New content of the message.public boolean isEditable(long messageId)
edit(long, String)
will be successful, because the time window allowed for the edit could have been passed by then. However, if a call to
edit(long, String)
is made right after this method returns true
then it is very likely to succeed
(i.e. not fail because the edit window has elapsed; it can still fail for other reasons).
A message can be edited if it has been posted less than seconds ago.
messageId
- Id of the message.true
if the given message can be edited right now, false
otherwise.public CompletionStage<Void> delete(long messageId)
messageId
- Id of the message to delete.public CompletionStage<Void> toggleStar(long messageId)
messageId
- Id of the message to star / unstar.public CompletionStage<Void> togglePin(long messageId)
messageId
- Id of the message to pin / unpin.public void leave()
Calling this method multiple times has no effect.
public Message getMessage(long messageId)
Message
having the given id.messageId
- Id of the message to fetch.public List<User> getPingableUsers()
This consists of all the users that have been in the room at least once for the past 14 days.
public List<User> getCurrentUsers()
This consists of all the users that are present, at the moment of this call, in the room.
public User getUser(long userId)
User
having the given id.userId
- Id of the user to fetch.public int getRoomId()
public RoomThumbs getThumbs()
Refer to RoomThumbs
for a description of all the fields.
public ChatHost getHost()