forked from blue/squawk
attaching messages fix, bad alloc fix
This commit is contained in:
parent
6657dc79ce
commit
b50ce146b8
@ -1377,6 +1377,7 @@ void Core::Account::addNewRoom(const QString& jid, const QString& nick, const QS
|
||||
{"avatars", conf->getAllAvatars()}
|
||||
};
|
||||
|
||||
|
||||
Archive::AvatarInfo info;
|
||||
bool hasAvatar = conf->readAvatarInfo(info);
|
||||
if (hasAvatar) {
|
||||
|
@ -817,15 +817,16 @@ void Core::Archive::readAllResourcesAvatars(std::map<QString, AvatarInfo>& data)
|
||||
mdb_txn_begin(environment, NULL, MDB_RDONLY, &txn);
|
||||
mdb_cursor_open(txn, avatars, &cursor);
|
||||
rc = mdb_cursor_get(cursor, &lmdbKey, &lmdbData, MDB_FIRST);
|
||||
|
||||
do {
|
||||
std::string sId((char*)lmdbKey.mv_data, lmdbKey.mv_size);
|
||||
QString res(sId.c_str());
|
||||
if (res != jid) {
|
||||
data.emplace(res, AvatarInfo());
|
||||
data[res].deserialize((char*)lmdbData.mv_data, lmdbData.mv_size);
|
||||
}
|
||||
} while (mdb_cursor_get(cursor, &lmdbKey, &lmdbData, MDB_NEXT) == 0);
|
||||
if (rc == 0) { //the db might be empty yet
|
||||
do {
|
||||
std::string sId((char*)lmdbKey.mv_data, lmdbKey.mv_size);
|
||||
QString res(sId.c_str());
|
||||
if (res != jid) {
|
||||
data.emplace(res, AvatarInfo());
|
||||
data[res].deserialize((char*)lmdbData.mv_data, lmdbData.mv_size);
|
||||
}
|
||||
} while (mdb_cursor_get(cursor, &lmdbKey, &lmdbData, MDB_NEXT) == 0);
|
||||
}
|
||||
|
||||
mdb_cursor_close(cursor);
|
||||
mdb_txn_abort(txn);
|
||||
|
@ -61,19 +61,14 @@ void Chat::updateState()
|
||||
statusIcon->setToolTip(Shared::Global::getName(av));
|
||||
}
|
||||
|
||||
void Chat::handleSendMessage(const QString& text)
|
||||
Shared::Message Chat::createMessage() const
|
||||
{
|
||||
Shared::Message msg(Shared::Message::chat);
|
||||
Shared::Message msg = Conversation::createMessage();
|
||||
msg.setType(Shared::Message::chat);
|
||||
msg.setFrom(account->getFullJid());
|
||||
msg.setToJid(palJid);
|
||||
msg.setToResource(activePalResource);
|
||||
msg.setBody(text);
|
||||
msg.setOutgoing(true);
|
||||
msg.generateRandomId();
|
||||
msg.setCurrentTime();
|
||||
msg.setState(Shared::Message::State::pending);
|
||||
addMessage(msg);
|
||||
emit sendMessage(msg);
|
||||
return msg;
|
||||
}
|
||||
|
||||
void Chat::addMessage(const Shared::Message& data)
|
||||
|
@ -43,7 +43,7 @@ protected slots:
|
||||
|
||||
protected:
|
||||
void setName(const QString & name) override;
|
||||
void handleSendMessage(const QString & text) override;
|
||||
Shared::Message createMessage() const override;
|
||||
|
||||
private:
|
||||
void updateState();
|
||||
|
@ -208,22 +208,14 @@ void Conversation::onEnterPressed()
|
||||
|
||||
if (body.size() > 0) {
|
||||
m_ui->messageEditor->clear();
|
||||
handleSendMessage(body);
|
||||
Shared::Message msg = createMessage();
|
||||
msg.setBody(body);
|
||||
addMessage(msg);
|
||||
emit sendMessage(msg);
|
||||
}
|
||||
if (filesToAttach.size() > 0) {
|
||||
for (Badge* badge : filesToAttach) {
|
||||
Shared::Message msg;
|
||||
if (isMuc) {
|
||||
msg.setType(Shared::Message::groupChat);
|
||||
} else {
|
||||
msg.setType(Shared::Message::chat);
|
||||
msg.setToResource(activePalResource);
|
||||
}
|
||||
msg.setFrom(account->getFullJid());
|
||||
msg.setToJid(palJid);
|
||||
msg.setOutgoing(true);
|
||||
msg.generateRandomId();
|
||||
msg.setCurrentTime();
|
||||
Shared::Message msg = createMessage();
|
||||
line->appendMessageWithUpload(msg, badge->id);
|
||||
usleep(1000); //this is required for the messages not to have equal time when appending into messageline
|
||||
}
|
||||
@ -486,6 +478,16 @@ void Conversation::dropEvent(QDropEvent* event)
|
||||
overlay->hide();
|
||||
}
|
||||
|
||||
Shared::Message Conversation::createMessage() const
|
||||
{
|
||||
Shared::Message msg;
|
||||
msg.setOutgoing(true);
|
||||
msg.generateRandomId();
|
||||
msg.setCurrentTime();
|
||||
msg.setState(Shared::Message::State::pending);
|
||||
return msg;
|
||||
}
|
||||
|
||||
bool VisibilityCatcher::eventFilter(QObject* obj, QEvent* event)
|
||||
{
|
||||
if (event->type() == QEvent::Show) {
|
||||
|
@ -102,7 +102,7 @@ signals:
|
||||
protected:
|
||||
virtual void setName(const QString& name);
|
||||
void applyVisualEffects();
|
||||
virtual void handleSendMessage(const QString& text) = 0;
|
||||
virtual Shared::Message createMessage() const;
|
||||
void setStatus(const QString& status);
|
||||
void addAttachedFile(const QString& path);
|
||||
void removeAttachedFile(Badge* badge);
|
||||
|
@ -46,20 +46,14 @@ Room::~Room()
|
||||
{
|
||||
}
|
||||
|
||||
void Room::handleSendMessage(const QString& text)
|
||||
Shared::Message Room::createMessage() const
|
||||
{
|
||||
Shared::Message msg(Shared::Message::groupChat);
|
||||
Shared::Message msg = Conversation::createMessage();
|
||||
msg.setType(Shared::Message::groupChat);
|
||||
msg.setFromJid(room->getJid());
|
||||
msg.setFromResource(room->getNick());
|
||||
msg.setToJid(palJid);
|
||||
//msg.setToResource(activePalResource);
|
||||
msg.setBody(text);
|
||||
msg.setOutgoing(true);
|
||||
msg.generateRandomId();
|
||||
msg.setCurrentTime();
|
||||
msg.setState(Shared::Message::State::pending);
|
||||
addMessage(msg);
|
||||
emit sendMessage(msg);
|
||||
return msg;
|
||||
}
|
||||
|
||||
bool Room::autoJoined() const
|
||||
|
@ -40,7 +40,7 @@ protected slots:
|
||||
void onParticipantLeft(const QString& name);
|
||||
|
||||
protected:
|
||||
void handleSendMessage(const QString & text) override;
|
||||
Shared::Message createMessage() const override;
|
||||
|
||||
private:
|
||||
Models::Room* room;
|
||||
|
Loading…
Reference in New Issue
Block a user