Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add XEP-0154 for VCard avatar updates via. presence #119

Merged
merged 1 commit into from
Aug 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add XEP-0154 for VCard photo/avatar updates
  • Loading branch information
LNJ committed Aug 7, 2017
commit 7e5236d2bd7afad5fde536c3d086b4d2e5fea81a
4 changes: 2 additions & 2 deletions src/Kaidan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <gloox/forward.h>
#include <gloox/carbons.h>
#include <gloox/vcardmanager.h>
#include <gloox/vcardupdate.h>
// Kaidan
#include "RosterModel.h"
#include "MessageModel.h"
Expand Down Expand Up @@ -128,17 +129,16 @@ void Kaidan::mainConnect()

// Presence Handler
presenceHandler = new PresenceHandler(client);
client->registerPresenceHandler(presenceHandler);

// Service Discovery
serviceDiscoveryManager = new ServiceDiscoveryManager(client, client->disco());

// Register Stanza Extensions
client->registerStanzaExtension(new gloox::Receipt(gloox::Receipt::Request));
client->registerStanzaExtension(new gloox::Receipt(gloox::Receipt::Received));
client->registerStanzaExtension(new gloox::DelayedDelivery(gloox::JID(), std::string("")));
client->registerStanzaExtension(new gloox::Forward());
client->registerStanzaExtension(new gloox::Carbons());
client->registerStanzaExtension(new gloox::VCardUpdate());

// Logging
client->logInstance().registerLogHandler(gloox::LogLevelDebug,
Expand Down
1 change: 1 addition & 0 deletions src/PresenceHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
PresenceHandler::PresenceHandler(gloox::Client *client)
{
this->client = client;
client->registerPresenceHandler(this);
}

PresenceHandler::~PresenceHandler()
Expand Down
1 change: 1 addition & 0 deletions src/PresenceHandler.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

/*
* Kaidan - A user-friendly XMPP client for every device!
*
Expand Down
10 changes: 10 additions & 0 deletions src/VCardManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

#include "VCardManager.h"
#include <gloox/vcardupdate.h>

VCardManager::VCardManager(gloox::Client *client, AvatarFileStorage *avatarStorage,
RosterModel *rosterModel)
Expand All @@ -26,6 +27,7 @@ VCardManager::VCardManager(gloox::Client *client, AvatarFileStorage *avatarStora
this->vCardManager = new gloox::VCardManager(client);
this->avatarStorage = avatarStorage;
this->rosterModel = rosterModel;
client->registerPresenceHandler(this);
}

VCardManager::~VCardManager()
Expand Down Expand Up @@ -56,3 +58,11 @@ void VCardManager::handleVCard(const gloox::JID& jid, const gloox::VCard* vcard)
void VCardManager::handleVCardResult(VCardContext context, const gloox::JID &jid, gloox::StanzaError stanzaError)
{
}

void VCardManager::handlePresence(const gloox::Presence& presence)
{
const gloox::VCardUpdate *vcupdate = presence.findExtension<gloox::VCardUpdate>
(gloox::ExtVCardUpdate);
if (vcupdate && vcupdate->hash().size() > 0)
fetchVCard(QString::fromStdString(presence.from().bare()));
}
6 changes: 4 additions & 2 deletions src/VCardManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@
#define VCARDMANAGER_H

// gloox
#include <gloox/client.h>
#include <gloox/vcardhandler.h>
#include <gloox/vcardmanager.h>
#include <gloox/client.h>
#include <gloox/presencehandler.h>
// Kaidan
#include "AvatarFileStorage.h"
#include "RosterModel.h"

class VCardManager : public gloox::VCardHandler
class VCardManager : public gloox::VCardHandler, public gloox::PresenceHandler
{
public:
VCardManager(gloox::Client *client, AvatarFileStorage *avatarStorage, RosterModel *rosterModel);
Expand All @@ -38,6 +39,7 @@ class VCardManager : public gloox::VCardHandler
virtual void handleVCard(const gloox::JID &jid, const gloox::VCard *vcard);
virtual void handleVCardResult(VCardContext context, const gloox::JID &jid,
gloox::StanzaError stanzaError = gloox::StanzaErrorUndefined);
virtual void handlePresence(const gloox::Presence &presence);

private:
gloox::Client *client;
Expand Down