Commit a89cf392 authored by Adrien Béraud's avatar Adrien Béraud

dring: add cancelMessage API

Change-Id: Id99a8d8a3af3ef59d52a3267e0f44262c6df17f3
parent 58de0e05
......@@ -542,6 +542,16 @@
</arg>
</method>
<method name="cancelMessage" tp:name-for-bindings="cancelMessage">
<arg type="s" name="accountID" direction="in"/>
<arg type="t" name="id" direction="in"/>
<arg type="b" name="success" direction="out">
<tp:docstring>
Cancel pending message.
</tp:docstring>
</arg>
</method>
<method name="getLastMessages" tp:name-for-bindings="getLastMessages">
<arg type="s" name="accountID" direction="in"/>
<arg type="t" name="base_timestamp" direction="in"/>
......
......@@ -89,6 +89,8 @@ void registerAllAccounts(void);
uint64_t sendAccountTextMessage(const std::string& accountID, const std::string& to, const std::map<std::string, std::string>& message);
std::vector<DRing::Message> getLastMessages(const std::string& accountID, uint64_t base_timestamp);
int getMessageStatus(uint64_t id);
int getMessageStatus(const std::string& accountID, uint64_t id);
bool cancelMessage(const std::string& accountID, uint64_t id);
bool lookupName(const std::string& account, const std::string& nameserver, const std::string& name);
bool lookupAddress(const std::string& account, const std::string& nameserver, const std::string& address);
......
......@@ -85,6 +85,8 @@ void registerAllAccounts(void);
uint64_t sendAccountTextMessage(const std::string& accountID, const std::string& to, const std::map<std::string, std::string>& message);
std::vector<Message> getLastMessages(const std::string& accountID, const uint64_t& base_timestamp);
int getMessageStatus(uint64_t id);
int getMessageStatus(const std::string& accountID, uint64_t id);
bool cancelMessage(const std::string& accountID, uint64_t id);
bool lookupName(const std::string& account, const std::string& nameserver, const std::string& name);
bool lookupAddress(const std::string& account, const std::string& nameserver, const std::string& address);
......
......@@ -2,7 +2,7 @@ dnl Jami - configure.ac for automake 1.9 and autoconf 2.59
dnl Process this file with autoconf to produce a configure script.
AC_PREREQ([2.65])
AC_INIT([Jami Daemon],[7.5.0],[ring@gnu.org],[jami])
AC_INIT([Jami Daemon],[7.6.0],[ring@gnu.org],[jami])
AC_COPYRIGHT([[Copyright (c) Savoir-faire Linux 2004-2019]])
AC_REVISION([$Revision$])
......
......@@ -163,10 +163,14 @@ class Account : public Serializable, public std::enable_shared_from_this<Account
/**
* Return the status corresponding to the token.
*/
virtual im::MessageStatus getMessageStatus(uint64_t id UNUSED) const {
virtual im::MessageStatus getMessageStatus(uint64_t /*id*/) const {
return im::MessageStatus::UNKNOWN;
}
virtual bool cancelMessage(uint64_t /*id*/) {
return false;
}
std::vector<std::shared_ptr<Call>> getCalls();
/**
......
......@@ -265,13 +265,29 @@ sendAccountTextMessage(const std::string& accountID, const std::string& to, cons
std::vector<Message>
getLastMessages(const std::string& accountID, const uint64_t& base_timestamp)
{
return ring::Manager::instance().getLastMessages(accountID, base_timestamp);
if (const auto acc = ring::Manager::instance().getAccount(accountID))
return acc->getLastMessages(base_timestamp);
return {};
}
int
getMessageStatus(uint64_t messageId)
{
return ring::Manager::instance().getMessageStatus(messageId);
}
int
getMessageStatus(uint64_t id)
getMessageStatus(const std::string& accountID, uint64_t messageId)
{
return ring::Manager::instance().getMessageStatus(id);
return ring::Manager::instance().getMessageStatus(accountID, messageId);
}
bool
cancelMessage(const std::string& accountID, uint64_t messageId)
{
if (const auto acc = ring::Manager::instance().getAccount(accountID))
return acc->cancelMessage(messageId);
return {};
}
bool
......
......@@ -67,7 +67,8 @@ enum class MessageStates : int {
SENDING,
SENT,
READ,
FAILURE
FAILURE,
CANCELLED
}; //DRing::Account::MessageStates
enum class testAccountICEInitializationStatus : int {
......
......@@ -75,9 +75,10 @@ DRING_PUBLIC std::vector<std::string> getAccountList();
DRING_PUBLIC void sendRegister(const std::string& accountID, bool enable);
DRING_PUBLIC void registerAllAccounts(void);
DRING_PUBLIC uint64_t sendAccountTextMessage(const std::string& accountID, const std::string& to, const std::map<std::string, std::string>& payloads);
DRING_PUBLIC bool cancelMessage(const std::string& accountID, uint64_t message);
DRING_PUBLIC std::vector<Message> getLastMessages(const std::string& accountID, const uint64_t& base_timestamp);
DRING_PUBLIC int getMessageStatus(uint64_t id);
DRING_PUBLIC int getMessageStatus(const std::string& accountID, uint64_t id);
DRING_PUBLIC std::map<std::string, std::string> getTlsDefaultSettings();
......
......@@ -116,6 +116,25 @@ MessageEngine::getStatus(MessageToken t) const
return MessageStatus::UNKNOWN;
}
bool
MessageEngine::cancel(MessageToken t)
{
std::lock_guard<std::mutex> lock(messagesMutex_);
for (auto& p : messages_) {
auto m = p.second.find(t);
if (m != p.second.end()) {
m->second.status = MessageStatus::CANCELLED;
emitSignal<DRing::ConfigurationSignal::AccountMessageStatusChanged>(account_.getAccountID(),
t,
m->second.to,
static_cast<int>(DRing::Account::MessageStates::CANCELLED));
save_();
return true;
}
}
return false;
}
void
MessageEngine::onMessageSent(const std::string& peer, MessageToken token, bool ok)
{
......@@ -215,7 +234,7 @@ MessageEngine::save_() const
Json::Value peerRoot(Json::objectValue);
for (auto& m : c.second) {
auto& v = m.second;
if (v.status == MessageStatus::FAILURE || v.status == MessageStatus::SENT)
if (v.status == MessageStatus::FAILURE || v.status == MessageStatus::SENT || v.status == MessageStatus::CANCELLED)
continue;
Json::Value msg;
std::ostringstream msgsId;
......
......@@ -40,7 +40,8 @@ enum class MessageStatus {
SENDING,
SENT,
READ,
FAILURE
FAILURE,
CANCELLED
};
class MessageEngine
......@@ -53,6 +54,8 @@ public:
MessageStatus getStatus(MessageToken t) const;
bool cancel(MessageToken t);
bool isSent(MessageToken t) const {
return getStatus(t) == MessageStatus::SENT;
}
......
......@@ -3027,30 +3027,42 @@ Manager::sendTextMessage(const std::string& accountID, const std::string& to,
}
int
Manager::getMessageStatus(uint64_t id)
statusFromImStatus(im::MessageStatus status) {
switch (status) {
case im::MessageStatus::IDLE:
case im::MessageStatus::SENDING:
return static_cast<int>(DRing::Account::MessageStates::SENDING);
case im::MessageStatus::SENT:
return static_cast<int>(DRing::Account::MessageStates::SENT);
case im::MessageStatus::READ:
return static_cast<int>(DRing::Account::MessageStates::READ);
case im::MessageStatus::FAILURE:
return static_cast<int>(DRing::Account::MessageStates::FAILURE);
default:
return static_cast<int>(DRing::Account::MessageStates::UNKNOWN);
}
}
int
Manager::getMessageStatus(uint64_t id) const
{
const auto& allAccounts = accountFactory.getAllAccounts();
for (auto acc : allAccounts) {
auto status = acc->getMessageStatus(id);
if (status != im::MessageStatus::UNKNOWN) {
switch (status) {
case im::MessageStatus::IDLE:
case im::MessageStatus::SENDING:
return static_cast<int>(DRing::Account::MessageStates::SENDING);
case im::MessageStatus::SENT:
return static_cast<int>(DRing::Account::MessageStates::SENT);
case im::MessageStatus::READ:
return static_cast<int>(DRing::Account::MessageStates::READ);
case im::MessageStatus::FAILURE:
return static_cast<int>(DRing::Account::MessageStates::FAILURE);
default:
return static_cast<int>(DRing::Account::MessageStates::UNKNOWN);
}
}
if (status != im::MessageStatus::UNKNOWN)
return statusFromImStatus(status);
}
return static_cast<int>(DRing::Account::MessageStates::UNKNOWN);
}
int
Manager::getMessageStatus(const std::string& accountID, uint64_t id) const
{
if (const auto acc = getAccount(accountID))
return statusFromImStatus(acc->getMessageStatus(id));
return static_cast<int>(DRing::Account::MessageStates::UNKNOWN);
}
void
Manager::setAccountActive(const std::string& accountID, bool active)
{
......
......@@ -388,7 +388,8 @@ class Manager {
uint64_t sendTextMessage(const std::string& accountID, const std::string& to,
const std::map<std::string, std::string>& payloads);
int getMessageStatus(uint64_t id);
int getMessageStatus(uint64_t id) const;
int getMessageStatus(const std::string& accountID, uint64_t id) const;
/**
* Get account list
......
......@@ -268,6 +268,10 @@ public:
return messageEngine_.getStatus(id);
}
virtual bool cancelMessage(uint64_t id) override {
return messageEngine_.cancel(id);
}
void onTextMessage(const std::string& from, const std::map<std::string, std::string>& payloads);
/* Returns true if the username and/or hostname match this account */
......
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