Skip to content

Commit

Permalink
Make VK post identifier unique
Browse files Browse the repository at this point in the history
  • Loading branch information
Antti Seppälä committed Aug 18, 2015
1 parent 70103b0 commit 20d19bf
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/vk/vk-posts/vkpostsyncadaptor.cpp
Expand Up @@ -240,25 +240,30 @@ void VKPostSyncAdaptor::saveVKPostFromObject(int accountId, const QJsonObject &p
copyPost.text = post.value(QStringLiteral("copy_text")).toString();
newPost.copyPost = copyPost;

QString identifier = post.contains(QStringLiteral("id"))
? QString::number(post.value(QStringLiteral("id")).toDouble())
: QString::number(post.value(QStringLiteral("post_id")).toDouble());
QDateTime createdTime = VKDataTypeSyncAdaptor::parseVKDateTime(post.value(QStringLiteral("date")));
QString body = post.value(QStringLiteral("text")).toString();
QString posterName, posterIcon;
int fromId = newPost.fromId;
if (newPost.fromId < 0) {
// it was posted by a group
const GroupProfile &group(VKDataTypeSyncAdaptor::findGroupProfile(groupProfiles, newPost.fromId));
posterName = group.name;
posterIcon = group.icon;

fromId = -fromId;
} else {
// it was posted by a user
const UserProfile &user(VKDataTypeSyncAdaptor::findUserProfile(userProfiles, newPost.fromId));
posterName = user.name();
posterIcon = user.icon;
}

// VK post indentifier is just index number and not globally unique. To make
// it unique we combine it with fromId
QString identifier = QString::number(fromId) + QStringLiteral("_") +
(post.contains(QStringLiteral("id"))
? QString::number(post.value(QStringLiteral("id")).toDouble())
: QString::number(post.value(QStringLiteral("post_id")).toDouble()));

SOCIALD_LOG_TRACE("Adding new VK post:" << identifier << "from:" << posterName << "at:" << createdTime);
Q_FOREACH (const QString &line, body.split('\n')) { SOCIALD_LOG_TRACE(line); }

Expand Down

0 comments on commit 20d19bf

Please sign in to comment.