1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-25 21:42:07 +01:00

muc: remove 'joined' boolean from MultiUserChat, use myRoomJid instead

If myRoomJid is set, we are joined.
This commit is contained in:
Florian Schmaus 2020-04-16 21:44:55 +02:00
parent 26ab832452
commit 20aaef2628

View file

@ -149,7 +149,6 @@ public class MultiUserChat {
private String subject; private String subject;
private EntityFullJid myRoomJid; private EntityFullJid myRoomJid;
private boolean joined = false;
private StanzaCollector messageCollector; private StanzaCollector messageCollector;
MultiUserChat(XMPPConnection connection, EntityBareJid room, MultiUserChatManager multiUserChatManager) { MultiUserChat(XMPPConnection connection, EntityBareJid room, MultiUserChatManager multiUserChatManager) {
@ -386,8 +385,6 @@ public class MultiUserChat {
Resourcepart receivedNickname = presence.getFrom().getResourceOrThrow(); Resourcepart receivedNickname = presence.getFrom().getResourceOrThrow();
setNickname(receivedNickname); setNickname(receivedNickname);
joined = true;
// Update the list of joined rooms // Update the list of joined rooms
multiUserChatManager.addJoinedRoom(room); multiUserChatManager.addJoinedRoom(room);
return presence; return presence;
@ -439,7 +436,7 @@ public class MultiUserChat {
public synchronized MucCreateConfigFormHandle create(Resourcepart nickname) throws NoResponseException, public synchronized MucCreateConfigFormHandle create(Resourcepart nickname) throws NoResponseException,
XMPPErrorException, InterruptedException, MucAlreadyJoinedException, XMPPErrorException, InterruptedException, MucAlreadyJoinedException,
NotConnectedException, MissingMucCreationAcknowledgeException, NotAMucServiceException { NotConnectedException, MissingMucCreationAcknowledgeException, NotAMucServiceException {
if (joined) { if (isJoined()) {
throw new MucAlreadyJoinedException(); throw new MucAlreadyJoinedException();
} }
@ -494,7 +491,7 @@ public class MultiUserChat {
*/ */
public synchronized MucCreateConfigFormHandle createOrJoin(MucEnterConfiguration mucEnterConfiguration) public synchronized MucCreateConfigFormHandle createOrJoin(MucEnterConfiguration mucEnterConfiguration)
throws NoResponseException, XMPPErrorException, InterruptedException, MucAlreadyJoinedException, NotConnectedException, NotAMucServiceException { throws NoResponseException, XMPPErrorException, InterruptedException, MucAlreadyJoinedException, NotConnectedException, NotAMucServiceException {
if (joined) { if (isJoined()) {
throw new MucAlreadyJoinedException(); throw new MucAlreadyJoinedException();
} }
@ -665,7 +662,7 @@ public class MultiUserChat {
throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException, NotAMucServiceException { throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException, NotAMucServiceException {
// If we've already joined the room, leave it before joining under a new // If we've already joined the room, leave it before joining under a new
// nickname. // nickname.
if (joined) { if (isJoined()) {
try { try {
leaveSync(); leaveSync();
} }
@ -683,7 +680,7 @@ public class MultiUserChat {
* @return true if currently in the multi user chat room. * @return true if currently in the multi user chat room.
*/ */
public boolean isJoined() { public boolean isJoined() {
return joined; return myRoomJid != null;
} }
/** /**
@ -1138,7 +1135,7 @@ public class MultiUserChat {
Objects.requireNonNull(nickname, "Nickname must not be null or blank."); Objects.requireNonNull(nickname, "Nickname must not be null or blank.");
// Check that we already have joined the room before attempting to change the // Check that we already have joined the room before attempting to change the
// nickname. // nickname.
if (!joined) { if (!isJoined()) {
throw new MucNotJoinedException(this); throw new MucNotJoinedException(this);
} }
final EntityFullJid jid = JidCreate.entityFullFrom(room, nickname); final EntityFullJid jid = JidCreate.entityFullFrom(room, nickname);
@ -1181,11 +1178,6 @@ public class MultiUserChat {
throw new MucNotJoinedException(this); throw new MucNotJoinedException(this);
} }
// Check that we already have joined the room before attempting to change the
// availability status.
if (!joined) {
throw new MucNotJoinedException(this);
}
// We change the availability status by sending a presence packet to the room with the // We change the availability status by sending a presence packet to the room with the
// new presence status and mode // new presence status and mode
Presence joinPresence = connection.getStanzaFactory().buildPresenceStanza() Presence joinPresence = connection.getStanzaFactory().buildPresenceStanza()
@ -2122,7 +2114,6 @@ public class MultiUserChat {
// to call leave() in order to resync the state. And leave() requires the nickname to send the unsubscribe // to call leave() in order to resync the state. And leave() requires the nickname to send the unsubscribe
// presence. // presence.
occupantsMap.clear(); occupantsMap.clear();
joined = false;
myRoomJid = null; myRoomJid = null;
// Update the list of joined rooms // Update the list of joined rooms
multiUserChatManager.removeJoinedRoom(room); multiUserChatManager.removeJoinedRoom(room);