Commit 732b0a76 authored by Ronan Abhamon's avatar Ronan Abhamon

feat(components/chat): remove properly end call event

parent 1d289809
......@@ -27,7 +27,7 @@
<file>assets/images/delete_hovered.svg</file>
<file>assets/images/delete_normal.svg</file>
<file>assets/images/delete_pressed.svg</file>
<file>assets/images/end_call.svg</file>
<file>assets/images/ended_call.svg</file>
<file>assets/images/filter.svg</file>
<file>assets/images/history.svg</file>
<file>assets/images/home_normal.svg</file>
......
......@@ -14,7 +14,7 @@ DefaultTranslator::DefaultTranslator () {
QString basename = info.baseName();
if (m_contexts.contains(basename))
qWarning() << QStringLiteral("QML file `%1` already exists in context list.").arg(basename);
qWarning() << QStringLiteral("QML context `%1` already exists in contexts list.").arg(basename);
else
m_contexts << basename;
}
......@@ -33,7 +33,7 @@ QString DefaultTranslator::translate (
QString translation = QTranslator::translate(context, source_text, disambiguation, n);
if (translation.length() == 0)
qWarning() << QStringLiteral("Unable to found a translation. (context=%1, label=%2)")
qWarning() << QStringLiteral("Unable to find a translation. (context=%1, label=%2)")
.arg(context).arg(source_text);
return translation;
......
#include <algorithm>
#include <QDateTime>
#include <QTimer>
#include <QtDebug>
#include "../../utils.hpp"
......@@ -104,16 +105,26 @@ void ChatModel::fillCallStartEntry (
dest["timestamp"] = timestamp;
dest["isOutgoing"] = call_log->getDir() == linphone::CallDirOutgoing;
dest["status"] = call_log->getStatus();
dest["isStart"] = true;
}
void ChatModel::fillCallEndEntry (
QVariantMap &dest,
const std::shared_ptr<linphone::CallLog> &call_log
) {
QDateTime timestamp = QDateTime::fromTime_t(
call_log->getStartDate() + call_log->getDuration()
);
dest["type"] = EntryType::CallEntry;
dest["timestamp"] = timestamp;
dest["isOutgoing"] = call_log->getDir() == linphone::CallDirOutgoing;
dest["status"] = call_log->getStatus();
dest["isStart"] = false;
}
// -------------------------------------------------------------------
void ChatModel::removeEntry (ChatEntryData &pair) {
int type = pair.first["type"].toInt();
......@@ -124,12 +135,32 @@ void ChatModel::removeEntry (ChatEntryData &pair) {
);
break;
case ChatModel::CallEntry:
if (pair.first["status"].toInt() == linphone::CallStatusSuccess) {
// WARNING: Unable to remove symmetric call here. (start/end)
// We are between `beginRemoveRows` and `endRemoveRows`.
// A solution is to schedule a `removeEntry` call in the Qt main loop.
std::shared_ptr<void> linphone_ptr = pair.second;
QTimer::singleShot(0, this, [this, linphone_ptr]() {
auto it = find_if(
m_entries.begin(), m_entries.end(),
[linphone_ptr](const ChatEntryData &pair) {
return pair.second == linphone_ptr;
}
);
if (it == m_entries.end())
qWarning("Unable to find symmetric call.");
else
removeEntry(distance(m_entries.begin(), it));
});
}
CoreManager::getInstance()->getCore()->removeCallLog(
static_pointer_cast<linphone::CallLog>(pair.second)
);
break;
default:
qWarning() << "Unknown chat entry type:" << type;
qWarning() << QStringLiteral("Unknown chat entry type: %1.").arg(type);
}
}
......@@ -165,28 +196,38 @@ void ChatModel::setSipAddress (const QString &sip_address) {
}
// Get calls.
auto insert_entry = [this](
const ChatEntryData &pair,
const QList<ChatEntryData>::iterator *start = NULL
) {
auto it = lower_bound(
start ? *start : m_entries.begin(), m_entries.end(), pair,
[](const ChatEntryData &a, const ChatEntryData &b) {
return a.first["timestamp"] < b.first["timestamp"];
}
);
return m_entries.insert(it, pair);
};
for (auto &call_log : core->getCallHistoryForAddress(m_chat_room->getPeerAddress())) {
linphone::CallStatus status = call_log->getStatus();
// Ignore aborted calls.
if (call_log->getStatus() == linphone::CallStatusAborted)
if (status == linphone::CallStatusAborted)
continue;
// Add start call.
QVariantMap start;
fillCallStartEntry(start, call_log);
ChatEntryData pair = qMakePair(start, static_pointer_cast<void>(call_log));
auto it = lower_bound(
m_entries.begin(), m_entries.end(), pair,
[](const ChatEntryData &a, const ChatEntryData &b) {
return a.first["timestamp"] < b.first["timestamp"];
}
);
m_entries.insert(it, pair);
auto it = insert_entry(qMakePair(start, static_pointer_cast<void>(call_log)));
// Add end call. (if necessary)
if (status == linphone::CallStatusSuccess) {
QVariantMap end;
fillCallEndEntry(end, call_log);
insert_entry(qMakePair(end, static_pointer_cast<void>(call_log)), &it);
}
}
endResetModel();
......
......@@ -11,19 +11,20 @@ Row {
property string _type: {
var status = $chatEntry.status
if ($chatEntry.status === ChatModel.CallStatusSuccess) {
if (status === ChatModel.CallStatusSuccess) {
if (!$chatEntry.isStart) {
return 'ended_call'
}
return $chatEntry.isOutgoing ? 'outgoing_call' : 'incoming_call'
}
if ($chatEntry.status === ChatModel.CallStatusDeclined) {
if (status === ChatModel.CallStatusDeclined) {
return $chatEntry.isOutgoing ? 'declined_outgoing_call' : 'declined_incoming_call'
}
if ($chatEntry.status === ChatModel.CallStatusMissed) {
if (status === ChatModel.CallStatusMissed) {
return $chatEntry.isOutgoing ? 'missed_outgoing_call' : 'missed_incoming_call'
}
return 'ended_call'
return 'unknown_call_event'
}
height: ChatStyle.entry.lineHeight
......
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