Commit 0988bb93 authored by Ronan Abhamon's avatar Ronan Abhamon

feat(src/components/sip-addresses/SipAddressesModel): better code...

feat(src/components/sip-addresses/SipAddressesModel): better code (SipAddressesModel::addOrUpdateSipAddress)
parent c2efb388
...@@ -16,7 +16,6 @@ class App : public QApplication { ...@@ -16,7 +16,6 @@ class App : public QApplication {
Q_OBJECT; Q_OBJECT;
public: public:
QQmlEngine *getEngine () { QQmlEngine *getEngine () {
return &m_engine; return &m_engine;
} }
......
...@@ -189,19 +189,29 @@ void SipAddressesModel::handleContactRemoved (const ContactModel *contact) { ...@@ -189,19 +189,29 @@ void SipAddressesModel::handleContactRemoved (const ContactModel *contact) {
} }
void SipAddressesModel::addOrUpdateSipAddress ( void SipAddressesModel::addOrUpdateSipAddress (
const QString &sip_address, QVariantMap &map,
ContactModel *contact, ContactModel *contact,
const std::shared_ptr<linphone::ChatMessage> &message const shared_ptr<linphone::ChatMessage> &message
) { ) {
auto it = m_sip_addresses.find(sip_address);
if (it != m_sip_addresses.end()) {
if (contact) { if (contact) {
(*it)["contact"] = QVariant::fromValue(contact); map["contact"] = QVariant::fromValue(contact);
updateObservers(sip_address, contact); updateObservers(map["sipAddress"].toString(), contact);
}
if (message) {
map["timestamp"] = QDateTime::fromMSecsSinceEpoch(message->getTime() * 1000);
map["unreadMessagesCount"] = message->getChatRoom()->getUnreadMessagesCount();
} }
}
if (message) void SipAddressesModel::addOrUpdateSipAddress (
(*it)["timestamp"] = QDateTime::fromMSecsSinceEpoch(message->getTime() * 1000); const QString &sip_address,
ContactModel *contact,
const shared_ptr<linphone::ChatMessage> &message
) {
auto it = m_sip_addresses.find(sip_address);
if (it != m_sip_addresses.end()) {
addOrUpdateSipAddress(*it, contact, message);
int row = m_refs.indexOf(&(*it)); int row = m_refs.indexOf(&(*it));
Q_ASSERT(row != -1); Q_ASSERT(row != -1);
...@@ -212,14 +222,7 @@ void SipAddressesModel::addOrUpdateSipAddress ( ...@@ -212,14 +222,7 @@ void SipAddressesModel::addOrUpdateSipAddress (
QVariantMap map; QVariantMap map;
map["sipAddress"] = sip_address; map["sipAddress"] = sip_address;
addOrUpdateSipAddress(map, contact, message);
if (contact) {
map["contact"] = QVariant::fromValue(contact);
updateObservers(sip_address, contact);
}
if (message)
map["timestamp"] = QDateTime::fromMSecsSinceEpoch(message->getTime() * 1000);
int row = m_refs.count(); int row = m_refs.count();
...@@ -273,6 +276,7 @@ void SipAddressesModel::initSipAddresses () { ...@@ -273,6 +276,7 @@ void SipAddressesModel::initSipAddresses () {
QVariantMap map; QVariantMap map;
map["sipAddress"] = sip_address; map["sipAddress"] = sip_address;
map["timestamp"] = QDateTime::fromMSecsSinceEpoch(history.back()->getTime() * 1000); map["timestamp"] = QDateTime::fromMSecsSinceEpoch(history.back()->getTime() * 1000);
map["unreadMessagesCount"] = chat_room->getUnreadMessagesCount();
m_sip_addresses[sip_address] = map; m_sip_addresses[sip_address] = map;
} }
......
...@@ -37,11 +37,18 @@ private: ...@@ -37,11 +37,18 @@ private:
void handleContactAdded (ContactModel *contact); void handleContactAdded (ContactModel *contact);
void handleContactRemoved (const ContactModel *contact); void handleContactRemoved (const ContactModel *contact);
void addOrUpdateSipAddress (
QVariantMap &map,
ContactModel *contact,
const std::shared_ptr<linphone::ChatMessage> &message
);
void addOrUpdateSipAddress ( void addOrUpdateSipAddress (
const QString &sip_address, const QString &sip_address,
ContactModel *contact = nullptr, ContactModel *contact = nullptr,
const std::shared_ptr<linphone::ChatMessage> &message = std::shared_ptr<linphone::ChatMessage>() const std::shared_ptr<linphone::ChatMessage> &message = std::shared_ptr<linphone::ChatMessage>()
); );
void removeContactOfSipAddress (const QString &sip_address); void removeContactOfSipAddress (const QString &sip_address);
void initSipAddresses (); void initSipAddresses ();
......
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