forked from blue/squawk
Bug with the edited message fixed, some further work on message correction
This commit is contained in:
parent
0823b35148
commit
bf4a27f35d
@ -406,7 +406,7 @@ bool Shared::Message::change(const QMap<QString, QVariant>& data)
|
|||||||
if (!edited || lastModified < correctionDate) {
|
if (!edited || lastModified < correctionDate) {
|
||||||
originalMessage = body;
|
originalMessage = body;
|
||||||
lastModified = correctionDate;
|
lastModified = correctionDate;
|
||||||
setBody(body);
|
setBody(b);
|
||||||
setEdited(true);
|
setEdited(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -549,6 +549,8 @@ void Models::Roster::changeMessage(const QString& account, const QString& jid, c
|
|||||||
Element* el = getElement({account, jid});
|
Element* el = getElement({account, jid});
|
||||||
if (el != NULL) {
|
if (el != NULL) {
|
||||||
el->changeMessage(id, data);
|
el->changeMessage(id, data);
|
||||||
|
} else {
|
||||||
|
qDebug() << "A request to change a message of the contact " << jid << " in the account " << account << " but it wasn't found";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,7 +110,7 @@ Conversation::Conversation(bool muc, Models::Account* acc, Models::Element* el,
|
|||||||
|
|
||||||
initializeOverlay();
|
initializeOverlay();
|
||||||
|
|
||||||
m_ui->currentActionBadge->setVisible(false);;
|
m_ui->currentActionBadge->setVisible(false);
|
||||||
// m_ui->currentActionBadge->setText(tr("Editing message..."));
|
// m_ui->currentActionBadge->setText(tr("Editing message..."));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -476,10 +476,10 @@ void Conversation::onFeedContext(const QPoint& pos)
|
|||||||
Shared::Message* item = static_cast<Shared::Message*>(index.internalPointer());
|
Shared::Message* item = static_cast<Shared::Message*>(index.internalPointer());
|
||||||
|
|
||||||
contextMenu->clear();
|
contextMenu->clear();
|
||||||
|
QString id = item->getId();
|
||||||
bool showMenu = false;
|
bool showMenu = false;
|
||||||
if (item->getState() == Shared::Message::State::error) {
|
if (item->getState() == Shared::Message::State::error) {
|
||||||
showMenu = true;
|
showMenu = true;
|
||||||
QString id = item->getId();
|
|
||||||
QAction* resend = contextMenu->addAction(Shared::icon("view-refresh"), tr("Try sending again"));
|
QAction* resend = contextMenu->addAction(Shared::icon("view-refresh"), tr("Try sending again"));
|
||||||
connect(resend, &QAction::triggered, [this, id]() {
|
connect(resend, &QAction::triggered, [this, id]() {
|
||||||
element->feed->registerUpload(id);
|
element->feed->registerUpload(id);
|
||||||
@ -501,6 +501,12 @@ void Conversation::onFeedContext(const QPoint& pos)
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (item->getOutgoing()) {
|
||||||
|
showMenu = true;
|
||||||
|
QAction* edit = contextMenu->addAction(Shared::icon("edit-rename"), tr("Edit"));
|
||||||
|
connect(edit, &QAction::triggered, this, std::bind(&Conversation::onMessageEditRequested, this, id));
|
||||||
|
}
|
||||||
|
|
||||||
if (showMenu) {
|
if (showMenu) {
|
||||||
contextMenu->popup(feed->viewport()->mapToGlobal(pos));
|
contextMenu->popup(feed->viewport()->mapToGlobal(pos));
|
||||||
}
|
}
|
||||||
@ -517,3 +523,23 @@ void Conversation::onMessageEditorContext(const QPoint& pos)
|
|||||||
|
|
||||||
editorMenu->exec(this->m_ui->messageEditor->mapToGlobal(pos));
|
editorMenu->exec(this->m_ui->messageEditor->mapToGlobal(pos));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Conversation::onMessageEditRequested(const QString& id)
|
||||||
|
{
|
||||||
|
if (currentAction == CurrentAction::edit) {
|
||||||
|
//todo;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
Shared::Message msg = element->feed->getMessage(id);
|
||||||
|
|
||||||
|
m_ui->currentActionBadge->setVisible(true);
|
||||||
|
m_ui->currentActionBadge->setText(tr("Editing message..."));
|
||||||
|
currentAction = CurrentAction::edit;
|
||||||
|
m_ui->messageEditor->setText(msg.getBody());
|
||||||
|
|
||||||
|
} catch (const Models::MessageFeed::NotFound& e) {
|
||||||
|
qDebug() << "The message requested to be edited was not found" << e.getMessage().c_str();
|
||||||
|
qDebug() << "Ignoring";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -116,6 +116,7 @@ protected slots:
|
|||||||
void positionShadow();
|
void positionShadow();
|
||||||
void onFeedContext(const QPoint &pos);
|
void onFeedContext(const QPoint &pos);
|
||||||
void onMessageEditorContext(const QPoint &pos);
|
void onMessageEditorContext(const QPoint &pos);
|
||||||
|
void onMessageEditRequested(const QString& id);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
const bool isMuc;
|
const bool isMuc;
|
||||||
|
@ -224,8 +224,20 @@ std::set<Models::MessageFeed::MessageRoles> Models::MessageFeed::detectChanges(c
|
|||||||
|
|
||||||
void Models::MessageFeed::removeMessage(const QString& id)
|
void Models::MessageFeed::removeMessage(const QString& id)
|
||||||
{
|
{
|
||||||
|
//todo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Shared::Message Models::MessageFeed::getMessage(const QString& id)
|
||||||
|
{
|
||||||
|
StorageById::iterator itr = indexById.find(id);
|
||||||
|
if (itr == indexById.end()) {
|
||||||
|
throw NotFound(id.toStdString(), rosterItem->getJid().toStdString(), rosterItem->getAccountName().toStdString());
|
||||||
|
}
|
||||||
|
|
||||||
|
return **itr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QVariant Models::MessageFeed::data(const QModelIndex& index, int role) const
|
QVariant Models::MessageFeed::data(const QModelIndex& index, int role) const
|
||||||
{
|
{
|
||||||
int i = index.row();
|
int i = index.row();
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
|
|
||||||
#include <shared/message.h>
|
#include <shared/message.h>
|
||||||
#include <shared/icons.h>
|
#include <shared/icons.h>
|
||||||
|
#include <shared/exception.h>
|
||||||
|
|
||||||
|
|
||||||
namespace Models {
|
namespace Models {
|
||||||
@ -55,6 +56,7 @@ public:
|
|||||||
void addMessage(const Shared::Message& msg);
|
void addMessage(const Shared::Message& msg);
|
||||||
void changeMessage(const QString& id, const QMap<QString, QVariant>& data);
|
void changeMessage(const QString& id, const QMap<QString, QVariant>& data);
|
||||||
void removeMessage(const QString& id);
|
void removeMessage(const QString& id);
|
||||||
|
Shared::Message getMessage(const QString& id);
|
||||||
|
|
||||||
QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const override;
|
QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const override;
|
||||||
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
|
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
|
||||||
@ -104,6 +106,21 @@ public:
|
|||||||
Bulk
|
Bulk
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class NotFound:
|
||||||
|
public Utils::Exception
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
NotFound(const std::string& k, const std::string& j, const std::string& acc):Exception(), key(k), jid(j), account(acc){}
|
||||||
|
|
||||||
|
std::string getMessage() const {
|
||||||
|
return "Message with id " + key + " wasn't found in messageFeed " + account + " of the chat with " + jid;
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
std::string key;
|
||||||
|
std::string jid;
|
||||||
|
std::string account;
|
||||||
|
};
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool sentByMe(const Shared::Message& msg) const;
|
bool sentByMe(const Shared::Message& msg) const;
|
||||||
Attachment fillAttach(const Shared::Message& msg) const;
|
Attachment fillAttach(const Shared::Message& msg) const;
|
||||||
|
Loading…
Reference in New Issue
Block a user