Skip to content

Commit

Permalink
#6: + get cookies per room or host
Browse files Browse the repository at this point in the history
  • Loading branch information
FelixSFD committed Jul 25, 2018
1 parent 4fb5705 commit 6fe1bcf
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
12 changes: 12 additions & 0 deletions src/main/java/org/sobotics/chatexchange/chat/ChatHost.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,17 @@ public String getName() {
public String getBaseUrl() {
return baseUrl;
}

/**
* Compares the host to another object
* @param otherHost other object
* @return true, if the name is the same
*/
public boolean equals(ChatHost otherHost) {
if (otherHost == null)
return false;

return this.name.equals(otherHost.name);
}

}
8 changes: 8 additions & 0 deletions src/main/java/org/sobotics/chatexchange/chat/Room.java
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,14 @@ public RoomThumbs getThumbs() {
public ChatHost getHost() {
return host;
}

/**
* Returns the cookies used to post in this room
* @return cookies as Map
*/
public Map<String, String> getCookies() {
return this.cookies;
}

void close() {
executor.shutdown();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,12 +247,22 @@ public void setAutoCreateAccount(boolean autoCreateAccount) {
this.autoCreateAccount = autoCreateAccount;
}


/**
* Returns the cookies the library uses
* @return Cookies
* Returns the cookies for the first room with the given host
* @param host {@link ChatHost} to search for
* @return null, if no room with the given {@link ChatHost} was found
*/
public Map<String, String> getCookies() {
return this.cookies;
public Map<String, String> getCookies(ChatHost host) {
for (Room room : this.rooms) {
ChatHost roomHost = room.getHost();

if (host.equals(roomHost)) {
return room.getCookies();
}
}

return null;
}

/**
Expand Down

0 comments on commit 6fe1bcf

Please sign in to comment.