summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Parser/PayloadParsers/MUCUserPayloadParser.cpp')
-rw-r--r--Swiften/Parser/PayloadParsers/MUCUserPayloadParser.cpp87
1 files changed, 12 insertions, 75 deletions
diff --git a/Swiften/Parser/PayloadParsers/MUCUserPayloadParser.cpp b/Swiften/Parser/PayloadParsers/MUCUserPayloadParser.cpp
index bd81b88..71ae571 100644
--- a/Swiften/Parser/PayloadParsers/MUCUserPayloadParser.cpp
+++ b/Swiften/Parser/PayloadParsers/MUCUserPayloadParser.cpp
@@ -8,87 +8,24 @@
#include <boost/lexical_cast.hpp>
+#include <Swiften/Base/foreach.h>
#include <Swiften/Elements/MUCOccupant.h>
-#include <cassert>
-#include <iostream>
-
namespace Swift {
-MUCUserPayloadParser::MUCUserPayloadParser() : level(TopLevel) {
-}
-
-void MUCUserPayloadParser::handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) {
- if (level == ItemLevel) {
- if (element == "item") {
- MUCUserPayload::Item item;
- std::string affiliation = attributes.getAttribute("affiliation");
- std::string role = attributes.getAttribute("role");
- std::string nick = attributes.getAttribute("nick");
- std::string jid = attributes.getAttribute("jid");
- item.affiliation = parseAffiliation(affiliation);
- item.role = parseRole(role);
- if (!jid.empty()) {
- item.realJID = JID(jid);
- }
- if (!nick.empty()) {
- item.nick = nick;
- }
- getPayloadInternal()->addItem(item);
- } else if (element == "status") {
- MUCUserPayload::StatusCode status;
- try {
- status.code = boost::lexical_cast<int>(attributes.getAttribute("code").c_str());
- getPayloadInternal()->addStatusCode(status);
- } catch (boost::bad_lexical_cast&) {
- }
+void MUCUserPayloadParser::handleTree(ParserElement::ref root) {
+ foreach (ParserElement::ref itemElement, root->getChildren("item", "http://jabber.org/protocol/muc#user")) {
+ MUCItem item = MUCItemParser::itemFromTree(itemElement);
+ getPayloadInternal()->addItem(item);
+ }
+ foreach (ParserElement::ref statusElement, root->getChildren("item", "http://jabber.org/protocol/muc#user")) {
+ MUCUserPayload::StatusCode status;
+ try {
+ status.code = boost::lexical_cast<int>(statusElement->getAttributes().getAttribute("code").c_str());
+ getPayloadInternal()->addStatusCode(status);
+ } catch (boost::bad_lexical_cast&) {
}
}
- ++level;
-}
-
-MUCOccupant::Role MUCUserPayloadParser::parseRole(const std::string& roleString) const {
- if (roleString == "moderator") {
- return MUCOccupant::Moderator;
- }
- if (roleString == "participant") {
- return MUCOccupant::Participant;
- }
- if (roleString == "visitor") {
- return MUCOccupant::Visitor;
- }
- if (roleString == "none") {
- return MUCOccupant::NoRole;
- }
- return MUCOccupant::NoRole;
-}
-
-MUCOccupant::Affiliation MUCUserPayloadParser::parseAffiliation(const std::string& affiliationString) const {
- if (affiliationString == "owner") {
- return MUCOccupant::Owner;
- }
- if (affiliationString == "admin") {
- return MUCOccupant::Admin;
- }
- if (affiliationString == "member") {
- return MUCOccupant::Member;
- }
- if (affiliationString == "outcast") {
- return MUCOccupant::Outcast;
- }
- if (affiliationString == "none") {
- return MUCOccupant::NoAffiliation;
- }
- return MUCOccupant::NoAffiliation;
-}
-
-
-void MUCUserPayloadParser::handleEndElement(const std::string& /*element*/, const std::string&) {
- --level;
-}
-
-void MUCUserPayloadParser::handleCharacterData(const std::string& /*data*/) {
-
}
}