Commit 00886473 authored by Nicolas Jager's avatar Nicolas Jager Committed by Guillaume Roguez

callbackshandler: link more callbacks from the daemon.

Change-Id: Ib073b8f6e3522c6617f3415ab6f9ebff7ee6d58f
Reviewd-by: Guillaume Roguez's avatarGuillaume Roguez <guillaume.roguez@savoirfairelinux.com>
parent 39c55e4a
/****************************************************************************
* Copyright (C) 2017 Savoir-faire Linux *
* Author : Nicolas Jäger <nicolas.jager@savoirfairelinux.com> *
* Author : Sébastien Blin <sebastien.blin@savoirfairelinux.com> *
* Author: Nicolas Jäger <nicolas.jager@savoirfairelinux.com> *
* Author: Sébastien Blin <sebastien.blin@savoirfairelinux.com> *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
......@@ -19,12 +19,16 @@
#include "callbackshandler.h"
// Models and database
#include "api/account.h"
#include "api/lrc.h"
#include "api/newaccountmodel.h"
// Dbus
// Lrc
#include "account.h"
#include "dbus/callmanager.h"
#include "dbus/configurationmanager.h"
#include "dbus/presencemanager.h"
#include "namedirectory.h"
namespace lrc
{
......@@ -55,6 +59,35 @@ CallbacksHandler::CallbacksHandler(const Lrc& parent)
&ConfigurationManagerInterface::contactRemoved,
this,
&CallbacksHandler::slotContactRemoved);
connect(&ConfigurationManager::instance(),
&ConfigurationManagerInterface::incomingTrustRequest,
this,
&CallbacksHandler::slotIncomingContactRequest);
connect(&NameDirectory::instance(),
&NameDirectory::registeredNameFound,
this,
&CallbacksHandler::slotRegisteredNameFound);
connect(&ConfigurationManager::instance(),
&ConfigurationManagerInterface::registrationStateChanged,
this,
&CallbacksHandler::slotRegistrationStateChanged);
connect(&CallManager::instance(),
&CallManagerInterface::incomingCall,
this,
&CallbacksHandler::slotIncomingCall);
connect(&CallManager::instance(),
&CallManagerInterface::callStateChanged,
this,
&CallbacksHandler::slotCallStateChanged);
connect(&CallManager::instance(),
&CallManagerInterface::incomingMessage,
this,
&CallbacksHandler::slotIncomingMessage);
}
CallbacksHandler::~CallbacksHandler()
......@@ -69,10 +102,14 @@ CallbacksHandler::slotNewAccountMessage(const QString& accountId,
{
std::map<std::string,std::string> stdPayloads;
for (auto item : payloads.keys())
for (auto item : payloads.keys()) {
stdPayloads[item.toStdString()] = payloads.value(item).toStdString();
}
emit NewAccountMessage(accountId.toStdString(), from.toStdString(), stdPayloads);
auto accountId2 = accountId.toStdString();
auto from2 = from.toStdString();
emit newAccountMessage(accountId2, from2, stdPayloads);
}
void
......@@ -81,7 +118,10 @@ CallbacksHandler::slotNewBuddySubscription(const QString& accountId,
bool status,
const QString& message)
{
emit NewBuddySubscription(uri.toStdString());
Q_UNUSED(accountId)
Q_UNUSED(status)
Q_UNUSED(message)
emit newBuddySubscription(uri.toStdString(), status);
}
void
......@@ -100,4 +140,89 @@ CallbacksHandler::slotContactRemoved(const QString& accountId,
emit contactRemoved(accountId.toStdString(), contactUri.toStdString(), banned);
}
void
CallbacksHandler::slotIncomingContactRequest(const QString& accountId,
const QString& ringId,
const QByteArray& payload,
time_t time)
{
Q_UNUSED(time)
emit incomingContactRequest(accountId.toStdString(), ringId.toStdString(), payload.toStdString());
}
void
CallbacksHandler::slotRegisteredNameFound(const Account* account, NameDirectory::LookupStatus status,
const QString& address, const QString& name)
{
if (!account) return;
if (status == NameDirectory::LookupStatus::SUCCESS) {
emit registeredNameFound(account->id().toStdString(), address.toStdString(), name.toStdString());
}
}
void
CallbacksHandler::slotIncomingCall(const QString &accountId, const QString &callId, const QString &fromUri)
{
if (fromUri.contains("ring.dht")) {
auto fromQString = fromUri.right(50);
fromQString = fromQString.left(40);
emit incomingCall(accountId.toStdString(), callId.toStdString(), fromQString.toStdString());
} else {
auto left = fromUri.indexOf("<")+1;
auto right = fromUri.indexOf("@");
auto fromQString = fromUri.mid(left, right-left);
emit incomingCall(accountId.toStdString(), callId.toStdString(), fromQString.toStdString());
}
}
void
CallbacksHandler::slotCallStateChanged(const QString& callId, const QString& state, int code)
{
emit callStateChanged(callId.toStdString(), state.toStdString(), code);
}
void
CallbacksHandler::slotRegistrationStateChanged(const QString& accountId,
const QString& registration_state,
unsigned detail_code,
const QString& detail_str)
{
emit accountStatusChanged(accountId.toStdString(), lrc::api::account::to_status(registration_state.toStdString()));
}
void
CallbacksHandler::slotIncomingMessage(const QString& callId,
const QString& from,
const QMap<QString,QString>& interaction)
{
std::string from2;
if (from.contains("ring.dht")) {
from2 = from.left(40).toStdString();
}
else {
auto left = from.indexOf(":")+1;
auto right = from.indexOf("@");
from2 = from.mid(left, right-left).toStdString();
}
for (auto& e : interaction.toStdMap()) {
if (e.first.contains("x-ring/ring.profile.vcard")) {
auto pieces0 = e.first.split( ";" );
auto pieces1 = pieces0[1].split( "," );
auto pieces2 = pieces1[1].split( "=" );
auto pieces3 = pieces1[2].split( "=" );
emit incomingVCardChunk(callId.toStdString(),
from2,
pieces2[1].toInt(),
pieces3[1].toInt(),
e.second.toStdString());
} else { // we consider it as an usual message interaction
emit incomingCallMessage(callId.toStdString(), from2, e.second.toStdString());
}
}
}
} // namespace lrc
/****************************************************************************
* Copyright (C) 2017 Savoir-faire Linux *
* Author : Nicolas Jäger <nicolas.jager@savoirfairelinux.com> *
* Author : Sébastien Blin <sebastien.blin@savoirfairelinux.com> *
* Author: Nicolas Jäger <nicolas.jager@savoirfairelinux.com> *
* Author: Sébastien Blin <sebastien.blin@savoirfairelinux.com> *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
......@@ -26,6 +26,7 @@
// Lrc
#include "typedefs.h"
#include "namedirectory.h"
namespace lrc
{
......@@ -33,6 +34,11 @@ namespace lrc
namespace api
{
class Lrc;
namespace account
{
enum class Status;
}
}
class CallbacksHandler : public QObject {
......@@ -44,64 +50,186 @@ public:
Q_SIGNALS:
/**
* Connect this signal to get incoming message.
* @param accountId, message reciever.
* @param from, message sender.
* Connect this signal to get incoming text interaction from the DHT.
* @param accountId interaction receiver.
* @param from interaction sender.
* @param payloads.
*/
void NewAccountMessage(const std::string& accountId,
const std::string& toStdString,
const std::map<std::string,std::string> payloads) const;
void newAccountMessage(std::string& accountId,
std::string& from,
std::map<std::string,std::string> payloads);
/**
* Connect this signal to get information when a peer is online.
* @param contactUri, the peer.
* @param contactUri the peer.
* @param present if the peer is online.
*/
void newBuddySubscription(const std::string& contactUri, bool present);
/**
* Connect this signal to know when a contact is removed by the daemon.
* @param accountId the one who lost a contact.
* @param contactUri the contact removed.
* @param banned if the contact was banned
*/
void contactRemoved(const std::string& accountId, const std::string& contactUri, bool banned);
/**
* Connect this signal to know when a contact is added by the daemon.
* @param accountId the one who got a new contact.
* @param contactUri the new contact.
* @param confirmed if the contact is trusted.
*/
void contactAdded(const std::string& accountId, const std::string& contactUri, bool confirmed);
/**
* Connect this signal to know when an incoming request is added by the daemon
* @param accountId the one who got the request
* @param ringId the peer contact
* @param payload the VCard
*/
void incomingContactRequest(const std::string& accountId, const std::string& ringId, const std::string& payload);
/**
* Connect this signal to know when a call arrives
* @param accountId the one who receives the call
* @param callId the call id
* @param fromUri the caller uri
*/
void incomingCall(const std::string& accountId,
const std::string& callId,
const std::string& fromUri);
/**
* Connect this signal to know when a call is updated
* @param callId the call id
* @param state the new state
* @param code
*/
void callStateChanged(const std::string& callId, const std::string &state, int code);
/**
* Connect this signal to know when the account status changed
* @param accountId the one who changes
* @param status the new status
*/
void accountStatusChanged(const std::string& accountId, const api::account::Status status);
/**
* Connect this signal to know when a registeredName is found
* @param accountId the account who receives this signal
* @param uri the URI of the profile found
* @param registeredName the registeredName linked to this URI
*/
void NewBuddySubscription(const std::string& contactUri) const;
void registeredNameFound(const std::string& accountId,
const std::string& uri,
const std::string& registeredName);
/**
* Connect this signal to know when a contact was removed by the daemon.
* @param accountId, the one who lost a contact.
* @param contactUri, the contact removed.
* @param banned, true if the contact was banned
* Connect this signal to know where a VCard is incoming
* @param callId the call linked to this VCard
* @param from the sender URI
* @param part the number of the part
* @param numberOfParts of the VCard
* @param payload content of the VCard
*/
void contactRemoved(const std::string& accountId, const std::string& contactUri, bool banned) const;
void incomingVCardChunk(const std::string& callId,
const std::string& from,
int part,
int numberOfParts,
const std::string& payload);
/**
* Connect this signal to know when a contact was addeb by the daemon.
* @param accountId, the one who got a new contact.
* @param contactUri, the new contact.
* @param confirmed, true if the contact is trusted.
* Connect this signal to get incoming text interaction from SIP.
* @param callId the call linked.
* @param from interaction sender.
* @param body the text received.
*/
void contactAdded(const std::string& accountId, const std::string& contactUri, bool confirmed) const;
void incomingCallMessage(const std::string& callId,
const std::string& from,
const std::string& body);
private Q_SLOTS:
/**
* Add the incoming message from the daemon to the database
* Emit newAccountMessage
* @param accountId
* @param from
* @param payloads of the message
* @param payloads of the interaction
*/
void slotNewAccountMessage(const QString& accountId, const QString& from, const QMap<QString,QString>& payloads);
void slotNewAccountMessage(const QString& accountId,
const QString& from,
const QMap<QString,QString>& payloads);
/**
* Update the presence of a contact for an account
* Emit newBuddySubscription
* @param accountId
* @param contactUri
* @param status if the contact is present
* @param message unused for now
*/
void slotNewBuddySubscription(const QString& accountId, const QString& contactUri, bool status, const QString& message);
void slotNewBuddySubscription(const QString& accountId,
const QString& contactUri,
bool status,
const QString& message);
/**
* Add a contact in the contact list of an account
* @param accountId
* Emit contactAdded
* @param accountId account linked
* @param contactUri
* @param confirmed
*/
void slotContactAdded(const QString& accountId, const QString& contactUri, bool confirmed);
/**
* Remove a contact from a contact list of an account
* @param accountId
* Emit contactRemoved
* @param accountId account linked
* @param contactUri
* @param banned
*/
void slotContactRemoved(const QString& accountId, const QString& contactUri, bool banned);
/**
* Emit incomingContactRequest
* @param accountId the linked id
* @param ringId the peer contact
* @param payload the VCard
* @param time when the request was received
*/
void slotIncomingContactRequest(const QString& accountId,
const QString& ringId,
const QByteArray& payload, time_t time);
/**
* Emit accountStatusChanged
* @param accountId
* @param registration_state
* @param detail_code
* @param detail_str
*/
void slotRegistrationStateChanged(const QString& accountId,
const QString& registration_state,
unsigned detail_code,
const QString& detail_str);
/**
* Listen from the daemon when a profile is found.
* @param account account linked.
* @param status if the method succeeds
* @param address the URI of the profile
* @param name registeredName
*/
void slotRegisteredNameFound(const Account* account,
NameDirectory::LookupStatus status,
const QString& address,
const QString& name);
/**
* Get the URI of the peer and emit incomingCall
* @param accountId account linked
* @param callId the incoming call id
* @param fromQString the uri of the peer
*/
void slotIncomingCall(const QString &accountId, const QString &callId, const QString &fromUri);
/**
* Emit callStateChanged
* @param callId the call which changes.
* @param state the new state
* @param code unused for now
*/
void slotCallStateChanged(const QString& callId, const QString &state, int code);
/**
* Parse a call message and emit incomingVCardChunk if it's a VCard chunk
* else incomingCallMessage if it's a text message
* @param callId call linked
* @param from the URI
* @param interaction the content of the Message.
*/
void slotIncomingMessage(const QString& callId,
const QString& from,
const QMap<QString,QString>& interaction);
private:
const api::Lrc& parent;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment