Commit 74be0201 authored by Ronan Abhamon's avatar Ronan Abhamon

feat(components/chat): supports a button to remove all history

parent 40236491
...@@ -141,6 +141,14 @@ ...@@ -141,6 +141,14 @@
<source>newMessagePlaceholder</source> <source>newMessagePlaceholder</source>
<translation type="vanished">Enter your message</translation> <translation type="vanished">Enter your message</translation>
</message> </message>
<message>
<source>removeAllEntriesDescription</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>removeAllEntriesTitle</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>DropZone</name> <name>DropZone</name>
......
...@@ -141,6 +141,14 @@ ...@@ -141,6 +141,14 @@
<source>newMessagePlaceholder</source> <source>newMessagePlaceholder</source>
<translation type="vanished">Entrer votre message.</translation> <translation type="vanished">Entrer votre message.</translation>
</message> </message>
<message>
<source>removeAllEntriesDescription</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>removeAllEntriesTitle</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>DropZone</name> <name>DropZone</name>
......
...@@ -46,18 +46,8 @@ bool ChatModel::removeRows (int row, int count, const QModelIndex &parent) { ...@@ -46,18 +46,8 @@ bool ChatModel::removeRows (int row, int count, const QModelIndex &parent) {
beginRemoveRows(parent, row, limit); beginRemoveRows(parent, row, limit);
for (int i = 0; i < count; ++i) { for (int i = 0; i < count; ++i) {
QPair<QVariantMap, shared_ptr<void> > pair = m_entries.takeAt(row); removeEntry(m_entries[row]);
m_entries.removeAt(row);
switch (pair.first["type"].toInt()) {
case ChatModel::MessageEntry:
m_chat_room->deleteMessage(
static_pointer_cast<linphone::ChatMessage>(pair.second)
);
break;
case ChatModel::CallEntry:
break;
}
} }
endRemoveRows(); endRemoveRows();
...@@ -74,8 +64,38 @@ void ChatModel::removeEntry (int id) { ...@@ -74,8 +64,38 @@ void ChatModel::removeEntry (int id) {
qWarning() << "Unable to remove chat entry:" << id; qWarning() << "Unable to remove chat entry:" << id;
} }
void ChatModel::removeAllEntries () {
qInfo() << "Removing all chat entries of:" << getSipAddress();
beginResetModel();
for (auto &entry : m_entries)
removeEntry(entry);
m_entries.clear();
endResetModel();
}
// ------------------------------------------------------------------- // -------------------------------------------------------------------
void ChatModel::removeEntry (ChatEntryData &pair) {
int type = pair.first["type"].toInt();
switch (type) {
case ChatModel::MessageEntry:
m_chat_room->deleteMessage(
static_pointer_cast<linphone::ChatMessage>(pair.second)
);
break;
case ChatModel::CallEntry:
break;
default:
qWarning() << "Unknown chat entry type:" << type;
}
}
QString ChatModel::getSipAddress () const { QString ChatModel::getSipAddress () const {
if (!m_chat_room) if (!m_chat_room)
return ""; return "";
......
...@@ -42,15 +42,20 @@ public: ...@@ -42,15 +42,20 @@ public:
public slots: public slots:
void removeEntry (int id); void removeEntry (int id);
void removeAllEntries ();
signals: signals:
void sipAddressChanged (const QString &sipAddress); void sipAddressChanged (const QString &sipAddress);
private: private:
typedef QPair<QVariantMap, std::shared_ptr<void> > ChatEntryData;
void removeEntry (ChatEntryData &pair);
QString getSipAddress () const; QString getSipAddress () const;
void setSipAddress (const QString &sip_address); void setSipAddress (const QString &sip_address);
QList<QPair<QVariantMap, std::shared_ptr<void> > > m_entries; QList<ChatEntryData> m_entries;
std::shared_ptr<linphone::ChatRoom> m_chat_room; std::shared_ptr<linphone::ChatRoom> m_chat_room;
}; };
......
...@@ -18,6 +18,20 @@ ColumnLayout { ...@@ -18,6 +18,20 @@ ColumnLayout {
sipAddress sipAddress
) || sipAddress ) || sipAddress
function _removeAllEntries () {
Utils.openConfirmDialog(window, {
descriptionText: qsTr('removeAllEntriesDescription'),
exitHandler: function (status) {
if (status) {
chatModel.removeAllEntries()
}
},
title: qsTr('removeAllEntriesTitle')
})
}
// -----------------------------------------------------------------
spacing: 0 spacing: 0
// ----------------------------------------------------------------- // -----------------------------------------------------------------
...@@ -90,7 +104,7 @@ ColumnLayout { ...@@ -90,7 +104,7 @@ ColumnLayout {
icon: 'delete' icon: 'delete'
iconSize: ConversationStyle.bar.actions.edit.iconSize iconSize: ConversationStyle.bar.actions.edit.iconSize
onClicked: window.setView('Contact') // TODO. onClicked: _removeAllEntries()
} }
} }
} }
...@@ -132,6 +146,8 @@ ColumnLayout { ...@@ -132,6 +146,8 @@ ColumnLayout {
Layout.fillWidth: true Layout.fillWidth: true
contact: parent._contact contact: parent._contact
model: ChatModel { model: ChatModel {
id: chatModel
sipAddress: conversation.sipAddress sipAddress: conversation.sipAddress
} }
} }
......
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