forked from blue/squawk
Now notifications have actions! Some more usefull functions to roster model
This commit is contained in:
parent
3916aec358
commit
e58213b294
15 changed files with 205 additions and 30 deletions
|
@ -155,6 +155,16 @@ void Models::Contact::removePresence(const QString& name)
|
|||
}
|
||||
}
|
||||
|
||||
Models::Presence * Models::Contact::getPresence(const QString& name)
|
||||
{
|
||||
QMap<QString, Presence*>::iterator itr = presences.find(name);
|
||||
if (itr == presences.end()) {
|
||||
return nullptr;
|
||||
} else {
|
||||
return itr.value();
|
||||
}
|
||||
}
|
||||
|
||||
void Models::Contact::refresh()
|
||||
{
|
||||
QDateTime lastActivity;
|
||||
|
|
|
@ -51,6 +51,7 @@ public:
|
|||
|
||||
void addPresence(const QString& name, const QMap<QString, QVariant>& data);
|
||||
void removePresence(const QString& name);
|
||||
Presence* getPresence(const QString& name);
|
||||
|
||||
QString getContactName() const;
|
||||
QString getStatus() const;
|
||||
|
|
|
@ -134,6 +134,11 @@ unsigned int Models::Element::getMessagesCount() const
|
|||
return feed->unreadMessagesCount();
|
||||
}
|
||||
|
||||
bool Models::Element::markMessageAsRead(const QString& id) const
|
||||
{
|
||||
return feed->markMessageAsRead(id);
|
||||
}
|
||||
|
||||
void Models::Element::addMessage(const Shared::Message& data)
|
||||
{
|
||||
feed->addMessage(data);
|
||||
|
|
|
@ -42,6 +42,7 @@ public:
|
|||
void addMessage(const Shared::Message& data);
|
||||
void changeMessage(const QString& id, const QMap<QString, QVariant>& data);
|
||||
unsigned int getMessagesCount() const;
|
||||
bool markMessageAsRead(const QString& id) const;
|
||||
void responseArchive(const std::list<Shared::Message> list, bool last);
|
||||
bool isRoom() const;
|
||||
void fileProgress(const QString& messageId, qreal value, bool up);
|
||||
|
|
|
@ -264,6 +264,16 @@ void Models::Room::removeParticipant(const QString& p_name)
|
|||
}
|
||||
}
|
||||
|
||||
Models::Participant * Models::Room::getParticipant(const QString& p_name)
|
||||
{
|
||||
std::map<QString, Participant*>::const_iterator itr = participants.find(p_name);
|
||||
if (itr == participants.end()) {
|
||||
return nullptr;
|
||||
} else {
|
||||
return itr->second;
|
||||
}
|
||||
}
|
||||
|
||||
void Models::Room::handleParticipantUpdate(std::map<QString, Participant*>::const_iterator itr, const QMap<QString, QVariant>& data)
|
||||
{
|
||||
Participant* part = itr->second;
|
||||
|
|
|
@ -58,6 +58,7 @@ public:
|
|||
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);
|
||||
Participant* getParticipant(const QString& name);
|
||||
|
||||
void toOfflineState() override;
|
||||
QString getDisplayedName() const override;
|
||||
|
|
|
@ -549,8 +549,8 @@ void Models::Roster::removeGroup(const QString& account, const QString& name)
|
|||
|
||||
void Models::Roster::changeContact(const QString& account, const QString& jid, const QMap<QString, QVariant>& data)
|
||||
{
|
||||
Element* el = getElement({account, jid});
|
||||
if (el != NULL) {
|
||||
Element* el = getElement(ElId(account, jid));
|
||||
if (el != nullptr) {
|
||||
for (QMap<QString, QVariant>::const_iterator itr = data.begin(), end = data.end(); itr != end; ++itr) {
|
||||
el->update(itr.key(), itr.value());
|
||||
}
|
||||
|
@ -559,8 +559,8 @@ void Models::Roster::changeContact(const QString& account, const QString& jid, c
|
|||
|
||||
void Models::Roster::changeMessage(const QString& account, const QString& jid, const QString& id, const QMap<QString, QVariant>& data)
|
||||
{
|
||||
Element* el = getElement({account, jid});
|
||||
if (el != NULL) {
|
||||
Element* el = getElement(ElId(account, jid));
|
||||
if (el != nullptr) {
|
||||
el->changeMessage(id, data);
|
||||
} else {
|
||||
qDebug() << "A request to change a message of the contact " << jid << " in the account " << account << " but it wasn't found";
|
||||
|
@ -707,8 +707,8 @@ void Models::Roster::removePresence(const QString& account, const QString& jid,
|
|||
|
||||
void Models::Roster::addMessage(const QString& account, const Shared::Message& data)
|
||||
{
|
||||
Element* el = getElement({account, data.getPenPalJid()});
|
||||
if (el != NULL) {
|
||||
Element* el = getElement(ElId(account, data.getPenPalJid()));
|
||||
if (el != nullptr) {
|
||||
el->addMessage(data);
|
||||
}
|
||||
}
|
||||
|
@ -948,9 +948,18 @@ const Models::Element * Models::Roster::getElementConst(const Models::Roster::El
|
|||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool Models::Roster::markMessageAsRead(const Models::Roster::ElId& elementId, const QString& messageId)
|
||||
{
|
||||
const Element* el = getElementConst(elementId);
|
||||
if (el != nullptr) {
|
||||
return el->markMessageAsRead(messageId);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
QModelIndex Models::Roster::getAccountIndex(const QString& name)
|
||||
{
|
||||
|
@ -968,7 +977,7 @@ QModelIndex Models::Roster::getGroupIndex(const QString& account, const QString&
|
|||
if (itr == accounts.end()) {
|
||||
return QModelIndex();
|
||||
} else {
|
||||
std::map<ElId, Group*>::const_iterator gItr = groups.find({account, name});
|
||||
std::map<ElId, Group*>::const_iterator gItr = groups.find(ElId(account, name));
|
||||
if (gItr == groups.end()) {
|
||||
return QModelIndex();
|
||||
} else {
|
||||
|
@ -978,6 +987,48 @@ QModelIndex Models::Roster::getGroupIndex(const QString& account, const QString&
|
|||
}
|
||||
}
|
||||
|
||||
QModelIndex Models::Roster::getContactIndex(const QString& account, const QString& jid, const QString& resource)
|
||||
{
|
||||
std::map<QString, Account*>::const_iterator itr = accounts.find(account);
|
||||
if (itr == accounts.end()) {
|
||||
return QModelIndex();
|
||||
} else {
|
||||
Account* acc = itr->second;
|
||||
QModelIndex accIndex = index(acc->row(), 0, QModelIndex());
|
||||
std::map<ElId, Contact*>::const_iterator cItr = contacts.find(ElId(account, jid));
|
||||
if (cItr != contacts.end()) {
|
||||
QModelIndex contactIndex = index(acc->getContact(jid), 0, accIndex);
|
||||
if (resource.size() == 0) {
|
||||
return contactIndex;
|
||||
} else {
|
||||
Presence* pres = cItr->second->getPresence(resource);
|
||||
if (pres != nullptr) {
|
||||
return index(pres->row(), 0, contactIndex);
|
||||
} else {
|
||||
return contactIndex;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
std::map<ElId, Room*>::const_iterator rItr = rooms.find(ElId(account, jid));
|
||||
if (rItr != rooms.end()) {
|
||||
QModelIndex roomIndex = index(rItr->second->row(), 0, accIndex);
|
||||
if (resource.size() == 0) {
|
||||
return roomIndex;
|
||||
} else {
|
||||
Participant* part = rItr->second->getParticipant(resource);
|
||||
if (part != nullptr) {
|
||||
return index(part->row(), 0, roomIndex);
|
||||
} else {
|
||||
return roomIndex;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return QModelIndex();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Models::Roster::onElementRequestArchive(const QString& before)
|
||||
{
|
||||
Element* el = static_cast<Element*>(sender());
|
||||
|
@ -988,7 +1039,7 @@ void Models::Roster::responseArchive(const QString& account, const QString& jid,
|
|||
{
|
||||
ElId id(account, jid);
|
||||
Element* el = getElement(id);
|
||||
if (el != NULL) {
|
||||
if (el != nullptr) {
|
||||
el->responseArchive(list, last);
|
||||
}
|
||||
}
|
||||
|
@ -996,8 +1047,8 @@ void Models::Roster::responseArchive(const QString& account, const QString& jid,
|
|||
void Models::Roster::fileProgress(const std::list<Shared::MessageInfo>& msgs, qreal value, bool up)
|
||||
{
|
||||
for (const Shared::MessageInfo& info : msgs) {
|
||||
Element* el = getElement({info.account, info.jid});
|
||||
if (el != NULL) {
|
||||
Element* el = getElement(ElId(info.account, info.jid));
|
||||
if (el != nullptr) {
|
||||
el->fileProgress(info.messageId, value, up);
|
||||
}
|
||||
}
|
||||
|
@ -1006,8 +1057,8 @@ void Models::Roster::fileProgress(const std::list<Shared::MessageInfo>& msgs, qr
|
|||
void Models::Roster::fileComplete(const std::list<Shared::MessageInfo>& msgs, bool up)
|
||||
{
|
||||
for (const Shared::MessageInfo& info : msgs) {
|
||||
Element* el = getElement({info.account, info.jid});
|
||||
if (el != NULL) {
|
||||
Element* el = getElement(ElId(info.account, info.jid));
|
||||
if (el != nullptr) {
|
||||
el->fileComplete(info.messageId, up);
|
||||
}
|
||||
}
|
||||
|
@ -1016,8 +1067,8 @@ void Models::Roster::fileComplete(const std::list<Shared::MessageInfo>& msgs, bo
|
|||
void Models::Roster::fileError(const std::list<Shared::MessageInfo>& msgs, const QString& err, bool up)
|
||||
{
|
||||
for (const Shared::MessageInfo& info : msgs) {
|
||||
Element* el = getElement({info.account, info.jid});
|
||||
if (el != NULL) {
|
||||
Element* el = getElement(ElId(info.account, info.jid));
|
||||
if (el != nullptr) {
|
||||
el->fileError(info.messageId, err, up);
|
||||
}
|
||||
}
|
||||
|
@ -1031,7 +1082,7 @@ Models::Element * Models::Roster::getElement(const Models::Roster::ElId& id)
|
|||
Models::Item::Type Models::Roster::getContactType(const Models::Roster::ElId& id) const
|
||||
{
|
||||
const Models::Element* el = getElementConst(id);
|
||||
if (el == NULL) {
|
||||
if (el == nullptr) {
|
||||
return Item::root;
|
||||
}
|
||||
|
||||
|
|
|
@ -88,6 +88,8 @@ public:
|
|||
const Account* getAccountConst(const QString& name) const;
|
||||
QModelIndex getAccountIndex(const QString& name);
|
||||
QModelIndex getGroupIndex(const QString& account, const QString& name);
|
||||
QModelIndex getContactIndex(const QString& account, const QString& jid, const QString& resource = "");
|
||||
bool markMessageAsRead(const ElId& elementId, const QString& messageId);
|
||||
void responseArchive(const QString& account, const QString& jid, const std::list<Shared::Message>& list, bool last);
|
||||
|
||||
void fileProgress(const std::list<Shared::MessageInfo>& msgs, qreal value, bool up);
|
||||
|
@ -115,7 +117,7 @@ private slots:
|
|||
void onChildMoved();
|
||||
void onElementRequestArchive(const QString& before);
|
||||
void recalculateUnreadMessages();
|
||||
|
||||
|
||||
private:
|
||||
Item* root;
|
||||
std::map<QString, Account*> accounts;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue