initial functionality of mucs

This commit is contained in:
Blue 2019-08-28 14:40:55 +03:00
parent e2cc1bae2e
commit 023494de0b
23 changed files with 347 additions and 119 deletions

View file

@ -70,3 +70,37 @@ void Chat::setStatus(const QString& status)
{
statusLabel->setText(status);
}
void Chat::handleSendMessage(const QString& text)
{
Shared::Message msg(Shared::Message::chat);
msg.setFromJid(myJid);
msg.setFromResource(myResource);
msg.setToJid(palJid);
msg.setToResource(activePalResource);
msg.setBody(text);
msg.setOutgoing(true);
msg.generateRandomId();
msg.setCurrentTime();
addMessage(msg);
emit sendMessage(msg);
}
void Chat::addMessage(const Shared::Message& data)
{
Conversation::addMessage(data);
if (!data.getOutgoing()) { //TODO need to check if that was the last message
const QString& res = data.getPenPalResource();
if (res.size() > 0) {
setPalResource(res);
}
}
}
void Chat::setName(const QString& name)
{
Conversation::setName(name);
line->setPalName(getJid(), name);
}

View file

@ -32,9 +32,15 @@ class Chat : public Conversation
public:
Chat(Models::Contact* p_contact, QWidget* parent = 0);
~Chat();
void addMessage(const Shared::Message & data) override;
protected slots:
void onContactChanged(Models::Item* item, int row, int col);
void handleSendMessage(const QString & text) override;
protected:
void setName(const QString & name) override;
private:
void updateState();

View file

@ -97,7 +97,6 @@ void Conversation::setName(const QString& name)
{
m_ui->nameLabel->setText(name);
setWindowTitle(name);
line->setPalName(getJid(), name);
}
QString Conversation::getAccount() const
@ -119,13 +118,6 @@ void Conversation::addMessage(const Shared::Message& data)
if (place == MessageLine::invalid) {
return;
}
if (!data.getOutgoing()) {
const QString& res = data.getPenPalResource();
if (res.size() > 0) {
setPalResource(res);
}
}
}
KeyEnterReceiver::KeyEnterReceiver(QObject* parent): QObject(parent), ownEvent(false) {}
@ -173,17 +165,7 @@ void Conversation::onEnterPressed()
if (body.size() > 0) {
m_ui->messageEditor->clear();
Shared::Message msg(Shared::Message::chat);
msg.setFromJid(myJid);
msg.setFromResource(myResource);
msg.setToJid(palJid);
msg.setToResource(activePalResource);
msg.setBody(body);
msg.setOutgoing(true);
msg.generateRandomId();
msg.setCurrentTime();
addMessage(msg);
emit sendMessage(msg);
handleSendMessage(body);
}
}

View file

@ -52,7 +52,7 @@ public:
QString getJid() const;
QString getAccount() const;
QString getPalResource() const;
void addMessage(const Shared::Message& data);
virtual void addMessage(const Shared::Message& data);
void setPalResource(const QString& res);
void responseArchive(const std::list<Shared::Message> list);
@ -64,8 +64,9 @@ signals:
void shown();
protected:
void setName(const QString& name);
virtual void setName(const QString& name);
void applyVisualEffects();
virtual void handleSendMessage(const QString& text) = 0;
protected slots:
void onEnterPressed();

View file

@ -30,7 +30,8 @@ MessageLine::MessageLine(QWidget* parent):
layout(new QVBoxLayout()),
myName(),
palNames(),
views()
views(),
room(false)
{
setLayout(layout);
setBackgroundRole(QPalette::Base);
@ -44,6 +45,11 @@ MessageLine::~MessageLine()
}
}
void MessageLine::setRoom(bool p_room)
{
room = p_room;
}
MessageLine::Position MessageLine::message(const Shared::Message& msg)
{
QString id = msg.getId();
@ -110,25 +116,40 @@ MessageLine::Position MessageLine::message(const Shared::Message& msg)
message->setGraphicsEffect(effect);
if (msg.getOutgoing()) {
//body->setAlignment(Qt::AlignRight);
sender->setAlignment(Qt::AlignRight);
time->setAlignment(Qt::AlignRight);
sender->setText(myName);
hBox->addStretch();
hBox->addWidget(message);
} else {
QString jid = msg.getFromJid();
std::map<QString, QString>::iterator itr = palNames.find(jid);
if (itr != palNames.end()) {
sender->setText(itr->second);
if (room) {
if (msg.getFromResource() == myName) {
//body->setAlignment(Qt::AlignRight);
sender->setAlignment(Qt::AlignRight);
time->setAlignment(Qt::AlignRight);
sender->setText(myName);
hBox->addStretch();
hBox->addWidget(message);
} else {
sender->setText(jid);
sender->setText(msg.getFromResource());
hBox->addWidget(message);
hBox->addStretch();
}
} else {
if (msg.getOutgoing()) {
//body->setAlignment(Qt::AlignRight);
sender->setAlignment(Qt::AlignRight);
time->setAlignment(Qt::AlignRight);
sender->setText(myName);
hBox->addStretch();
hBox->addWidget(message);
} else {
QString jid = msg.getFromJid();
std::map<QString, QString>::iterator itr = palNames.find(jid);
if (itr != palNames.end()) {
sender->setText(itr->second);
} else {
sender->setText(jid);
}
hBox->addWidget(message);
hBox->addStretch();
}
hBox->addWidget(message);
hBox->addStretch();
}
if (res == end) {
layout->addLayout(hBox);
} else {

View file

@ -45,6 +45,7 @@ public:
QString firstMessageId() const;
void showBusyIndicator();
void hideBusyIndicator();
void setRoom(bool p_room);
signals:
void resize(int amount);
@ -70,6 +71,7 @@ private:
QString myName;
std::map<QString, QString> palNames;
std::deque<QHBoxLayout*> views;
bool room;
};
#endif // MESSAGELINE_H

46
ui/widgets/room.cpp Normal file
View file

@ -0,0 +1,46 @@
/*
* 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/>.
*/
#include "room.h"
Room::Room(Models::Room* p_room, QWidget* parent):
Conversation(p_room->getAccountJid(), p_room->getAccountResource(), p_room->getJid(), "", p_room->getAccountName(), parent),
room(p_room)
{
setName(p_room->getName());
line->setMyName(room->getNick());
line->setRoom(true);
}
Room::~Room()
{
}
void Room::handleSendMessage(const QString& text)
{
Shared::Message msg(Shared::Message::groupChat);
msg.setFromJid(myJid);
msg.setFromResource(myResource);
msg.setToJid(palJid);
//msg.setToResource(activePalResource);
msg.setBody(text);
msg.setOutgoing(true);
msg.generateRandomId();
msg.setCurrentTime();
emit sendMessage(msg);
}

43
ui/widgets/room.h Normal file
View file

@ -0,0 +1,43 @@
/*
* 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 ROOM_H
#define ROOM_H
#include "conversation.h"
#include "../models/room.h"
/**
* @todo write docs
*/
class Room : public Conversation
{
Q_OBJECT
public:
Room(Models::Room* p_room, QWidget* parent = 0);
~Room();
protected:
void handleSendMessage(const QString & text) override;
private:
Models::Room* room;
};
#endif // ROOM_H