Skip to content

Commit

Permalink
[buteo-sync-plugins-social] Use gd:fullName in Google Contacts API. J…
Browse files Browse the repository at this point in the history
…B#51541

Encode and decode the gd:fullName entry in the atom feed. The server
always sends a fullName composed from the first name, last name,
prefix etc. so encoding this in the request will avoid a spurious
modification from the server on the next sync after it reassembles the
fullName on the server side.
  • Loading branch information
blammit committed Oct 19, 2020
1 parent 0184365 commit 625191d
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions src/google/google-contacts/googlecontactstream.cpp
Expand Up @@ -642,6 +642,8 @@ QContactDetail GoogleContactStream::handleEntryName()
name.setPrefix(mXmlReader->readElementText());
} else if (mXmlReader->qualifiedName() == "gd:nameSuffix") {
name.setSuffix(mXmlReader->readElementText());
} else if (mXmlReader->qualifiedName() == "gd:fullName") {
name.setCustomLabel(mXmlReader->readElementText());
}
}
mXmlReader->readNextStartElement();
Expand Down Expand Up @@ -972,16 +974,32 @@ void GoogleContactStream::encodeEtag(const QContact &qContact, bool needed)
void GoogleContactStream::encodeName(const QContactName &name)
{
mXmlWriter->writeStartElement("gd:name");
if (!name.firstName().isEmpty())
mXmlWriter->writeTextElement("gd:givenName", name.firstName());

const QString firstName = name.firstName();
const QString lastName = name.lastName();

if (!firstName.isEmpty())
mXmlWriter->writeTextElement("gd:givenName", firstName);
if (!name.middleName().isEmpty())
mXmlWriter->writeTextElement("gd:additionalName", name.middleName());
if (!name.lastName().isEmpty())
mXmlWriter->writeTextElement("gd:familyName", name.lastName());
if (!lastName.isEmpty())
mXmlWriter->writeTextElement("gd:familyName", lastName);
if (!name.prefix().isEmpty())
mXmlWriter->writeTextElement("gd:namePrefix", name.prefix());
if (!name.suffix().isEmpty())
mXmlWriter->writeTextElement("gd:nameSuffix", name.suffix());

const QString fullName = (QStringList()
<< name.prefix()
<< SeasideCache::primaryName(firstName, lastName)
<< name.middleName()
<< SeasideCache::secondaryName(firstName, lastName)
<< name.suffix()).join(' ');
if (!fullName.isEmpty())
mXmlWriter->writeTextElement("gd:fullName", fullName);
else if (!name.customLabel().isEmpty())
mXmlWriter->writeTextElement("gd:fullName", name.customLabel());

mXmlWriter->writeEndElement();
}

Expand Down

0 comments on commit 625191d

Please sign in to comment.