now we have avatars in muc chats

This commit is contained in:
Blue 2019-12-31 21:14:12 +03:00
parent 55703c2007
commit 52efc2b1a4
8 changed files with 94 additions and 13 deletions

View File

@ -276,6 +276,7 @@ void Models::Room::addParticipant(const QString& p_name, const QMap<QString, QVa
part->setName(p_name); part->setName(p_name);
participants.insert(std::make_pair(p_name, part)); participants.insert(std::make_pair(p_name, part));
appendChild(part); appendChild(part);
emit participantJoined(*part);
} }
} }
@ -299,6 +300,7 @@ void Models::Room::removeParticipant(const QString& p_name)
participants.erase(itr); participants.erase(itr);
removeChild(p->row()); removeChild(p->row());
p->deleteLater(); p->deleteLater();
emit participantLeft(p_name);
} }
} }
@ -373,3 +375,24 @@ void Models::Room::setAvatarState(unsigned int p_state)
qDebug() << "An attempt to set invalid avatar state" << p_state << "to the room" << jid << ", skipping"; qDebug() << "An attempt to set invalid avatar state" << p_state << "to the room" << jid << ", skipping";
} }
} }
std::map<QString, const Models::Participant &> Models::Room::getParticipants() const
{
std::map<QString, const Models::Participant&> result;
for (std::pair<QString, Models::Participant*> pair : participants) {
result.emplace(pair.first, *(pair.second));
}
return result;
}
QString Models::Room::getParticipantIconPath(const QString& name) const
{
std::map<QString, Models::Participant*>::const_iterator itr = participants.find(name);
if (itr == participants.end()) {
return "";
}
return itr->second->getAvatarPath();
}

View File

@ -71,6 +71,12 @@ public:
QString getDisplayedName() const override; QString getDisplayedName() const override;
Shared::Avatar getAvatarState() const; Shared::Avatar getAvatarState() const;
QString getAvatarPath() const; QString getAvatarPath() const;
std::map<QString, const Participant&> getParticipants() const;
QString getParticipantIconPath(const QString& name) const;
signals:
void participantJoined(const Participant& participant);
void participantLeft(const QString& name);
private: private:
void handleParticipantUpdate(std::map<QString, Participant*>::const_iterator itr, const QMap<QString, QVariant>& data); void handleParticipantUpdate(std::map<QString, Participant*>::const_iterator itr, const QMap<QString, QVariant>& data);

View File

@ -949,7 +949,7 @@ bool Models::Roster::groupHasContact(const QString& account, const QString& grou
} }
} }
QString Models::Roster::getContactIconPath(const QString& account, const QString& jid) QString Models::Roster::getContactIconPath(const QString& account, const QString& jid, const QString& resource)
{ {
ElId id(account, jid); ElId id(account, jid);
std::multimap<ElId, Contact*>::const_iterator cItr = contacts.find(id); std::multimap<ElId, Contact*>::const_iterator cItr = contacts.find(id);
@ -959,7 +959,7 @@ QString Models::Roster::getContactIconPath(const QString& account, const QString
if (rItr == rooms.end()) { if (rItr == rooms.end()) {
qDebug() << "An attempt to get an icon path of non existing contact" << account << ":" << jid << ", returning empty value"; qDebug() << "An attempt to get an icon path of non existing contact" << account << ":" << jid << ", returning empty value";
} else { } else {
//path = rItr->second->getRoomName(); path = rItr->second->getParticipantIconPath(resource);
} }
} else { } else {
if (cItr->second->getAvatarState() != Shared::Avatar::empty) { if (cItr->second->getAvatarState() != Shared::Avatar::empty) {

View File

@ -73,7 +73,7 @@ public:
std::deque<QString> groupList(const QString& account) const; std::deque<QString> groupList(const QString& account) const;
bool groupHasContact(const QString& account, const QString& group, const QString& contactJID) const; bool groupHasContact(const QString& account, const QString& group, const QString& contactJID) const;
QString getContactIconPath(const QString& account, const QString& jid); QString getContactIconPath(const QString& account, const QString& jid, const QString& resource);
Account* getAccount(const QString& name); Account* getAccount(const QString& name);
QModelIndex getAccountIndex(const QString& name); QModelIndex getAccountIndex(const QString& name);
QModelIndex getGroupIndex(const QString& account, const QString& name); QModelIndex getGroupIndex(const QString& account, const QString& name);

View File

@ -230,7 +230,6 @@ void Squawk::addGroup(const QString& account, const QString& name)
settings.beginGroup(account); settings.beginGroup(account);
if (settings.value("expanded", false).toBool()) { if (settings.value("expanded", false).toBool()) {
QModelIndex ind = rosterModel.getAccountIndex(account); QModelIndex ind = rosterModel.getAccountIndex(account);
qDebug() << "expanding account " << ind.data();
m_ui->roster->expand(ind); m_ui->roster->expand(ind);
if (settings.value(name + "/expanded", false).toBool()) { if (settings.value(name + "/expanded", false).toBool()) {
m_ui->roster->expand(rosterModel.getGroupIndex(account, name)); m_ui->roster->expand(rosterModel.getGroupIndex(account, name));
@ -497,21 +496,28 @@ void Squawk::accountMessage(const QString& account, const Shared::Message& data)
void Squawk::notify(const QString& account, const Shared::Message& msg) void Squawk::notify(const QString& account, const Shared::Message& msg)
{ {
QString name = QString(rosterModel.getContactName(account, msg.getPenPalJid())); QString name = QString(rosterModel.getContactName(account, msg.getPenPalJid()));
QString path = QString(rosterModel.getContactIconPath(account, msg.getPenPalJid())); QString path = QString(rosterModel.getContactIconPath(account, msg.getPenPalJid(), msg.getPenPalResource()));
QVariantList args; QVariantList args;
args << QString(QCoreApplication::applicationName()); args << QString(QCoreApplication::applicationName());
args << QVariant(QVariant::UInt); //TODO some normal id args << QVariant(QVariant::UInt); //TODO some normal id
if (path.size() > 0) { if (path.size() > 0) {
args << path; args << path;
} else { } else {
args << QString("mail-message"); args << QString("mail-message"); //TODO should here better be unknown user icon?
} }
if (msg.getType() == Shared::Message::groupChat) { if (msg.getType() == Shared::Message::groupChat) {
args << msg.getFromResource() + " from " + name; args << msg.getFromResource() + " from " + name;
} else { } else {
args << name; args << name;
} }
args << QString(msg.getBody());
QString body(msg.getBody());
QString oob(msg.getOutOfBandUrl());
if (body == oob) {
body = tr("Attached file");
}
args << body;
args << QStringList(); args << QStringList();
args << QVariantMap(); args << QVariantMap();
args << 3000; args << 3000;

View File

@ -74,6 +74,10 @@ MessageLine::Position MessageLine::message(const Shared::Message& msg, bool forc
outgoing = true; outgoing = true;
} else { } else {
sender = msg.getFromResource(); sender = msg.getFromResource();
std::map<QString, QString>::iterator aItr = palAvatars.find(sender);
if (aItr != palAvatars.end()) {
aPath = aItr->second;
}
outgoing = false; outgoing = false;
} }
} else { } else {
@ -111,17 +115,19 @@ MessageLine::Position MessageLine::message(const Shared::Message& msg, bool forc
if (outgoing) { if (outgoing) {
myMessages.insert(std::make_pair(id, message)); myMessages.insert(std::make_pair(id, message));
} else { } else {
QString senderId;
if (room) { if (room) {
senderId = sender;
} else { } else {
QString jid = msg.getFromJid(); QString jid = msg.getFromJid();
std::map<QString, Index>::iterator pItr = palMessages.find(jid); }
std::map<QString, Index>::iterator pItr = palMessages.find(senderId);
if (pItr == palMessages.end()) { if (pItr == palMessages.end()) {
pItr = palMessages.insert(std::make_pair(jid, Index())).first; pItr = palMessages.insert(std::make_pair(senderId, Index())).first;
} }
pItr->second.insert(std::make_pair(id, message)); pItr->second.insert(std::make_pair(id, message));
} }
}
messageIndex.insert(std::make_pair(id, message)); messageIndex.insert(std::make_pair(id, message));
unsigned long index = std::distance<Order::const_iterator>(messageOrder.begin(), result.first); //need to make with binary indexed tree unsigned long index = std::distance<Order::const_iterator>(messageOrder.begin(), result.first); //need to make with binary indexed tree
Position res = invalid; Position res = invalid;

View File

@ -28,6 +28,16 @@ Room::Room(Models::Account* acc, Models::Room* p_room, QWidget* parent):
setAvatar(room->getAvatarPath()); setAvatar(room->getAvatarPath());
connect(room, &Models::Room::childChanged, this, &Room::onRoomChanged); connect(room, &Models::Room::childChanged, this, &Room::onRoomChanged);
connect(room, &Models::Room::participantJoined, this, &Room::onParticipantJoined);
connect(room, &Models::Room::participantLeft, this, &Room::onParticipantLeft);
std::map<QString, const Models::Participant&> members = room->getParticipants();
for (std::pair<QString, const Models::Participant&> pair : members) {
QString aPath = pair.second.getAvatarPath();
if (aPath.size() > 0) {
line->setPalAvatar(pair.first, aPath);
}
}
} }
Room::~Room() Room::~Room()
@ -62,6 +72,34 @@ void Room::onRoomChanged(Models::Item* item, int row, int col)
case 6: case 6:
setStatus(room->getSubject()); setStatus(room->getSubject());
break; break;
case 8:
setAvatar(room->getAvatarPath());
break;
}
} else {
switch (col) {
case 7: {
Models::Participant* mem = static_cast<Models::Participant*>(item);
QString aPath = mem->getAvatarPath();
if (aPath.size() > 0) {
line->setPalAvatar(mem->getName(), aPath);
} else {
line->dropPalAvatar(mem->getName());
} }
} }
} }
}
}
void Room::onParticipantJoined(const Models::Participant& participant)
{
QString aPath = participant.getAvatarPath();
if (aPath.size() > 0) {
line->setPalAvatar(participant.getName(), aPath);
}
}
void Room::onParticipantLeft(const QString& name)
{
line->dropPalAvatar(name);
}

View File

@ -36,6 +36,8 @@ public:
protected slots: protected slots:
void onRoomChanged(Models::Item* item, int row, int col); void onRoomChanged(Models::Item* item, int row, int col);
void onParticipantJoined(const Models::Participant& participant);
void onParticipantLeft(const QString& name);
protected: protected:
void handleSendMessage(const QString & text) override; void handleSendMessage(const QString & text) override;