Commit 8dfc664d authored by Andreas Traczyk's avatar Andreas Traczyk

database: migrate to per account database

Gitlab: #407
Change-Id: I834cf0d216dfd9e6badab8d7aab951b8875c1bd6
parent 2697394b
...@@ -280,7 +280,7 @@ SET( libringclient_LIB_SRCS ...@@ -280,7 +280,7 @@ SET( libringclient_LIB_SRCS
src/conversationmodel.cpp src/conversationmodel.cpp
src/database.cpp src/database.cpp
src/authority/daemon.cpp src/authority/daemon.cpp
src/authority/databasehelper.cpp src/authority/storagehelper.cpp
src/lrc.cpp src/lrc.cpp
src/newaccountmodel.cpp src/newaccountmodel.cpp
src/peerdiscoverymodel.cpp src/peerdiscoverymodel.cpp
......
...@@ -131,7 +131,7 @@ struct Info ...@@ -131,7 +131,7 @@ struct Info
std::chrono::steady_clock::time_point startTime; std::chrono::steady_clock::time_point startTime;
Status status = Status::INVALID; Status status = Status::INVALID;
Type type = Type::INVALID; Type type = Type::INVALID;
std::string peer; std::string peerUri;
bool isOutgoing; bool isOutgoing;
bool audioMuted = false; bool audioMuted = false;
bool videoMuted = false; bool videoMuted = false;
......
...@@ -33,6 +33,13 @@ namespace api ...@@ -33,6 +33,13 @@ namespace api
namespace contact namespace contact
{ {
/**
* @var profileInfo
* @var registeredName
* @var isTrusted
* @var isPresent
* @var isBanned
*/
struct Info struct Info
{ {
profile::Info profileInfo; profile::Info profileInfo;
......
...@@ -57,7 +57,7 @@ public: ...@@ -57,7 +57,7 @@ public:
const account::Info& owner; const account::Info& owner;
ContactModel(const account::Info& owner, ContactModel(const account::Info& owner,
Database& database, Database& db,
const CallbacksHandler& callbacksHandler, const CallbacksHandler& callbacksHandler,
const BehaviorController& behaviorController); const BehaviorController& behaviorController);
~ContactModel(); ~ContactModel();
...@@ -85,18 +85,6 @@ public: ...@@ -85,18 +85,6 @@ public:
* @return list of banned contacts uris as string * @return list of banned contacts uris as string
*/ */
const std::list<std::string>& getBannedContacts() const; const std::list<std::string>& getBannedContacts() const;
/**
* @param uri
* @param isAccount
* @return empty string if no contact, else the uri in db
*/
const std::string getProfileId(const std::string &ur, bool isAccount = false) const;
/**
* @deprecated use getProfileId
* @param contactUri
* @return empty string if no contact, else the uri in db
*/
const std::string getContactProfileId(const std::string& contactUri) const;
/** /**
* @return all contacts for this account. * @return all contacts for this account.
*/ */
......
...@@ -36,8 +36,8 @@ enum class Type { ...@@ -36,8 +36,8 @@ enum class Type {
TEXT, TEXT,
CALL, CALL,
CONTACT, CONTACT,
OUTGOING_DATA_TRANSFER, DATA_TRANSFER,
INCOMING_DATA_TRANSFER COUNT__
}; };
static inline const std::string static inline const std::string
...@@ -50,11 +50,10 @@ to_string(const Type& type) ...@@ -50,11 +50,10 @@ to_string(const Type& type)
return "CALL"; return "CALL";
case Type::CONTACT: case Type::CONTACT:
return "CONTACT"; return "CONTACT";
case Type::OUTGOING_DATA_TRANSFER: case Type::DATA_TRANSFER:
return "OUTGOING_DATA_TRANSFER"; return "DATA_TRANSFER";
case Type::INCOMING_DATA_TRANSFER:
return "INCOMING_DATA_TRANSFER";
case Type::INVALID: case Type::INVALID:
case Type::COUNT__:
default: default:
return "INVALID"; return "INVALID";
} }
...@@ -69,24 +68,19 @@ to_type(const std::string& type) ...@@ -69,24 +68,19 @@ to_type(const std::string& type)
return interaction::Type::CALL; return interaction::Type::CALL;
else if (type == "CONTACT") else if (type == "CONTACT")
return interaction::Type::CONTACT; return interaction::Type::CONTACT;
else if (type == "OUTGOING_DATA_TRANSFER") else if (type == "DATA_TRANSFER")
return interaction::Type::OUTGOING_DATA_TRANSFER; return interaction::Type::DATA_TRANSFER;
else if (type == "INCOMING_DATA_TRANSFER")
return interaction::Type::INCOMING_DATA_TRANSFER;
else else
return interaction::Type::INVALID; return interaction::Type::INVALID;
} }
enum class Status { enum class Status {
INVALID, INVALID,
UNKNOWN, UNKNOWN,
SENDING, SENDING,
FAILED, FAILURE,
SUCCEED, SUCCESS,
READ, TRANSFER_CREATED,
UNREAD,
TRANSFER_CREATED, /*[jn] mettre à jour les fonctions de conversion */
TRANSFER_ACCEPTED, TRANSFER_ACCEPTED,
TRANSFER_CANCELED, TRANSFER_CANCELED,
TRANSFER_ERROR, TRANSFER_ERROR,
...@@ -95,7 +89,8 @@ enum class Status { ...@@ -95,7 +89,8 @@ enum class Status {
TRANSFER_AWAITING_PEER, TRANSFER_AWAITING_PEER,
TRANSFER_AWAITING_HOST, TRANSFER_AWAITING_HOST,
TRANSFER_TIMEOUT_EXPIRED, TRANSFER_TIMEOUT_EXPIRED,
TRANSFER_FINISHED TRANSFER_FINISHED,
COUNT__
}; };
static inline const std::string static inline const std::string
...@@ -106,14 +101,10 @@ to_string(const Status& status) ...@@ -106,14 +101,10 @@ to_string(const Status& status)
return "UNKNOWN"; return "UNKNOWN";
case Status::SENDING: case Status::SENDING:
return "SENDING"; return "SENDING";
case Status::FAILED: case Status::FAILURE:
return "FAILED"; return "FAILURE";
case Status::SUCCEED: case Status::SUCCESS:
return "SUCCEED"; return "SUCCESS";
case Status::READ:
return "READ";
case Status::UNREAD:
return "UNREAD";
case Status::TRANSFER_CREATED: case Status::TRANSFER_CREATED:
return "TRANSFER_CREATED"; return "TRANSFER_CREATED";
case Status::TRANSFER_ACCEPTED: case Status::TRANSFER_ACCEPTED:
...@@ -135,6 +126,7 @@ to_string(const Status& status) ...@@ -135,6 +126,7 @@ to_string(const Status& status)
case Status::TRANSFER_FINISHED: case Status::TRANSFER_FINISHED:
return "TRANSFER_FINISHED"; return "TRANSFER_FINISHED";
case Status::INVALID: case Status::INVALID:
case Status::COUNT__:
default: default:
return "INVALID"; return "INVALID";
} }
...@@ -144,56 +136,60 @@ static inline Status ...@@ -144,56 +136,60 @@ static inline Status
to_status(const std::string& status) to_status(const std::string& status)
{ {
if (status == "UNKNOWN") if (status == "UNKNOWN")
return interaction::Status::UNKNOWN; return Status::UNKNOWN;
else if (status == "SENDING") else if (status == "SENDING")
return interaction::Status::SENDING; return Status::SENDING;
else if (status == "FAILED") else if (status == "FAILURE")
return interaction::Status::FAILED; return Status::FAILURE;
else if (status == "SUCCEED") else if (status == "SUCCESS")
return interaction::Status::SUCCEED; return Status::SUCCESS;
else if (status == "READ")
return interaction::Status::READ;
else if (status == "UNREAD")
return interaction::Status::UNREAD;
else if (status == "TRANSFER_CREATED") else if (status == "TRANSFER_CREATED")
return interaction::Status::TRANSFER_CREATED; return Status::TRANSFER_CREATED;
else if (status == "TRANSFER_ACCEPTED") else if (status == "TRANSFER_ACCEPTED")
return interaction::Status::TRANSFER_ACCEPTED; return Status::TRANSFER_ACCEPTED;
else if (status == "TRANSFER_CANCELED") else if (status == "TRANSFER_CANCELED")
return interaction::Status::TRANSFER_CANCELED; return Status::TRANSFER_CANCELED;
else if (status == "TRANSFER_ERROR") else if (status == "TRANSFER_ERROR")
return interaction::Status::TRANSFER_ERROR; return Status::TRANSFER_ERROR;
else if (status == "TRANSFER_UNJOINABLE_PEER") else if (status == "TRANSFER_UNJOINABLE_PEER")
return interaction::Status::TRANSFER_UNJOINABLE_PEER; return Status::TRANSFER_UNJOINABLE_PEER;
else if (status == "TRANSFER_ONGOING") else if (status == "TRANSFER_ONGOING")
return interaction::Status::TRANSFER_ONGOING; return Status::TRANSFER_ONGOING;
else if (status == "TRANSFER_AWAITING_HOST") else if (status == "TRANSFER_AWAITING_HOST")
return interaction::Status::TRANSFER_AWAITING_HOST; return Status::TRANSFER_AWAITING_HOST;
else if (status == "TRANSFER_AWAITING_PEER") else if (status == "TRANSFER_AWAITING_PEER")
return interaction::Status::TRANSFER_AWAITING_PEER; return Status::TRANSFER_AWAITING_PEER;
else if (status == "TRANSFER_TIMEOUT_EXPIRED") else if (status == "TRANSFER_TIMEOUT_EXPIRED")
return interaction::Status::TRANSFER_TIMEOUT_EXPIRED; return Status::TRANSFER_TIMEOUT_EXPIRED;
else if (status == "TRANSFER_FINISHED") else if (status == "TRANSFER_FINISHED")
return interaction::Status::TRANSFER_FINISHED; return Status::TRANSFER_FINISHED;
else else
return interaction::Status::INVALID; return Status::INVALID;
} }
/**
* @var authorUri
* @var body
* @var timestamp
* @var duration
* @var type
* @var status
* @var isRead
*/
struct Info struct Info
{ {
std::string authorUri; std::string authorUri;
std::string body; std::string body;
std::time_t timestamp = 0; std::time_t timestamp = 0;
std::time_t duration = 0;
Type type = Type::INVALID; Type type = Type::INVALID;
Status status = Status::INVALID; Status status = Status::INVALID;
bool isRead = false;
}; };
static inline bool isOutgoing(const Info& interaction) { static inline bool isOutgoing(const Info& interaction) {
return (interaction.status != lrc::api::interaction::Status::READ return interaction.authorUri.empty();
&& interaction.status != lrc::api::interaction::Status::UNREAD
&& interaction.type != lrc::api::interaction::Type::INCOMING_DATA_TRANSFER)
|| interaction.type == lrc::api::interaction::Type::OUTGOING_DATA_TRANSFER;
} }
} // namespace interaction } // namespace interaction
......
...@@ -41,7 +41,15 @@ class AVModel; ...@@ -41,7 +41,15 @@ class AVModel;
class LIB_EXPORT Lrc { class LIB_EXPORT Lrc {
public: public:
Lrc(); /**
* Construct an Lrc object and optionally invoke callbacks
* to control ui informing the user of a possibly lengthy
* migration process.
* @param willMigrateCb
* @param didMigrateCb
*/
Lrc(MigrationCb willMigrateCb = {},
MigrationCb didMigrateCb = {});
~Lrc(); ~Lrc();
/** /**
* get a reference on account model. * get a reference on account model.
...@@ -77,6 +85,10 @@ public: ...@@ -77,6 +85,10 @@ public:
* Can communicate with the daemon via dbus * Can communicate with the daemon via dbus
*/ */
static bool dbusIsValid(); static bool dbusIsValid();
/**
* Connect to debugMessageReceived signal
*/
void subscribeToDebugReceived();
/** /**
* Helper: get call list from daemon * Helper: get call list from daemon
......
...@@ -53,12 +53,11 @@ class BehaviorController; ...@@ -53,12 +53,11 @@ class BehaviorController;
class LIB_EXPORT NewAccountModel : public QObject { class LIB_EXPORT NewAccountModel : public QObject {
Q_OBJECT Q_OBJECT
public: public:
using AccountInfoMap = std::map<std::string, account::Info>;
NewAccountModel(Lrc& lrc, NewAccountModel(Lrc& lrc,
Database& database,
const CallbacksHandler& callbackHandler, const CallbacksHandler& callbackHandler,
const api::BehaviorController& behaviorController); const api::BehaviorController& behaviorController,
MigrationCb& willMigrateCb,
MigrationCb& didMigrateCb);
~NewAccountModel(); ~NewAccountModel();
/** /**
...@@ -173,13 +172,13 @@ public: ...@@ -173,13 +172,13 @@ public:
* Set an account to the first position * Set an account to the first position
*/ */
void setTopAccount(const std::string& accountId); void setTopAccount(const std::string& accountId);
/** /**
* Build the vCard for an account * Get the vCard for an account
* @param id * @param id
* @return vcard of the account * @return vcard of the account
*/ */
std::string accountVCard(const std::string& accountId, bool compressImage = true) const; std::string accountVCard(const std::string& accountId, bool compressImage = true) const;
std::string compressedAvatar(const std::string& img) const;
Q_SIGNALS: Q_SIGNALS:
/** /**
......
...@@ -72,11 +72,12 @@ public: ...@@ -72,11 +72,12 @@ public:
/** /**
* Create a new call with a contact * Create a new call with a contact
* @param url of the contact to call * @param uri of the contact to call
* @param isAudioOnly, set to false by default * @param isAudioOnly, set to false by default
* @return the call uid created. Empty string is returned if call couldn't be created. * @return the call uid created. Empty string is returned if call couldn't be created.
*/ */
std::string createCall(const std::string& url, bool isAudioOnly = false); std::string createCall(const std::string& uri, bool isAudioOnly = false);
/** /**
* Get the call from its call id * Get the call from its call id
* @param uid * @param uid
...@@ -84,6 +85,7 @@ public: ...@@ -84,6 +85,7 @@ public:
* @throw out_of_range exception if not found * @throw out_of_range exception if not found
*/ */
const call::Info& getCall(const std::string& uid) const; const call::Info& getCall(const std::string& uid) const;
/** /**
* Get the call from the peer uri * Get the call from the peer uri
* @param uri * @param uri
...@@ -92,6 +94,7 @@ public: ...@@ -92,6 +94,7 @@ public:
* @throw out_of_range exception if not found * @throw out_of_range exception if not found
*/ */
const call::Info& getCallFromURI(const std::string& uri, bool notOver = false) const; const call::Info& getCallFromURI(const std::string& uri, bool notOver = false) const;
/** /**
* Get conference from a peer uri * Get conference from a peer uri
* @param uri * @param uri
...@@ -99,11 +102,13 @@ public: ...@@ -99,11 +102,13 @@ public:
* @throw out_of_range exception if not found * @throw out_of_range exception if not found
*/ */
const call::Info& getConferenceFromURI(const std::string& uri) const; const call::Info& getConferenceFromURI(const std::string& uri) const;
/** /**
* @param callId to test * @param callId to test
* @return true if callId is presend else false. * @return true if callId is presend else false.
*/ */
bool hasCall(const std::string& callId) const; bool hasCall(const std::string& callId) const;
/** /**
* Send a text message to a SIP call * Send a text message to a SIP call
* @param callId * @param callId
...@@ -116,64 +121,76 @@ public: ...@@ -116,64 +121,76 @@ public:
* @param callId * @param callId
*/ */
void accept(const std::string& callId) const; void accept(const std::string& callId) const;
/** /**
* Hang up a call * Hang up a call
* @param callId * @param callId
*/ */
void hangUp(const std::string& callId) const; void hangUp(const std::string& callId) const;
/** /**
* Refuse a call * Refuse a call
* @param callId * @param callId
*/ */
void refuse(const std::string& callId) const; void refuse(const std::string& callId) const;
/** /**
* Toggle audio record on a call * Toggle audio record on a call
* @param callId * @param callId
*/ */
void toggleAudioRecord(const std::string& callId) const; void toggleAudioRecord(const std::string& callId) const;
/** /**
* Play DTMF in a call * Play DTMF in a call
* @param callId * @param callId
* @param value to play * @param value to play
*/ */
void playDTMF(const std::string& callId, const std::string& value) const; void playDTMF(const std::string& callId, const std::string& value) const;
/** /**
* Toggle pause on a call * Toggle pause on a call
* @param callId * @param callId
*/ */
void togglePause(const std::string& callId) const; void togglePause(const std::string& callId) const;
/** /**
* Toggle a media on a call * Toggle a media on a call
* @param callId * @param callId
* @param media {AUDIO, VIDEO} * @param media {AUDIO, VIDEO}
*/ */
void toggleMedia(const std::string& callId, const NewCallModel::Media media) const; void toggleMedia(const std::string& callId, const NewCallModel::Media media) const;
/** /**
* Not implemented yet * Not implemented yet
*/ */
void setQuality(const std::string& callId, const double quality) const; void setQuality(const std::string& callId, const double quality) const;
/** /**
* Blind transfer. Directly transfer a call to a sip number * Blind transfer. Directly transfer a call to a sip number
* @param callId: the call to transfer * @param callId: the call to transfer
* @param to: the sip number (for example: "sip:1412") * @param to: the sip number (for example: "sip:1412")
*/ */
void transfer(const std::string& callId, const std::string& to) const; void transfer(const std::string& callId, const std::string& to) const;
/** /**
* Perform an attended. Transfer a call to another call * Perform an attended. Transfer a call to another call
* @param callIdSrc: the call to transfer * @param callIdSrc: the call to transfer
* @param callIdDest: the destination's call * @param callIdDest: the destination's call
*/ */
void transferToCall(const std::string& callIdSrc, const std::string& callIdDest) const; void transferToCall(const std::string& callIdSrc, const std::string& callIdDest) const;
/** /**
* Create a conference from 2 calls. * Create a conference from 2 calls.
* @param callIdA uid of the call A * @param callIdA uid of the call A
* @param callIdB uid of the call B * @param callIdB uid of the call B
*/ */
void joinCalls(const std::string& callIdA, const std::string& callIdB) const; void joinCalls(const std::string& callIdA, const std::string& callIdB) const;
/** /**
* Not implemented yet * Not implemented yet
*/ */
void removeParticipant(const std::string& callId, const std::string& participant) const; void removeParticipant(const std::string& callId, const std::string& participant) const;
/** /**
* @param callId * @param callId
* @return a human readable call duration (M:ss) * @return a human readable call duration (M:ss)
......
...@@ -35,7 +35,8 @@ enum class Type { ...@@ -35,7 +35,8 @@ enum class Type {
RING, RING,
SIP, SIP,
PENDING, PENDING,
TEMPORARY TEMPORARY,
COUNT__
}; };
static inline const std::string static inline const std::string
...@@ -51,6 +52,7 @@ to_string(const Type& type) ...@@ -51,6 +52,7 @@ to_string(const Type& type)
case Type::TEMPORARY: case Type::TEMPORARY:
return "TEMPORARY"; return "TEMPORARY";
case Type::INVALID: case Type::INVALID:
case Type::COUNT__: