From b746e5caee6b6af9677cfd6bc25b3f119aa2c722 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Mon, 28 Sep 2015 13:05:06 +0200 Subject: [PATCH] Add support for MUC Item Actor 'nick' Fixes SMACK-691. --- .../smackx/muc/packet/MUCItem.java | 27 ++++++++++++++----- .../smackx/muc/provider/MUCParserUtils.java | 10 ++++++- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/packet/MUCItem.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/packet/MUCItem.java index 830c2cb85..9cbc6cd3a 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/packet/MUCItem.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/packet/MUCItem.java @@ -35,32 +35,33 @@ public class MUCItem implements NamedElement { private final MUCAffiliation affiliation; private final MUCRole role; private final Jid actor; + private final Resourcepart actorNick; private final String reason; private final Jid jid; private final Resourcepart nick; public MUCItem(MUCAffiliation affiliation) { - this(affiliation, null, null, null, null, null); + this(affiliation, null, null, null, null, null, null); } public MUCItem(MUCRole role) { - this(null, role, null, null, null, null); + this(null, role, null, null, null, null, null); } public MUCItem(MUCRole role, Resourcepart nick) { - this(null, role, null, null, null, nick); + this(null, role, null, null, null, nick, null); } public MUCItem(MUCAffiliation affiliation, Jid jid, String reason) { - this(affiliation, null, null, reason, jid, null); + this(affiliation, null, null, reason, jid, null, null); } public MUCItem(MUCAffiliation affiliation, Jid jid) { - this(affiliation, null, null, null, jid, null); + this(affiliation, null, null, null, jid, null, null); } public MUCItem(MUCRole role, Resourcepart nick, String reason) { - this(null, role, null, reason, null, nick); + this(null, role, null, reason, null, nick, null); } /** @@ -72,15 +73,17 @@ public class MUCItem implements NamedElement { * @param reason * @param jid * @param nick + * @param actorNick */ public MUCItem(MUCAffiliation affiliation, MUCRole role, Jid actor, - String reason, Jid jid, Resourcepart nick) { + String reason, Jid jid, Resourcepart nick, Resourcepart actorNick) { this.affiliation = affiliation; this.role = role; this.actor = actor; this.reason = reason; this.jid = jid; this.nick = nick; + this.actorNick = actorNick; } /** @@ -92,6 +95,16 @@ public class MUCItem implements NamedElement { return actor; } + /** + * Get the nickname of the actor. + * + * @return the nickname of the actor. + * @since 4.2 + */ + public Resourcepart getActorNick() { + return actorNick; + } + /** * Returns the reason for the item child. The reason is optional and could be used to explain * the reason why a user (occupant) was kicked or banned. diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/provider/MUCParserUtils.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/provider/MUCParserUtils.java index 25c0be677..67f4dd77d 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/provider/MUCParserUtils.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/provider/MUCParserUtils.java @@ -37,6 +37,7 @@ public class MUCParserUtils { MUCRole role = MUCRole.fromString(parser.getAttributeValue("", "role")); Jid jid = ParserUtils.getJidAttribute(parser); Jid actor = null; + Resourcepart actorNick = null; String reason = null; outerloop: while (true) { int eventType = parser.next(); @@ -46,6 +47,13 @@ public class MUCParserUtils { switch (name) { case "actor": actor = ParserUtils.getJidAttribute(parser); + // TODO change to + // actorNick = Resourcepart.from(parser.getAttributeValue("", "nick")); + // once a newer version of JXMPP is used that supports from(null). + String actorNickString = parser.getAttributeValue("", "nick"); + if (actorNickString != null) { + actorNick = Resourcepart.from(actorNickString); + } break; case "reason": reason = parser.nextText(); @@ -59,7 +67,7 @@ public class MUCParserUtils { break; } } - return new MUCItem(affiliation, role, actor, reason, jid, nick); + return new MUCItem(affiliation, role, actor, reason, jid, nick, actorNick); } public static Destroy parseDestroy(XmlPullParser parser) throws XmlPullParserException, IOException {