mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-22 12:02:05 +01:00
Add support for MUC roomnick rewrite
SMACK-646
This commit is contained in:
parent
5af4f1a5d1
commit
fcc62ad131
4 changed files with 86 additions and 4 deletions
|
@ -60,6 +60,7 @@ import org.jivesoftware.smackx.iqregister.packet.Registration;
|
||||||
import org.jivesoftware.smackx.muc.MultiUserChatException.MucAlreadyJoinedException;
|
import org.jivesoftware.smackx.muc.MultiUserChatException.MucAlreadyJoinedException;
|
||||||
import org.jivesoftware.smackx.muc.MultiUserChatException.MucNotJoinedException;
|
import org.jivesoftware.smackx.muc.MultiUserChatException.MucNotJoinedException;
|
||||||
import org.jivesoftware.smackx.muc.MultiUserChatException.MissingMucCreationAcknowledgeException;
|
import org.jivesoftware.smackx.muc.MultiUserChatException.MissingMucCreationAcknowledgeException;
|
||||||
|
import org.jivesoftware.smackx.muc.filter.MUCUserStatusCodeFilter;
|
||||||
import org.jivesoftware.smackx.muc.packet.Destroy;
|
import org.jivesoftware.smackx.muc.packet.Destroy;
|
||||||
import org.jivesoftware.smackx.muc.packet.MUCAdmin;
|
import org.jivesoftware.smackx.muc.packet.MUCAdmin;
|
||||||
import org.jivesoftware.smackx.muc.packet.MUCInitialPresence;
|
import org.jivesoftware.smackx.muc.packet.MUCInitialPresence;
|
||||||
|
@ -308,9 +309,6 @@ public class MultiUserChat {
|
||||||
}
|
}
|
||||||
joinPresence.addExtension(mucInitialPresence);
|
joinPresence.addExtension(mucInitialPresence);
|
||||||
|
|
||||||
// Wait for a presence packet back from the server.
|
|
||||||
StanzaFilter responseFilter = new AndFilter(FromMatchesFilter.createFull(jid), new StanzaTypeFilter(Presence.class));
|
|
||||||
|
|
||||||
// Setup the messageListeners and presenceListeners *before* the join presence is send.
|
// Setup the messageListeners and presenceListeners *before* the join presence is send.
|
||||||
connection.addSyncStanzaListener(messageListener, fromRoomGroupchatFilter);
|
connection.addSyncStanzaListener(messageListener, fromRoomGroupchatFilter);
|
||||||
connection.addSyncStanzaListener(presenceListener, new AndFilter(fromRoomFilter,
|
connection.addSyncStanzaListener(presenceListener, new AndFilter(fromRoomFilter,
|
||||||
|
@ -323,6 +321,10 @@ public class MultiUserChat {
|
||||||
StanzaTypeFilter.PRESENCE));
|
StanzaTypeFilter.PRESENCE));
|
||||||
messageCollector = connection.createPacketCollector(fromRoomGroupchatFilter);
|
messageCollector = connection.createPacketCollector(fromRoomGroupchatFilter);
|
||||||
|
|
||||||
|
// Wait for a presence packet back from the server.
|
||||||
|
// Use a bare JID filter, since the room may rewrite the nickname.
|
||||||
|
StanzaFilter responseFilter = new AndFilter(FromMatchesFilter.createBare(jid), new StanzaTypeFilter(
|
||||||
|
Presence.class), MUCUserStatusCodeFilter.STATUS_110_PRESENCE_TO_SELF);
|
||||||
Presence presence;
|
Presence presence;
|
||||||
try {
|
try {
|
||||||
presence = connection.createPacketCollectorAndSend(responseFilter, joinPresence).nextResultOrThrow(timeout);
|
presence = connection.createPacketCollectorAndSend(responseFilter, joinPresence).nextResultOrThrow(timeout);
|
||||||
|
@ -333,7 +335,9 @@ public class MultiUserChat {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.nickname = nickname;
|
// This presence must be send from a full JID. We use the resourcepart of this JID as nick, since the room may
|
||||||
|
// performed roomnick rewriting
|
||||||
|
this.nickname = presence.getFrom().asFullJidIfPossible().getResourcepart();
|
||||||
joined = true;
|
joined = true;
|
||||||
|
|
||||||
// Update the list of joined rooms
|
// Update the list of joined rooms
|
||||||
|
|
|
@ -0,0 +1,51 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright 2015 Florian Schmaus
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jivesoftware.smackx.muc.filter;
|
||||||
|
|
||||||
|
import org.jivesoftware.smack.filter.StanzaFilter;
|
||||||
|
import org.jivesoftware.smack.packet.Stanza;
|
||||||
|
import org.jivesoftware.smackx.muc.packet.MUCUser;
|
||||||
|
|
||||||
|
public class MUCUserStatusCodeFilter implements StanzaFilter {
|
||||||
|
|
||||||
|
public static final MUCUserStatusCodeFilter STATUS_110_PRESENCE_TO_SELF = new MUCUserStatusCodeFilter(
|
||||||
|
MUCUser.Status.PRESENCE_TO_SELF_110);
|
||||||
|
|
||||||
|
private final MUCUser.Status status;
|
||||||
|
|
||||||
|
public MUCUserStatusCodeFilter(MUCUser.Status status) {
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MUCUserStatusCodeFilter(int statusCode) {
|
||||||
|
this(MUCUser.Status.create(statusCode));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean accept(Stanza stanza) {
|
||||||
|
MUCUser mucUser = MUCUser.from(stanza);
|
||||||
|
if (mucUser == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return mucUser.getStatus().contains(status);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return getClass().getSimpleName() + ": status=" + status;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright 2015 Florian Schmaus
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stanza filters for Multi-User Chat.
|
||||||
|
*/
|
||||||
|
package org.jivesoftware.smackx.muc.filter;
|
|
@ -418,6 +418,7 @@ public class MUCUser implements ExtensionElement {
|
||||||
|
|
||||||
private static final Map<Integer, Status> statusMap = new HashMap<Integer, Status>(8);
|
private static final Map<Integer, Status> statusMap = new HashMap<Integer, Status>(8);
|
||||||
|
|
||||||
|
public static final Status PRESENCE_TO_SELF_110 = Status.create(110);
|
||||||
public static final Status ROOM_CREATED_201 = Status.create(201);
|
public static final Status ROOM_CREATED_201 = Status.create(201);
|
||||||
public static final Status BANNED_301 = Status.create(301);
|
public static final Status BANNED_301 = Status.create(301);
|
||||||
public static final Status NEW_NICKNAME_303 = Status.create(303);
|
public static final Status NEW_NICKNAME_303 = Status.create(303);
|
||||||
|
@ -467,6 +468,11 @@ public class MUCUser implements ExtensionElement {
|
||||||
return xml;
|
return xml;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return code.toString();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object other) {
|
public boolean equals(Object other) {
|
||||||
if (other == null) {
|
if (other == null) {
|
||||||
|
|
Loading…
Reference in a new issue