forked from blue/squawk
Muc participants are displayed now in the roster
This commit is contained in:
parent
70f9739cf5
commit
5547d78608
16 changed files with 350 additions and 7 deletions
|
@ -38,7 +38,7 @@ Models::AbstractParticipant::~AbstractParticipant()
|
|||
|
||||
int Models::AbstractParticipant::columnCount() const
|
||||
{
|
||||
return 5;
|
||||
return 4;
|
||||
}
|
||||
|
||||
QVariant Models::AbstractParticipant::data(int column) const
|
||||
|
|
115
ui/models/participant.cpp
Normal file
115
ui/models/participant.cpp
Normal file
|
@ -0,0 +1,115 @@
|
|||
/*
|
||||
* 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 "participant.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
Models::Participant::Participant(const QMap<QString, QVariant>& data, Models::Item* parentItem):
|
||||
AbstractParticipant(participant, data, parentItem),
|
||||
affiliation(Shared::Affiliation::unspecified),
|
||||
role(Shared::Role::unspecified)
|
||||
{
|
||||
QMap<QString, QVariant>::const_iterator itr = data.find("affiliation");
|
||||
if (itr != data.end()) {
|
||||
setAffiliation(itr.value().toUInt());
|
||||
}
|
||||
|
||||
itr = data.find("role");
|
||||
if (itr != data.end()) {
|
||||
setRole(itr.value().toUInt());
|
||||
}
|
||||
}
|
||||
|
||||
Models::Participant::~Participant()
|
||||
{
|
||||
}
|
||||
|
||||
int Models::Participant::columnCount() const
|
||||
{
|
||||
return 6;
|
||||
}
|
||||
|
||||
QVariant Models::Participant::data(int column) const
|
||||
{
|
||||
switch (column) {
|
||||
case 4:
|
||||
return static_cast<uint8_t>(affiliation);
|
||||
case 5:
|
||||
return static_cast<uint8_t>(role);
|
||||
default:
|
||||
return AbstractParticipant::data(column);
|
||||
}
|
||||
}
|
||||
|
||||
void Models::Participant::update(const QString& key, const QVariant& value)
|
||||
{
|
||||
if (key == "affiliation") {
|
||||
setAffiliation(value.toUInt());
|
||||
} else if (key == "role") {
|
||||
setRole(value.toUInt());
|
||||
} else {
|
||||
AbstractParticipant::update(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
Shared::Affiliation Models::Participant::getAffiliation() const
|
||||
{
|
||||
return affiliation;
|
||||
}
|
||||
|
||||
void Models::Participant::setAffiliation(Shared::Affiliation p_aff)
|
||||
{
|
||||
if (p_aff != affiliation) {
|
||||
affiliation = p_aff;
|
||||
changed(4);
|
||||
}
|
||||
}
|
||||
|
||||
void Models::Participant::setAffiliation(unsigned int aff)
|
||||
{
|
||||
if (aff <= static_cast<uint8_t>(Shared::affiliationHighest)) {
|
||||
Shared::Affiliation affil = static_cast<Shared::Affiliation>(aff);
|
||||
setAffiliation(affil);
|
||||
} else {
|
||||
qDebug() << "An attempt to set wrong affiliation" << aff << "to the room participant" << name;
|
||||
}
|
||||
}
|
||||
|
||||
Shared::Role Models::Participant::getRole() const
|
||||
{
|
||||
return role;
|
||||
}
|
||||
|
||||
void Models::Participant::setRole(Shared::Role p_role)
|
||||
{
|
||||
if (p_role != role) {
|
||||
role = p_role;
|
||||
changed(5);
|
||||
}
|
||||
}
|
||||
|
||||
void Models::Participant::setRole(unsigned int p_role)
|
||||
{
|
||||
if (p_role <= static_cast<uint8_t>(Shared::roleHighest)) {
|
||||
Shared::Role r = static_cast<Shared::Role>(p_role);
|
||||
setRole(r);
|
||||
} else {
|
||||
qDebug() << "An attempt to set wrong role" << p_role << "to the room participant" << name;
|
||||
}
|
||||
}
|
52
ui/models/participant.h
Normal file
52
ui/models/participant.h
Normal file
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* 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 MODELS_PARTICIPANT_H
|
||||
#define MODELS_PARTICIPANT_H
|
||||
|
||||
#include "abstractparticipant.h"
|
||||
|
||||
namespace Models {
|
||||
|
||||
class Participant : public Models::AbstractParticipant
|
||||
{
|
||||
public:
|
||||
Participant(const QMap<QString, QVariant> &data, Item *parentItem = 0);
|
||||
~Participant();
|
||||
|
||||
int columnCount() const override;
|
||||
QVariant data(int column) const override;
|
||||
|
||||
void update(const QString& key, const QVariant& value) override;
|
||||
|
||||
Shared::Affiliation getAffiliation() const;
|
||||
void setAffiliation(Shared::Affiliation p_aff);
|
||||
void setAffiliation(unsigned int aff);
|
||||
|
||||
Shared::Role getRole() const;
|
||||
void setRole(Shared::Role p_role);
|
||||
void setRole(unsigned int role);
|
||||
|
||||
private:
|
||||
Shared::Affiliation affiliation;
|
||||
Shared::Role role;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // MODELS_PARTICIPANT_H
|
|
@ -28,6 +28,11 @@ Models::Presence::~Presence()
|
|||
{
|
||||
}
|
||||
|
||||
int Models::Presence::columnCount() const
|
||||
{
|
||||
return 5;
|
||||
}
|
||||
|
||||
QVariant Models::Presence::data(int column) const
|
||||
{
|
||||
switch (column) {
|
||||
|
|
|
@ -33,7 +33,8 @@ public:
|
|||
typedef std::deque<Shared::Message> Messages;
|
||||
explicit Presence(const QMap<QString, QVariant> &data, Item *parentItem = 0);
|
||||
~Presence();
|
||||
|
||||
|
||||
int columnCount() const override;
|
||||
QVariant data(int column) const override;
|
||||
|
||||
QIcon getStatusIcon(bool big = false) const override;
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
#include "room.h"
|
||||
#include <QIcon>
|
||||
#include <QDebug>
|
||||
|
||||
Models::Room::Room(const QString& p_jid, const QMap<QString, QVariant>& data, Models::Item* parentItem):
|
||||
Item(room, data, parentItem),
|
||||
|
@ -25,7 +26,8 @@ Models::Room::Room(const QString& p_jid, const QMap<QString, QVariant>& data, Mo
|
|||
joined(false),
|
||||
jid(p_jid),
|
||||
nick(""),
|
||||
messages()
|
||||
messages(),
|
||||
participants()
|
||||
{
|
||||
QMap<QString, QVariant>::const_iterator itr = data.find("autoJoin");
|
||||
if (itr != data.end()) {
|
||||
|
@ -127,6 +129,9 @@ void Models::Room::setJoined(bool p_joined)
|
|||
if (joined != p_joined) {
|
||||
joined = p_joined;
|
||||
changed(2);
|
||||
if (!joined) {
|
||||
toOfflineState();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -217,3 +222,67 @@ void Models::Room::getMessages(Models::Room::Messages& container) const
|
|||
container.push_back(msg);
|
||||
}
|
||||
}
|
||||
|
||||
void Models::Room::toOfflineState()
|
||||
{
|
||||
emit childIsAboutToBeRemoved(this, 0, childItems.size());
|
||||
for (int i = 0; i < childItems.size(); ++i) {
|
||||
Item* item = childItems[i];
|
||||
disconnect(item, SIGNAL(childChanged(Models::Item*, int, int)), this, SLOT(refresh()));
|
||||
Item::_removeChild(i);
|
||||
item->deleteLater();
|
||||
}
|
||||
childItems.clear();
|
||||
participants.clear();
|
||||
emit childRemoved();
|
||||
}
|
||||
|
||||
void Models::Room::addParticipant(const QString& p_name, const QMap<QString, QVariant>& data)
|
||||
{
|
||||
std::map<QString, Participant*>::const_iterator itr = participants.find(p_name);
|
||||
if (itr != participants.end()) {
|
||||
qDebug() << "An attempt to add already existing participant" << p_name << "to the room" << name << ", updating instead";
|
||||
handleParticipantUpdate(itr, data);
|
||||
} else {
|
||||
Participant* part = new Participant(data);
|
||||
part->setName(p_name);
|
||||
participants.insert(std::make_pair(p_name, part));
|
||||
appendChild(part);
|
||||
}
|
||||
}
|
||||
|
||||
void Models::Room::changeParticipant(const QString& p_name, const QMap<QString, QVariant>& data)
|
||||
{
|
||||
std::map<QString, Participant*>::const_iterator itr = participants.find(p_name);
|
||||
if (itr == participants.end()) {
|
||||
qDebug() << "An attempt to change non existing participant" << p_name << "from the room" << name << ", skipping";
|
||||
} else {
|
||||
handleParticipantUpdate(itr, data);
|
||||
}
|
||||
}
|
||||
|
||||
void Models::Room::removeParticipant(const QString& p_name)
|
||||
{
|
||||
std::map<QString, Participant*>::const_iterator itr = participants.find(p_name);
|
||||
if (itr == participants.end()) {
|
||||
qDebug() << "An attempt to remove non existing participant" << p_name << "from the room" << name << ", skipping";
|
||||
} else {
|
||||
Participant* p = itr->second;
|
||||
participants.erase(itr);
|
||||
removeChild(p->row());
|
||||
p->deleteLater();
|
||||
}
|
||||
}
|
||||
|
||||
void Models::Room::handleParticipantUpdate(std::map<QString, Participant*>::const_iterator itr, const QMap<QString, QVariant>& data)
|
||||
{
|
||||
Participant* part = itr->second;
|
||||
const QString& p_name = itr->first;
|
||||
for (QMap<QString, QVariant>::const_iterator itr = data.begin(), end = data.end(); itr != end; ++itr) {
|
||||
part->update(itr.key(), itr.value());
|
||||
}
|
||||
if (p_name != part->getName()) {
|
||||
participants.erase(itr);
|
||||
participants.insert(std::make_pair(part->getName(), part));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#define MODELS_ROOM_H
|
||||
|
||||
#include "item.h"
|
||||
#include "participant.h"
|
||||
#include "../global.h"
|
||||
|
||||
namespace Models {
|
||||
|
@ -59,8 +60,15 @@ public:
|
|||
unsigned int getMessagesCount() const;
|
||||
void dropMessages();
|
||||
void getMessages(Messages& container) const;
|
||||
|
||||
protected:
|
||||
|
||||
void addParticipant(const QString& name, const QMap<QString, QVariant>& data);
|
||||
void changeParticipant(const QString& name, const QMap<QString, QVariant>& data);
|
||||
void removeParticipant(const QString& name);
|
||||
|
||||
void toOfflineState() override;
|
||||
|
||||
private:
|
||||
void handleParticipantUpdate(std::map<QString, Participant*>::const_iterator itr, const QMap<QString, QVariant>& data);
|
||||
|
||||
private:
|
||||
bool autoJoin;
|
||||
|
@ -68,6 +76,7 @@ private:
|
|||
QString jid;
|
||||
QString nick;
|
||||
Messages messages;
|
||||
std::map<QString, Participant*> participants;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -783,3 +783,39 @@ void Models::Roster::removeRoom(const QString& account, const QString jid)
|
|||
room->deleteLater();
|
||||
rooms.erase(itr);
|
||||
}
|
||||
|
||||
void Models::Roster::addRoomParticipant(const QString& account, const QString& jid, const QString& name, const QMap<QString, QVariant>& data)
|
||||
{
|
||||
ElId id = {account, jid};
|
||||
std::map<ElId, Room*>::const_iterator itr = rooms.find(id);
|
||||
if (itr == rooms.end()) {
|
||||
qDebug() << "An attempt to add participant" << name << "non existing room" << jid << "of an account" << account << ", skipping";
|
||||
return;
|
||||
} else {
|
||||
itr->second->addParticipant(name, data);
|
||||
}
|
||||
}
|
||||
|
||||
void Models::Roster::changeRoomParticipant(const QString& account, const QString& jid, const QString& name, const QMap<QString, QVariant>& data)
|
||||
{
|
||||
ElId id = {account, jid};
|
||||
std::map<ElId, Room*>::const_iterator itr = rooms.find(id);
|
||||
if (itr == rooms.end()) {
|
||||
qDebug() << "An attempt change participant" << name << "of non existing room" << jid << "of an account" << account << ", skipping";
|
||||
return;
|
||||
} else {
|
||||
itr->second->changeParticipant(name, data);
|
||||
}
|
||||
}
|
||||
|
||||
void Models::Roster::removeRoomParticipant(const QString& account, const QString& jid, const QString& name)
|
||||
{
|
||||
ElId id = {account, jid};
|
||||
std::map<ElId, Room*>::const_iterator itr = rooms.find(id);
|
||||
if (itr == rooms.end()) {
|
||||
qDebug() << "An attempt remove participant" << name << "from non existing room" << jid << "of an account" << account << ", skipping";
|
||||
return;
|
||||
} else {
|
||||
itr->second->removeParticipant(name);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,6 +58,9 @@ public:
|
|||
void addRoom(const QString& account, const QString jid, const QMap<QString, QVariant>& data);
|
||||
void changeRoom(const QString& account, const QString jid, const QMap<QString, QVariant>& data);
|
||||
void removeRoom(const QString& account, const QString jid);
|
||||
void addRoomParticipant(const QString& account, const QString& jid, const QString& name, const QMap<QString, QVariant>& data);
|
||||
void changeRoomParticipant(const QString& account, const QString& jid, const QString& name, const QMap<QString, QVariant>& data);
|
||||
void removeRoomParticipant(const QString& account, const QString& jid, const QString& name);
|
||||
QString getContactName(const QString& account, const QString& jid);
|
||||
|
||||
QVariant data ( const QModelIndex& index, int role ) const override;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue