Skip to content

Commit

Permalink
Merge pull request nemomobile#11 from matthewvogt/fix-self-init
Browse files Browse the repository at this point in the history
[contactsd] Correct the initialization of the self contact
  • Loading branch information
matthewvogt committed Jul 1, 2013
2 parents 8703f5d + 03ec865 commit daa9fcf
Showing 1 changed file with 23 additions and 24 deletions.
47 changes: 23 additions & 24 deletions plugins/telepathy/cdtpstorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,24 @@ ContactIdType selfContactLocalId()
if (!mgr->saveContact(&tpSelf)) {
warning() << "Unable to save empty contact as self contact - error:" << mgr->error();
} else {
// Now connect our contact to the real self contact
QContactRelationship relationship;
#ifdef USING_QTPIM
relationship.setRelationshipType(QContactRelationship::Aggregates());
relatedContact.setId(selfId);
relationship.setFirst(relatedContact);
relationship.setSecond(tpSelf);
#else
relationship.setRelationshipType(QContactRelationship::Aggregates);
relationship.setFirst(selfId);
relationship.setSecond(tpSelf.id());
#endif

if (!mgr->saveRelationship(&relationship)) {
warning() << "Unable to save relationship for self contact - error:" << mgr->error();
qFatal("Cannot proceed with invalid self contact!");
}

// Find the aggregate contact created by saving our self contact
#ifdef USING_QTPIM
relationshipFilter.setRelationshipType(QContactRelationship::Aggregates());
Expand All @@ -373,7 +391,10 @@ ContactIdType selfContactLocalId()
relationshipFilter.setRelatedContactRole(QContactRelationship::Second);

foreach (const QContact &aggregator, mgr->contacts(relationshipFilter)) {
// Remove the relationship between these contacts
if (aggregator.id() == tpSelf.id())
continue;

// Remove the relationship between these contacts (which removes the childless aggregate)
QContactRelationship relationship;
#ifdef USING_QTPIM
relationship.setRelationshipType(QContactRelationship::Aggregates());
Expand All @@ -387,32 +408,10 @@ ContactIdType selfContactLocalId()

if (!mgr->removeRelationship(relationship)) {
warning() << "Unable to remove relationship for self contact - error:" << mgr->error();
} else {
// Remove this contact
if (!mgr->removeContact(apiId(aggregator))) {
warning() << "Unable to remove unwanted aggregate of self contact - error:" << mgr->error();
}
}
}

// Now connect our contact to the real self contact
QContactRelationship relationship;
#ifdef USING_QTPIM
relationship.setRelationshipType(QContactRelationship::Aggregates());
relatedContact.setId(selfId);
relationship.setFirst(relatedContact);
relationship.setSecond(tpSelf);
#else
relationship.setRelationshipType(QContactRelationship::Aggregates);
relationship.setFirst(selfId);
relationship.setSecond(tpSelf.id());
#endif

if (!mgr->saveRelationship(&relationship)) {
warning() << "Unable to save relationship for self contact - error:" << mgr->error();
} else {
return apiId(tpSelf);
}
return apiId(tpSelf);
}
}

Expand Down

0 comments on commit daa9fcf

Please sign in to comment.