removed Order, resolved a crash on several files being uploaded simultaniuosly

This commit is contained in:
Blue 2023-11-09 19:36:30 -03:00
parent 0a530bfa93
commit be466fbad1
Signed by untrusted user: blue
GPG Key ID: 9B203B252A63EE38
12 changed files with 122 additions and 304 deletions

View File

@ -141,14 +141,13 @@ Core::Account::Account(
loadingOmemo = true; loadingOmemo = true;
future.then(this, [this] (bool result) { future.then(this, [this] (bool result) {
loadingOmemo = false; loadingOmemo = false;
if (state == Shared::ConnectionState::scheduled) { if (state == Shared::ConnectionState::scheduled)
client.connectToServer(config, presence); client.connectToServer(config, presence);
}
if (result) { if (result)
qDebug() << "successfully loaded OMEMO data for account" << getName(); qDebug() << "successfully loaded OMEMO data for account" << getName();
} else { else
qDebug() << "couldn't load OMEMO data for account" << getName(); qDebug() << "couldn't load OMEMO data for account" << getName();
}
}); });
} }
#endif #endif

View File

@ -30,7 +30,7 @@ Core::Archive::Archive(const QString& account, const QString& p_jid, QObject* pa
opened(false), opened(false),
db(account + "/" + jid), db(account + "/" + jid),
messages(db.addStorage<QString, Shared::Message>("messages")), messages(db.addStorage<QString, Shared::Message>("messages")),
order(db.addStorage<uint64_t, QString>("order")), order(db.addStorage<uint64_t, QString>("order", true)),
stats(db.addStorage<QString, QVariant>("stats")), stats(db.addStorage<QString, QVariant>("stats")),
avatars(db.addStorage<QString, AvatarInfo>("avatars")), avatars(db.addStorage<QString, AvatarInfo>("avatars")),
stanzaIdToId(db.addStorage<QString, QString>("stanzaIdToId")), stanzaIdToId(db.addStorage<QString, QString>("stanzaIdToId")),

View File

@ -51,8 +51,7 @@ void Core::MessageHandler::onMessageReceived(const QXmppMessage& msg) {
qDebug() << "Account" << acc->getName() << "received an Omemo1 encrypted message, not supported yet"; qDebug() << "Account" << acc->getName() << "received an Omemo1 encrypted message, not supported yet";
break; //let it go the way it is, there is nothing I can do yet break; //let it go the way it is, there is nothing I can do yet
case QXmpp::Omemo2: case QXmpp::Omemo2:
qDebug() << "Account" << acc->getName() << "received an Omemo2 encrypted message, not supported yet"; break;
break; //let it go the way it is, there is nothing I can do yet
} }
#endif #endif
#endif #endif
@ -359,6 +358,8 @@ std::pair<Shared::Message::State, QString> Core::MessageHandler::scheduleSending
const QXmppE2eeExtension::MessageEncryptResult& res = task.result(); const QXmppE2eeExtension::MessageEncryptResult& res = task.result();
if (std::holds_alternative<std::unique_ptr<QXmppMessage>>(res)) { if (std::holds_alternative<std::unique_ptr<QXmppMessage>>(res)) {
const std::unique_ptr<QXmppMessage>& encrypted = std::get<std::unique_ptr<QXmppMessage>>(res); const std::unique_ptr<QXmppMessage>& encrypted = std::get<std::unique_ptr<QXmppMessage>>(res);
encrypted->setBody("This message is encrypted with OMEMO 2 but could not be decrypted");
encrypted->setOutOfBandUrl("");
bool success = acc->client.sendPacket(*encrypted.get()); bool success = acc->client.sendPacket(*encrypted.get());
if (success) if (success)
return {Shared::Message::State::sent, ""}; return {Shared::Message::State::sent, ""};
@ -375,6 +376,7 @@ std::pair<Shared::Message::State, QString> Core::MessageHandler::scheduleSending
if (std::holds_alternative<std::unique_ptr<QXmppMessage>>(result)) { if (std::holds_alternative<std::unique_ptr<QXmppMessage>>(result)) {
const std::unique_ptr<QXmppMessage>& encrypted = std::get<std::unique_ptr<QXmppMessage>>(result); const std::unique_ptr<QXmppMessage>& encrypted = std::get<std::unique_ptr<QXmppMessage>>(result);
encrypted->setBody("This message is encrypted with OMEMO 2 but could not be decrypted"); encrypted->setBody("This message is encrypted with OMEMO 2 but could not be decrypted");
encrypted->setOutOfBandUrl("");
bool success = acc->client.sendPacket(*encrypted.get()); bool success = acc->client.sendPacket(*encrypted.get());
if (success) { if (success) {
std::tuple<bool, QString, QString> ids = getOriginalPendingMessageId(id, false); std::tuple<bool, QString, QString> ids = getOriginalPendingMessageId(id, false);

View File

@ -11,7 +11,4 @@ set(HEADER_FILES
root.h root.h
) )
target_sources(squawk PRIVATE target_sources(squawk PRIVATE ${SOURCE_FILES})
${SOURCE_FILES}
${HEADER_FILES}
)

View File

@ -18,7 +18,6 @@ set(SOURCE_FILES
) )
set(HEADER_FILES set(HEADER_FILES
order.h
shared.h shared.h
enums.h enums.h
global.h global.h

View File

@ -1,154 +0,0 @@
/*
* Squawk messenger.
* Copyright (C) 2019 Yury Gubich <blue@macaw.me>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ORDER_H
#define ORDER_H
#include <map>
#include <list>
#include "exception.h"
namespace W
{
template <typename data_type, typename comparator = std::less<data_type>>
class Order
{
public:
class Duplicates:
public Utils::Exception
{
public:
Duplicates():Exception(){}
std::string getMessage() const{return "Inserting element duplicates existing";}
};
class NotFound:
public Utils::Exception
{
public:
NotFound():Exception(){}
std::string getMessage() const{return "Erasing element haven't been found";}
};
protected:
typedef std::list<data_type> List;
public:
typedef typename List::size_type size_type;
typedef typename List::const_iterator const_iterator;
typedef typename List::iterator iterator;
protected:
typedef std::map<data_type, const_iterator, comparator> Map;
typedef typename Map::const_iterator m_const_itr;
typedef typename Map::iterator m_itr;
public:
Order():
order(),
r_map()
{}
~Order() {};
size_type size() const {
return order.size();
}
void push_back(data_type element) {
m_const_itr m_itr = r_map.find(element);
if (m_itr != r_map.end()) {
throw Duplicates();
}
const_iterator itr = order.insert(order.end(), element);
r_map.insert(std::make_pair(element, itr));
}
void erase(data_type element) {
m_const_itr itr = r_map.find(element);
if (itr == r_map.end()) {
throw NotFound();
}
order.erase(itr->second);
r_map.erase(itr);
}
void clear() {
order.clear();
r_map.clear();
}
void insert(const_iterator pos, data_type element) {
m_const_itr m_itr = r_map.find(element);
if (m_itr != r_map.end()) {
throw Duplicates();
}
const_iterator itr = order.insert(pos, element);
r_map.insert(std::make_pair(element, itr));
}
void insert(iterator pos, data_type element) {
m_const_itr m_itr = r_map.find(element);
if (m_itr != r_map.end()) {
throw Duplicates();
}
const_iterator itr = order.insert(pos, element);
r_map.insert(std::make_pair(element, itr));
}
const_iterator find(data_type element) const {
m_const_itr itr = r_map.find(element);
if (itr == r_map.end()) {
return end();
} else {
return itr->second;
}
}
const_iterator begin() const {
return order.begin();
}
const_iterator end() const {
return order.end();
}
iterator begin() {
return order.begin();
}
iterator end() {
return order.end();
}
private:
List order;
Map r_map;
};
}
#endif // ORDER_H

View File

@ -18,6 +18,8 @@
#include "badge.h" #include "badge.h"
#include "shared/utils.h"
Badge::Badge(const QString& p_id, const QString& p_text, const QIcon& icon, QWidget* parent): Badge::Badge(const QString& p_id, const QString& p_text, const QIcon& icon, QWidget* parent):
QFrame(parent), QFrame(parent),
id(p_id), id(p_id),
@ -48,8 +50,7 @@ Badge::Badge(QWidget* parent):
layout->addWidget(closeButton); layout->addWidget(closeButton);
} }
void Badge::setIcon(const QIcon& icon) void Badge::setIcon(const QIcon& icon) {
{
if (image == nullptr) { if (image == nullptr) {
image = new QLabel(); image = new QLabel();
image->setPixmap(icon.pixmap(25, 25)); image->setPixmap(icon.pixmap(25, 25));
@ -59,8 +60,7 @@ void Badge::setIcon(const QIcon& icon)
} }
} }
void Badge::setText(const QString& p_text) void Badge::setText(const QString& p_text) {
{
if (text == nullptr) { if (text == nullptr) {
text = new QLabel(p_text); text = new QLabel(p_text);
int index = 0; int index = 0;
@ -73,42 +73,30 @@ void Badge::setText(const QString& p_text)
} }
} }
Badge::~Badge() Badge::~Badge() {
{ if (image != nullptr)
if (image != nullptr) {
delete image; delete image;
}
if (text != nullptr) { if (text != nullptr)
delete text; delete text;
}
delete closeButton; delete closeButton;
} }
bool Badge::Comparator::operator()(const Badge* a, const Badge* b) const void Badge::createMandatoryComponents() {
{
return a->id < b->id;
}
bool Badge::Comparator::operator()(const Badge& a, const Badge& b) const
{
return a.id < b.id;
}
void Badge::createMandatoryComponents()
{
setBackgroundRole(QPalette::Base); setBackgroundRole(QPalette::Base);
//setAutoFillBackground(true); //setAutoFillBackground(true);
setFrameStyle(QFrame::StyledPanel); setFrameStyle(QFrame::StyledPanel);
setFrameShadow(QFrame::Raised); setFrameShadow(QFrame::Raised);
QIcon tabCloseIcon = QIcon::fromTheme("tab-close"); QIcon tabCloseIcon = QIcon::fromTheme("tab-close");
if (tabCloseIcon.isNull()) { if (tabCloseIcon.isNull())
tabCloseIcon.addFile(QString::fromUtf8(":/images/fallback/dark/big/edit-none.svg"), QSize(), QIcon::Normal, QIcon::Off); tabCloseIcon.addFile(QString::fromUtf8(":/images/fallback/dark/big/edit-none.svg"), QSize(), QIcon::Normal, QIcon::Off);
}
closeButton->setIcon(tabCloseIcon); closeButton->setIcon(tabCloseIcon);
closeButton->setMaximumHeight(25); closeButton->setMaximumHeight(25);
closeButton->setMaximumWidth(25); closeButton->setMaximumWidth(25);
layout->setContentsMargins(2, 2, 2, 2); layout->setContentsMargins(2, 2, 2, 2);
connect(closeButton, &QPushButton::clicked, this, &Badge::close); connect(closeButton, &QPushButton::clicked, this, &Badge::closeClicked);
} }

View File

@ -16,8 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef BADGE_H #pragma once
#define BADGE_H
#include <QFrame> #include <QFrame>
#include <QLabel> #include <QLabel>
@ -25,13 +24,7 @@
#include <QIcon> #include <QIcon>
#include <QPushButton> #include <QPushButton>
#include "shared/utils.h" class Badge : public QFrame {
/**
* @todo write docs
*/
class Badge : public QFrame
{
Q_OBJECT Q_OBJECT
public: public:
Badge(const QString& id, const QString& text, const QIcon& icon, QWidget* parent = nullptr); Badge(const QString& id, const QString& text, const QIcon& icon, QWidget* parent = nullptr);
@ -45,7 +38,7 @@ public:
void setIcon(const QIcon& icon); void setIcon(const QIcon& icon);
signals: signals:
void close(); void closeClicked();
private: private:
QLabel* image; QLabel* image;
@ -56,11 +49,4 @@ private:
private: private:
void createMandatoryComponents(); void createMandatoryComponents();
public:
struct Comparator {
bool operator()(const Badge& a, const Badge& b) const;
bool operator()(const Badge* a, const Badge* b) const;
};
}; };
#endif // BADGE_H

View File

@ -16,8 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef FLOWLAYOUT_H #pragma once
#define FLOWLAYOUT_H
#include <QLayout> #include <QLayout>
#include <QWidget> #include <QWidget>
@ -26,8 +25,7 @@
/** /**
* @todo write docs * @todo write docs
*/ */
class FlowLayout : public QLayout class FlowLayout : public QLayout {
{
Q_OBJECT Q_OBJECT
public: public:
explicit FlowLayout(QWidget *parent, int margin = -1, int hSpacing = -1, int vSpacing = -1); explicit FlowLayout(QWidget *parent, int margin = -1, int hSpacing = -1, int vSpacing = -1);
@ -55,5 +53,3 @@ private:
int m_hSpace; int m_hSpace;
int m_vSpace; int m_vSpace;
}; };
#endif // FLOWLAYOUT_H

View File

@ -33,6 +33,12 @@
#include <QBitmap> #include <QBitmap>
#include <unistd.h> #include <unistd.h>
#include <algorithm>
#include "shared/icons.h"
#include "shared/utils.h"
#include "shared/pathcheck.h"
#include "shared/defines.h"
constexpr QSize avatarSize(50, 50); constexpr QSize avatarSize(50, 50);
@ -61,29 +67,48 @@ Conversation::Conversation(bool muc, Models::Account* acc, Models::Element* el,
currentAction(CurrentAction::none), currentAction(CurrentAction::none),
currentMessageId() currentMessageId()
{ {
m_ui->setupUi(this); createUI();
createFeed();
subscribeEvents();
initializeOverlay();
}
shadow.setFrames(true, false, true, false); Conversation::~Conversation() {
delete contextMenu;
element->feed->decrementObservers();
delete m_ui;
}
void Conversation::createFeed() {
feed->setItemDelegate(delegate); feed->setItemDelegate(delegate);
feed->setFrameShape(QFrame::NoFrame); feed->setFrameShape(QFrame::NoFrame);
feed->setContextMenuPolicy(Qt::CustomContextMenu); feed->setContextMenuPolicy(Qt::CustomContextMenu);
feed->setModel(el->feed); feed->setModel(element->feed);
el->feed->incrementObservers(); element->feed->incrementObservers();
m_ui->widget->layout()->addWidget(feed); m_ui->widget->layout()->addWidget(feed);
connect(el->feed, &Models::MessageFeed::newMessage, this, &Conversation::onFeedMessage); connect(element->feed, &Models::MessageFeed::newMessage, this, &Conversation::onFeedMessage);
connect(feed, &FeedView::resized, this, &Conversation::positionShadow); connect(feed, &FeedView::resized, this, &Conversation::positionShadow);
connect(feed, &FeedView::customContextMenuRequested, this, &Conversation::onFeedContext); connect(feed, &FeedView::customContextMenuRequested, this, &Conversation::onFeedContext);
}
connect(acc, &Models::Account::childChanged, this, &Conversation::onAccountChanged); void Conversation::createUI() {
m_ui->setupUi(this);
statusIcon = m_ui->statusIcon;
statusLabel = m_ui->statusLabel;
filesLayout = new FlowLayout(m_ui->filesPanel, 0); filesLayout = new FlowLayout(m_ui->filesPanel, 0);
m_ui->filesPanel->setLayout(filesLayout); m_ui->filesPanel->setLayout(filesLayout);
statusIcon = m_ui->statusIcon; m_ui->currentActionBadge->setVisible(false);
statusLabel = m_ui->statusLabel; m_ui->encryptionButton->setVisible(false);
shadow.setFrames(true, false, true, false);
}
void Conversation::subscribeEvents() {
connect(account, &Models::Account::childChanged, this, &Conversation::onAccountChanged);
connect(&ker, &KeyEnterReceiver::enterPressed, this, qOverload<>(&Conversation::initiateMessageSending)); connect(&ker, &KeyEnterReceiver::enterPressed, this, qOverload<>(&Conversation::initiateMessageSending));
connect(&ker, &KeyEnterReceiver::imagePasted, this, &Conversation::onImagePasted); connect(&ker, &KeyEnterReceiver::imagePasted, this, &Conversation::onImagePasted);
connect(m_ui->sendButton, &QPushButton::clicked, this, qOverload<>(&Conversation::initiateMessageSending)); connect(m_ui->sendButton, &QPushButton::clicked, this, qOverload<>(&Conversation::initiateMessageSending));
@ -98,29 +123,7 @@ Conversation::Conversation(bool muc, Models::Account* acc, Models::Element* el,
connect(m_ui->messageEditor, &QTextEdit::customContextMenuRequested, this, &Conversation::onMessageEditorContext); connect(m_ui->messageEditor, &QTextEdit::customContextMenuRequested, this, &Conversation::onMessageEditorContext);
connect(pasteImageAction, &QAction::triggered, this, &Conversation::onImagePasted); connect(pasteImageAction, &QAction::triggered, this, &Conversation::onImagePasted);
connect(m_ui->currentActionBadge, &Badge::close, this, &Conversation::clear); connect(m_ui->currentActionBadge, &Badge::closeClicked, this, &Conversation::clear);
m_ui->currentActionBadge->setVisible(false);
m_ui->encryptionButton->setVisible(false);
//line->setAutoFillBackground(false);
//if (testAttribute(Qt::WA_TranslucentBackground)) {
//m_ui->scrollArea->setAutoFillBackground(false);
//} else {
//m_ui->scrollArea->setBackgroundRole(QPalette::Base);
//}
//line->setMyAvatarPath(acc->getAvatarPath());
//line->setMyName(acc->getName());
initializeOverlay();
}
Conversation::~Conversation() {
delete contextMenu;
element->feed->decrementObservers();
delete m_ui;
} }
void Conversation::onAccountChanged(Models::Item* item, int row, int col) { void Conversation::onAccountChanged(Models::Item* item, int row, int col) {
@ -228,7 +231,7 @@ void Conversation::initiateMessageSending() {
initiateMessageSending(msg); initiateMessageSending(msg);
} }
if (filesToAttach.size() > 0) { if (filesToAttach.size() > 0) {
for (Badge* badge : filesToAttach) { for (const Badge* badge : filesToAttach) {
Shared::Message msg = createMessage(); Shared::Message msg = createMessage();
msg.setAttachPath(badge->id); msg.setAttachPath(badge->id);
element->feed->registerUpload(msg.getId()); element->feed->registerUpload(msg.getId());
@ -291,6 +294,14 @@ Models::Roster::ElId Conversation::getId() const {
} }
void Conversation::addAttachedFile(const QString& path) { void Conversation::addAttachedFile(const QString& path) {
std::vector<Badge*>::const_iterator itr = std::find_if(
filesToAttach.begin(),
filesToAttach.end(),
[&path] (const Badge* badge) {return badge->id == path;}
);
if (itr != filesToAttach.end())
return;
QMimeDatabase db; QMimeDatabase db;
QMimeType type = db.mimeTypeForFile(path); QMimeType type = db.mimeTypeForFile(path);
QFileInfo info(path); QFileInfo info(path);
@ -300,25 +311,23 @@ void Conversation::addAttachedFile(const QString& path) {
fileIcon.addFile(QString::fromUtf8(":/images/fallback/dark/big/mail-attachment.svg"), QSize(), QIcon::Normal, QIcon::Off); fileIcon.addFile(QString::fromUtf8(":/images/fallback/dark/big/mail-attachment.svg"), QSize(), QIcon::Normal, QIcon::Off);
Badge* badge = new Badge(path, info.fileName(), fileIcon); Badge* badge = new Badge(path, info.fileName(), fileIcon);
connect(badge, &Badge::close, this, &Conversation::onBadgeClose);
try {
filesToAttach.push_back(badge); filesToAttach.push_back(badge);
connect(badge, &Badge::closeClicked, this, &Conversation::onBadgeClose);
filesLayout->addWidget(badge); filesLayout->addWidget(badge);
if (filesLayout->count() == 1) { if (filesLayout->count() == 1)
filesLayout->setContentsMargins(3, 3, 3, 3); filesLayout->setContentsMargins(3, 3, 3, 3);
}
} catch (const W::Order<Badge*, Badge::Comparator>::Duplicates& e) {
delete badge;
} catch (...) {
throw;
}
} }
void Conversation::removeAttachedFile(Badge* badge) { void Conversation::removeAttachedFile(const QString& id) {
W::Order<Badge*, Badge::Comparator>::const_iterator itr = filesToAttach.find(badge); std::vector<Badge*>::const_iterator itr = std::find_if(
filesToAttach.begin(),
filesToAttach.end(),
[&id] (const Badge* badge) {return badge->id == id;}
);
if (itr != filesToAttach.end()) { if (itr != filesToAttach.end()) {
filesToAttach.erase(badge); Badge* badge = *itr;
filesToAttach.erase(itr);
if (filesLayout->count() == 1) if (filesLayout->count() == 1)
filesLayout->setContentsMargins(0, 0, 0, 0); filesLayout->setContentsMargins(0, 0, 0, 0);
@ -328,7 +337,7 @@ void Conversation::removeAttachedFile(Badge* badge) {
void Conversation::onBadgeClose() { void Conversation::onBadgeClose() {
Badge* badge = static_cast<Badge*>(sender()); Badge* badge = static_cast<Badge*>(sender());
removeAttachedFile(badge); removeAttachedFile(badge->id);
} }
void Conversation::clearAttachedFiles() { void Conversation::clearAttachedFiles() {
@ -351,12 +360,10 @@ void Conversation::onEncryptionButtonClicked() {}
void Conversation::setAvatar(const QString& path) { void Conversation::setAvatar(const QString& path) {
QPixmap pixmap; QPixmap pixmap;
if (path.size() == 0) { if (path.size() == 0)
pixmap = Shared::icon("user", true).pixmap(avatarSize); pixmap = Shared::icon("user", true).pixmap(avatarSize);
} else { else
pixmap = QPixmap(path).scaled(avatarSize, Qt::KeepAspectRatio, Qt::SmoothTransformation); pixmap = QPixmap(path).scaled(avatarSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
}
QPixmap result(avatarSize); QPixmap result(avatarSize);
result.fill(Qt::transparent); result.fill(Qt::transparent);
@ -379,8 +386,7 @@ void Conversation::setFeedFrames(bool top, bool right, bool bottom, bool left) {
shadow.setFrames(top, right, bottom, left); shadow.setFrames(top, right, bottom, left);
} }
void Conversation::dragEnterEvent(QDragEnterEvent* event) void Conversation::dragEnterEvent(QDragEnterEvent* event) {
{
bool accept = false; bool accept = false;
if (event->mimeData()->hasUrls()) { if (event->mimeData()->hasUrls()) {
QList<QUrl> list = event->mimeData()->urls(); QList<QUrl> list = event->mimeData()->urls();
@ -542,9 +548,8 @@ void Conversation::onMessageEditRequested(const QString& id) {
currentAction = CurrentAction::edit; currentAction = CurrentAction::edit;
m_ui->messageEditor->setText(msg.getBody()); m_ui->messageEditor->setText(msg.getBody());
QString path = msg.getAttachPath(); QString path = msg.getAttachPath();
if (path.size() > 0) { if (path.size() > 0)
addAttachedFile(path); addAttachedFile(path);
}
} catch (const Models::MessageFeed::NotFound& e) { } catch (const Models::MessageFeed::NotFound& e) {
qDebug() << "The message requested to be edited was not found" << e.getMessage().c_str(); qDebug() << "The message requested to be edited was not found" << e.getMessage().c_str();

View File

@ -16,8 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef CONVERSATION_H #pragma once
#define CONVERSATION_H
#include <QWidget> #include <QWidget>
#include <QObject> #include <QObject>
@ -30,12 +29,9 @@
#include <QAction> #include <QAction>
#include <QDesktopServices> #include <QDesktopServices>
#include <vector>
#include "shared/message.h" #include "shared/message.h"
#include "shared/order.h"
#include "shared/icons.h"
#include "shared/utils.h"
#include "shared/pathcheck.h"
#include "shared/defines.h"
#include "ui/models/account.h" #include "ui/models/account.h"
#include "ui/models/roster.h" #include "ui/models/roster.h"
@ -96,7 +92,7 @@ protected:
virtual Shared::Message createMessage() const; virtual Shared::Message createMessage() const;
void setStatus(const QString& status); void setStatus(const QString& status);
void addAttachedFile(const QString& path); void addAttachedFile(const QString& path);
void removeAttachedFile(Badge* badge); void removeAttachedFile(const QString& id);
void clearAttachedFiles(); void clearAttachedFiles();
void dragEnterEvent(QDragEnterEvent* event) override; void dragEnterEvent(QDragEnterEvent* event) override;
void dragLeaveEvent(QDragLeaveEvent* event) override; void dragLeaveEvent(QDragLeaveEvent* event) override;
@ -105,6 +101,10 @@ protected:
virtual void onMessage(const Shared::Message& msg); virtual void onMessage(const Shared::Message& msg);
virtual void showEvent(QShowEvent * event) override; virtual void showEvent(QShowEvent * event) override;
void createFeed();
void createUI();
void subscribeEvents();
protected slots: protected slots:
void initiateMessageSending(); void initiateMessageSending();
void initiateMessageSending(const Shared::Message& msg); void initiateMessageSending(const Shared::Message& msg);
@ -142,7 +142,7 @@ protected:
QLabel* statusLabel; QLabel* statusLabel;
FlowLayout* filesLayout; FlowLayout* filesLayout;
QWidget* overlay; QWidget* overlay;
W::Order<Badge*, Badge::Comparator> filesToAttach; std::vector<Badge*> filesToAttach;
FeedView* feed; FeedView* feed;
MessageDelegate* delegate; MessageDelegate* delegate;
bool manualSliderChange; bool manualSliderChange;
@ -161,5 +161,3 @@ private:
static QPixmap* avatarPixmap; static QPixmap* avatarPixmap;
static QPainter* avatarPainter; static QPainter* avatarPainter;
}; };
#endif // CONVERSATION_H

View File

@ -18,6 +18,8 @@
#include "room.h" #include "room.h"
#include "shared/defines.h"
Room::Room(Models::Account* acc, Models::Room* p_room, QWidget* parent): Room::Room(Models::Account* acc, Models::Room* p_room, QWidget* parent):
Conversation(true, acc, p_room, p_room->getJid(), "", parent), Conversation(true, acc, p_room, p_room->getJid(), "", parent),
room(p_room) room(p_room)