forked from blue/squawk
first compiling prototype, doesnt work yet
This commit is contained in:
parent
ef1a9846bf
commit
38159eafeb
21 changed files with 662 additions and 734 deletions
|
@ -17,55 +17,26 @@
|
|||
*/
|
||||
|
||||
#include "contact.h"
|
||||
#include "account.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
Models::Contact::Contact(const Account* acc, const QString& p_jid ,const QMap<QString, QVariant> &data, Item *parentItem):
|
||||
Item(Item::contact, data, parentItem),
|
||||
jid(p_jid),
|
||||
Element(Item::contact, acc, p_jid, data, parentItem),
|
||||
availability(Shared::Availability::offline),
|
||||
state(Shared::SubscriptionState::none),
|
||||
avatarState(Shared::Avatar::empty),
|
||||
presences(),
|
||||
messages(),
|
||||
childMessages(0),
|
||||
status(),
|
||||
avatarPath(),
|
||||
account(acc)
|
||||
status()
|
||||
{
|
||||
QMap<QString, QVariant>::const_iterator itr = data.find("state");
|
||||
if (itr != data.end()) {
|
||||
setState(itr.value().toUInt());
|
||||
}
|
||||
|
||||
itr = data.find("avatarState");
|
||||
if (itr != data.end()) {
|
||||
setAvatarState(itr.value().toUInt());
|
||||
}
|
||||
itr = data.find("avatarPath");
|
||||
if (itr != data.end()) {
|
||||
setAvatarPath(itr.value().toString());
|
||||
}
|
||||
}
|
||||
|
||||
Models::Contact::~Contact()
|
||||
{
|
||||
}
|
||||
|
||||
QString Models::Contact::getJid() const
|
||||
{
|
||||
return jid;
|
||||
}
|
||||
|
||||
void Models::Contact::setJid(const QString p_jid)
|
||||
{
|
||||
if (jid != p_jid) {
|
||||
jid = p_jid;
|
||||
changed(1);
|
||||
}
|
||||
}
|
||||
|
||||
void Models::Contact::setAvailability(unsigned int p_state)
|
||||
{
|
||||
setAvailability(Shared::Global::fromInt<Shared::Availability>(p_state));
|
||||
|
@ -144,16 +115,12 @@ void Models::Contact::update(const QString& field, const QVariant& value)
|
|||
{
|
||||
if (field == "name") {
|
||||
setName(value.toString());
|
||||
} else if (field == "jid") {
|
||||
setJid(value.toString());
|
||||
} else if (field == "availability") {
|
||||
setAvailability(value.toUInt());
|
||||
} else if (field == "state") {
|
||||
setState(value.toUInt());
|
||||
} else if (field == "avatarState") {
|
||||
setAvatarState(value.toUInt());
|
||||
} else if (field == "avatarPath") {
|
||||
setAvatarPath(value.toString());
|
||||
} else {
|
||||
Element::update(field, value);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -192,11 +159,9 @@ void Models::Contact::refresh()
|
|||
{
|
||||
QDateTime lastActivity;
|
||||
Presence* presence = 0;
|
||||
unsigned int count = 0;
|
||||
for (QMap<QString, Presence*>::iterator itr = presences.begin(), end = presences.end(); itr != end; ++itr) {
|
||||
Presence* pr = itr.value();
|
||||
QDateTime la = pr->getLastActivity();
|
||||
count += pr->getMessagesCount();
|
||||
|
||||
if (la > lastActivity) {
|
||||
lastActivity = la;
|
||||
|
@ -211,11 +176,6 @@ void Models::Contact::refresh()
|
|||
setAvailability(Shared::Availability::offline);
|
||||
setStatus("");
|
||||
}
|
||||
|
||||
if (childMessages != count) {
|
||||
childMessages = count;
|
||||
changed(4);
|
||||
}
|
||||
}
|
||||
|
||||
void Models::Contact::_removeChild(int index)
|
||||
|
@ -257,81 +217,6 @@ QIcon Models::Contact::getStatusIcon(bool big) const
|
|||
}
|
||||
}
|
||||
|
||||
void Models::Contact::addMessage(const Shared::Message& data)
|
||||
{
|
||||
const QString& res = data.getPenPalResource();
|
||||
if (res.size() > 0) {
|
||||
QMap<QString, Presence*>::iterator itr = presences.find(res);
|
||||
if (itr == presences.end()) {
|
||||
// this is actually the place when I can spot someone's invisible presence, and there is nothing criminal in it, cuz the sender sent us a message
|
||||
// therefore he have revealed himself
|
||||
// the only issue is to find out when the sender is gone offline
|
||||
Presence* pr = new Presence({});
|
||||
pr->setName(res);
|
||||
pr->setAvailability(Shared::Availability::invisible);
|
||||
pr->setLastActivity(QDateTime::currentDateTimeUtc());
|
||||
presences.insert(res, pr);
|
||||
appendChild(pr);
|
||||
pr->addMessage(data);
|
||||
return;
|
||||
}
|
||||
itr.value()->addMessage(data);
|
||||
} else {
|
||||
messages.emplace_back(data);
|
||||
changed(4);
|
||||
}
|
||||
}
|
||||
|
||||
void Models::Contact::changeMessage(const QString& id, const QMap<QString, QVariant>& data)
|
||||
{
|
||||
|
||||
bool found = false;
|
||||
for (Shared::Message& msg : messages) {
|
||||
if (msg.getId() == id) {
|
||||
msg.change(data);
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
for (Presence* pr : presences) {
|
||||
found = pr->changeMessage(id, data);
|
||||
if (found) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int Models::Contact::getMessagesCount() const
|
||||
{
|
||||
return messages.size() + childMessages;
|
||||
}
|
||||
|
||||
void Models::Contact::dropMessages()
|
||||
{
|
||||
if (messages.size() > 0) {
|
||||
messages.clear();
|
||||
changed(4);
|
||||
}
|
||||
|
||||
for (QMap<QString, Presence*>::iterator itr = presences.begin(), end = presences.end(); itr != end; ++itr) {
|
||||
itr.value()->dropMessages();
|
||||
}
|
||||
}
|
||||
|
||||
void Models::Contact::getMessages(Models::Contact::Messages& container) const
|
||||
{
|
||||
for (Messages::const_iterator itr = messages.begin(), end = messages.end(); itr != end; ++itr) {
|
||||
const Shared::Message& msg = *itr;
|
||||
container.push_back(msg);
|
||||
}
|
||||
|
||||
for (QMap<QString, Presence*>::const_iterator itr = presences.begin(), end = presences.end(); itr != end; ++itr) {
|
||||
itr.value()->getMessages(container);
|
||||
}
|
||||
}
|
||||
|
||||
void Models::Contact::toOfflineState()
|
||||
{
|
||||
std::deque<Item*>::size_type size = childItems.size();
|
||||
|
@ -355,75 +240,3 @@ QString Models::Contact::getDisplayedName() const
|
|||
return getContactName();
|
||||
}
|
||||
|
||||
bool Models::Contact::columnInvolvedInDisplay(int col)
|
||||
{
|
||||
return Item::columnInvolvedInDisplay(col) && col == 1;
|
||||
}
|
||||
|
||||
Models::Contact * Models::Contact::copy() const
|
||||
{
|
||||
Contact* cnt = new Contact(*this);
|
||||
return cnt;
|
||||
}
|
||||
|
||||
Models::Contact::Contact(const Models::Contact& other):
|
||||
Item(other),
|
||||
jid(other.jid),
|
||||
availability(other.availability),
|
||||
state(other.state),
|
||||
presences(),
|
||||
messages(other.messages),
|
||||
childMessages(0),
|
||||
account(other.account)
|
||||
{
|
||||
for (const Presence* pres : other.presences) {
|
||||
Presence* pCopy = new Presence(*pres);
|
||||
presences.insert(pCopy->getName(), pCopy);
|
||||
Item::appendChild(pCopy);
|
||||
connect(pCopy, &Item::childChanged, this, &Contact::refresh);
|
||||
}
|
||||
|
||||
refresh();
|
||||
}
|
||||
|
||||
QString Models::Contact::getAvatarPath() const
|
||||
{
|
||||
return avatarPath;
|
||||
}
|
||||
|
||||
Shared::Avatar Models::Contact::getAvatarState() const
|
||||
{
|
||||
return avatarState;
|
||||
}
|
||||
|
||||
void Models::Contact::setAvatarPath(const QString& path)
|
||||
{
|
||||
if (path != avatarPath) {
|
||||
avatarPath = path;
|
||||
changed(7);
|
||||
}
|
||||
}
|
||||
|
||||
void Models::Contact::setAvatarState(Shared::Avatar p_state)
|
||||
{
|
||||
if (avatarState != p_state) {
|
||||
avatarState = p_state;
|
||||
changed(6);
|
||||
}
|
||||
}
|
||||
|
||||
void Models::Contact::setAvatarState(unsigned int p_state)
|
||||
{
|
||||
if (p_state <= static_cast<quint8>(Shared::Avatar::valid)) {
|
||||
Shared::Avatar state = static_cast<Shared::Avatar>(p_state);
|
||||
setAvatarState(state);
|
||||
} else {
|
||||
qDebug() << "An attempt to set invalid avatar state" << p_state << "to the contact" << jid << ", skipping";
|
||||
}
|
||||
}
|
||||
|
||||
const Models::Account * Models::Contact::getParentAccount() const
|
||||
{
|
||||
return account;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue