diff options
Diffstat (limited to 'Swiften')
-rw-r--r-- | Swiften/Roster/ContactRosterItem.cpp | 12 | ||||
-rw-r--r-- | Swiften/Roster/ContactRosterItem.h | 5 | ||||
-rw-r--r-- | Swiften/Roster/Roster.cpp | 12 |
3 files changed, 29 insertions, 0 deletions
diff --git a/Swiften/Roster/ContactRosterItem.cpp b/Swiften/Roster/ContactRosterItem.cpp index 9251fad..bbf3928 100644 --- a/Swiften/Roster/ContactRosterItem.cpp +++ b/Swiften/Roster/ContactRosterItem.cpp @@ -98,6 +98,18 @@ void ContactRosterItem::applyPresence(const String& resource, boost::shared_ptr< onDataChanged(); } +const std::vector<String> ContactRosterItem::getGroups() const { + return groups_; +} + +/** Only used so a contact can know about the groups it's in*/ +void ContactRosterItem::addGroup(const String& group) { + groups_.push_back(group); +} +void ContactRosterItem::removeGroup(const String& group) { + groups_.erase(std::find(groups_.begin(), groups_.end(), group)); +} + } diff --git a/Swiften/Roster/ContactRosterItem.h b/Swiften/Roster/ContactRosterItem.h index 21f6024..707dd42 100644 --- a/Swiften/Roster/ContactRosterItem.h +++ b/Swiften/Roster/ContactRosterItem.h @@ -36,6 +36,10 @@ class ContactRosterItem : public RosterItem { void applyPresence(const String& resource, boost::shared_ptr<Presence> presence); void clearPresence(); void calculateShownPresence(); + const std::vector<String> getGroups() const; + /** Only used so a contact can know about the groups it's in*/ + void addGroup(const String& group); + void removeGroup(const String& group); private: JID jid_; JID displayJID_; @@ -44,6 +48,7 @@ class ContactRosterItem : public RosterItem { std::map<String, boost::shared_ptr<Presence> > presences_; boost::shared_ptr<Presence> offlinePresence_; boost::shared_ptr<Presence> shownPresence_; + std::vector<String> groups_; }; } diff --git a/Swiften/Roster/Roster.cpp b/Swiften/Roster/Roster.cpp index f9f0dbb..68bac53 100644 --- a/Swiften/Roster/Roster.cpp +++ b/Swiften/Roster/Roster.cpp @@ -73,9 +73,18 @@ void Roster::addContact(const JID& jid, const JID& displayJID, const String& nam ContactRosterItem *item = new ContactRosterItem(jid, displayJID, name, group); item->setAvatarPath(avatarPath); group->addChild(item); + if (itemMap_[fullJIDMapping_ ? jid : jid.toBare()].size() > 0) { + foreach (String existingGroup, itemMap_[fullJIDMapping_ ? jid : jid.toBare()][0]->getGroups()) { + item->addGroup(existingGroup); + } + } itemMap_[fullJIDMapping_ ? jid : jid.toBare()].push_back(item); item->onDataChanged.connect(boost::bind(&Roster::handleDataChanged, this, item)); filterContact(item, group); + + foreach (ContactRosterItem* item, itemMap_[fullJIDMapping_ ? jid : jid.toBare()]) { + item->addGroup(groupName); + } } struct JIDEqualsTo { @@ -113,6 +122,9 @@ void Roster::removeContactFromGroup(const JID& jid, const String& groupName) { } it++; } + foreach (ContactRosterItem* item, itemMap_[fullJIDMapping_ ? jid : jid.toBare()]) { + item->removeGroup(groupName); + } } |