Libtransport: Fix #85 - Add iconhash field to Participant type. When backend uses that field, Frontends will ask for VCards with name set to 'room/user' format.
This commit is contained in:
parent
3566e833e3
commit
5f04f45903
7 changed files with 108 additions and 7 deletions
|
@ -81,7 +81,7 @@ class Conversation {
|
|||
/// \param status Current status of this participant.
|
||||
/// \param statusMessage Current status message of this participant.
|
||||
/// \param newname If participant was renamed, this variable contains his new name.
|
||||
void handleParticipantChanged(const std::string &nickname, ParticipantFlag flag, int status = Swift::StatusShow::None, const std::string &statusMessage = "", const std::string &newname = "");
|
||||
void handleParticipantChanged(const std::string &nickname, ParticipantFlag flag, int status = Swift::StatusShow::None, const std::string &statusMessage = "", const std::string &newname = "", const std::string &iconhash = "");
|
||||
|
||||
/// Sets XMPP user nickname in MUC rooms.
|
||||
|
||||
|
@ -154,7 +154,7 @@ class Conversation {
|
|||
void setMUCEscaping(bool mucEscaping);
|
||||
|
||||
private:
|
||||
Swift::Presence::ref generatePresence(const std::string &nick, int flag, int status, const std::string &statusMessage, const std::string &newname = "");
|
||||
Swift::Presence::ref generatePresence(const std::string &nick, int flag, int status, const std::string &statusMessage, const std::string &newname = "", const std::string &iconhash = "");
|
||||
void cacheMessage(boost::shared_ptr<Swift::Message> &message);
|
||||
|
||||
private:
|
||||
|
|
|
@ -110,6 +110,7 @@ message Participant {
|
|||
required StatusType status = 5;
|
||||
optional string statusMessage = 6;
|
||||
optional string newname = 7;
|
||||
optional string iconHash = 8;
|
||||
}
|
||||
|
||||
message VCard {
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
#include "Swiften/Elements/MUCUserPayload.h"
|
||||
#include "Swiften/Elements/Delay.h"
|
||||
#include "Swiften/Elements/MUCPayload.h"
|
||||
#include "Swiften/Elements/VCardUpdate.h"
|
||||
|
||||
namespace Transport {
|
||||
|
||||
|
@ -252,7 +253,7 @@ void Conversation::sendCachedMessages(const Swift::JID &to) {
|
|||
m_cachedMessages.clear();
|
||||
}
|
||||
|
||||
Swift::Presence::ref Conversation::generatePresence(const std::string &nick, int flag, int status, const std::string &statusMessage, const std::string &newname) {
|
||||
Swift::Presence::ref Conversation::generatePresence(const std::string &nick, int flag, int status, const std::string &statusMessage, const std::string &newname, const std::string &iconhash) {
|
||||
std::string nickname = nick;
|
||||
Swift::Presence::ref presence = Swift::Presence::create();
|
||||
std::string legacyName = m_legacyName;
|
||||
|
@ -330,6 +331,10 @@ Swift::Presence::ref Conversation::generatePresence(const std::string &nick, int
|
|||
p->addStatusCode(c);
|
||||
presence->setType(Swift::Presence::Unavailable);
|
||||
}
|
||||
|
||||
if (!iconhash.empty()) {
|
||||
presence->addPayload(boost::shared_ptr<Swift::Payload>(new Swift::VCardUpdate (iconhash)));
|
||||
}
|
||||
|
||||
p->addItem(item);
|
||||
presence->addPayload(boost::shared_ptr<Swift::Payload>(p));
|
||||
|
@ -350,8 +355,8 @@ void Conversation::handleRawPresence(Swift::Presence::ref presence) {
|
|||
m_participants[presence->getFrom().getResource()] = presence;
|
||||
}
|
||||
|
||||
void Conversation::handleParticipantChanged(const std::string &nick, Conversation::ParticipantFlag flag, int status, const std::string &statusMessage, const std::string &newname) {
|
||||
Swift::Presence::ref presence = generatePresence(nick, flag, status, statusMessage, newname);
|
||||
void Conversation::handleParticipantChanged(const std::string &nick, Conversation::ParticipantFlag flag, int status, const std::string &statusMessage, const std::string &newname, const std::string &iconhash) {
|
||||
Swift::Presence::ref presence = generatePresence(nick, flag, status, statusMessage, newname, iconhash);
|
||||
|
||||
if (presence->getType() == Swift::Presence::Unavailable) {
|
||||
m_participants.erase(nick);
|
||||
|
@ -366,7 +371,7 @@ void Conversation::handleParticipantChanged(const std::string &nick, Conversatio
|
|||
m_conversationManager->getComponent()->getFrontend()->sendPresence(presence);
|
||||
}
|
||||
if (!newname.empty()) {
|
||||
handleParticipantChanged(newname, flag, status, statusMessage);
|
||||
handleParticipantChanged(newname, flag, status, statusMessage, "", iconhash);
|
||||
}
|
||||
|
||||
if (m_sentInitialPresence && m_subject) {
|
||||
|
|
|
@ -636,7 +636,7 @@ void NetworkPluginServer::handleParticipantChangedPayload(const std::string &dat
|
|||
return;
|
||||
}
|
||||
|
||||
conv->handleParticipantChanged(payload.nickname(), (Conversation::ParticipantFlag) payload.flag(), payload.status(), payload.statusmessage(), payload.newname());
|
||||
conv->handleParticipantChanged(payload.nickname(), (Conversation::ParticipantFlag) payload.flag(), payload.status(), payload.statusmessage(), payload.newname(), payload.iconhash());
|
||||
}
|
||||
|
||||
void NetworkPluginServer::handleRoomChangedPayload(const std::string &data) {
|
||||
|
|
|
@ -95,6 +95,10 @@ bool VCardResponder::handleGetRequest(const Swift::JID& from, const Swift::JID&
|
|||
}
|
||||
|
||||
name = Buddy::JIDToLegacyName(to_, user);
|
||||
// If the resource is not empty, it is probably VCard for room participant
|
||||
if (!to.getResource().empty()) {
|
||||
name += "/" + to.getResource();
|
||||
}
|
||||
|
||||
LOG4CXX_INFO(logger, from.toBare().toString() << ": Requested VCard of " << name);
|
||||
|
||||
|
|
63
tests/libtransport/VCardResponder.cpp
Normal file
63
tests/libtransport/VCardResponder.cpp
Normal file
|
@ -0,0 +1,63 @@
|
|||
#include <cppunit/TestFixture.h>
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
#include <Swiften/Swiften.h>
|
||||
#include <Swiften/EventLoop/DummyEventLoop.h>
|
||||
#include <Swiften/Server/Server.h>
|
||||
#include <Swiften/Network/DummyNetworkFactories.h>
|
||||
#include <Swiften/Network/DummyConnectionServer.h>
|
||||
#include "Swiften/Server/ServerStanzaChannel.h"
|
||||
#include "Swiften/Server/ServerFromClientSession.h"
|
||||
#include "Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h"
|
||||
#include "basictest.h"
|
||||
#include "vcardresponder.h"
|
||||
|
||||
using namespace Transport;
|
||||
|
||||
class VCardResponderTest : public CPPUNIT_NS :: TestFixture, public BasicTest {
|
||||
CPPUNIT_TEST_SUITE(VCardResponderTest);
|
||||
CPPUNIT_TEST(handleGetRequestMUC);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
public:
|
||||
std::string vcardName;
|
||||
unsigned int vcardId;
|
||||
|
||||
void setUp (void) {
|
||||
setMeUp();
|
||||
connectUser();
|
||||
received.clear();
|
||||
component->getFrontend()->onVCardRequired.connect(boost::bind(&VCardResponderTest::handleVCardRequired, this, _1, _2, _3));
|
||||
}
|
||||
|
||||
void tearDown (void) {
|
||||
tearMeDown();
|
||||
}
|
||||
|
||||
void handleVCardRequired(User *user, const std::string &name, unsigned int id) {
|
||||
vcardName = name;
|
||||
vcardId = id;
|
||||
}
|
||||
|
||||
void handleGetRequestMUC() {
|
||||
boost::shared_ptr<Swift::VCard> payload(new Swift::VCard());
|
||||
boost::shared_ptr<Swift::IQ> iq = Swift::IQ::createRequest(Swift::IQ::Get, Swift::JID("localhost"), "foobar", payload);
|
||||
iq->setFrom("user@localhost/me");
|
||||
iq->setTo("#room@localhost/user");
|
||||
injectIQ(iq);
|
||||
loop->processEvents();
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL(0, (int) received.size());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("#room/user"), vcardName);
|
||||
|
||||
userManager->sendVCard(vcardId, payload);
|
||||
loop->processEvents();
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL(1, (int) received.size());
|
||||
CPPUNIT_ASSERT_EQUAL(Swift::IQ::Result, dynamic_cast<Swift::IQ *>(getStanza(received[0]))->getType());
|
||||
CPPUNIT_ASSERT_EQUAL(Swift::IQ::Result, dynamic_cast<Swift::IQ *>(getStanza(received[0]))->getType());
|
||||
CPPUNIT_ASSERT(getStanza(received[0])->getPayload<Swift::VCard>());
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION (VCardResponderTest);
|
|
@ -5,6 +5,7 @@
|
|||
#include <Swiften/Server/Server.h>
|
||||
#include <Swiften/Network/DummyNetworkFactories.h>
|
||||
#include <Swiften/Network/DummyConnectionServer.h>
|
||||
#include <Swiften/Elements/VCardUpdate.h>
|
||||
#include "Swiften/Server/ServerStanzaChannel.h"
|
||||
#include "Swiften/Server/ServerFromClientSession.h"
|
||||
#include "Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h"
|
||||
|
@ -28,6 +29,7 @@ class ConversationManagerTest : public CPPUNIT_NS :: TestFixture, public BasicTe
|
|||
CPPUNIT_TEST(handleParticipantChangedEscaped);
|
||||
CPPUNIT_TEST(handleParticipantChangedEscaped2);
|
||||
CPPUNIT_TEST(handleParticipantChangedTwoResources);
|
||||
CPPUNIT_TEST(handleParticipantChangedIconHash);
|
||||
CPPUNIT_TEST(handlePMFromXMPP);
|
||||
CPPUNIT_TEST(handleGroupchatRemoved);
|
||||
CPPUNIT_TEST(handleNicknameConflict);
|
||||
|
@ -595,6 +597,32 @@ class ConversationManagerTest : public CPPUNIT_NS :: TestFixture, public BasicTe
|
|||
CPPUNIT_ASSERT_EQUAL(Swift::MUCOccupant::Participant, *getStanza(received[0])->getPayload<Swift::MUCUserPayload>()->getItems()[0].role);
|
||||
}
|
||||
|
||||
void handleParticipantChangedIconHash() {
|
||||
User *user = userManager->getUser("user@localhost");
|
||||
TestingConversation *conv = new TestingConversation(user->getConversationManager(), "19:70027094a9c84c518535a610766bed65@thread.skype", true);
|
||||
conv->setMUCEscaping(true);
|
||||
|
||||
conv->onMessageToSend.connect(boost::bind(&ConversationManagerTest::handleMessageReceived, this, _1, _2));
|
||||
conv->setNickname("nickname");
|
||||
conv->addJID("user@localhost/resource");
|
||||
|
||||
// normal presence
|
||||
conv->handleParticipantChanged("anotheruser", Conversation::PARTICIPANT_FLAG_NONE, Swift::StatusShow::Away, "my status message", "", "hash");
|
||||
loop->processEvents();
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL(1, (int) received.size());
|
||||
CPPUNIT_ASSERT(dynamic_cast<Swift::Presence *>(getStanza(received[0])));
|
||||
CPPUNIT_ASSERT_EQUAL(Swift::StatusShow::Away, dynamic_cast<Swift::Presence *>(getStanza(received[0]))->getShow());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("user@localhost/resource"), dynamic_cast<Swift::Presence *>(getStanza(received[0]))->getTo().toString());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("19\\3a70027094a9c84c518535a610766bed65\\40thread.skype@localhost/anotheruser"), dynamic_cast<Swift::Presence *>(getStanza(received[0]))->getFrom().toString());
|
||||
CPPUNIT_ASSERT(getStanza(received[0])->getPayload<Swift::MUCUserPayload>());
|
||||
CPPUNIT_ASSERT_EQUAL(Swift::MUCOccupant::Member, *getStanza(received[0])->getPayload<Swift::MUCUserPayload>()->getItems()[0].affiliation);
|
||||
CPPUNIT_ASSERT_EQUAL(Swift::MUCOccupant::Participant, *getStanza(received[0])->getPayload<Swift::MUCUserPayload>()->getItems()[0].role);
|
||||
|
||||
Swift::VCardUpdate::ref payload = getStanza(received[0])->getPayload<Swift::VCardUpdate>();
|
||||
CPPUNIT_ASSERT(payload);
|
||||
}
|
||||
|
||||
void handleParticipantChangedTwoResources() {
|
||||
connectSecondResource();
|
||||
received2.clear();
|
||||
|
|
Loading…
Add table
Reference in a new issue