Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added support for cleanup of old accounts
  • Loading branch information
SfietKonstantin committed Aug 19, 2013
1 parent 75e838d commit c8c72dd
Show file tree
Hide file tree
Showing 12 changed files with 188 additions and 203 deletions.
39 changes: 28 additions & 11 deletions src/eventfeed/SocialAccountPullDownMenu.qml
Expand Up @@ -13,18 +13,33 @@ PullDownMenu {
property var pageContainer
onMetaDataChanged: refreshAccountList()

// We distinguish internal.index and container.currentAccountIndex
// It is because internal.accounts is not matching the accounts
// data carried by the metadata. This is because accounts might
// got deleted between two sync, and that metadata contains
// data that should not exist.
//
// internal.index stores the index of the current account in
// internal.account, while container.currentAccountIndex
// is used to store the index for the metadata. If metadata
// carries also information for (for example) avatar, that
// are indexed, then container.currentAccountIndex contains
// the good index, even if accounts got removed
function refreshAccountList() {
internal.accounts = []
internal.accountCount = container.metaData["accountIdCount"]
for (var i = 0; i < internal.accountCount; i++) {
for (var i = 0; i < container.metaData["accountIdCount"]; i++) {
var accountData = new Object
accountData["id"] = container.metaData["accountId" + i]
var account = accountManager.account(accountData["id"])
accountData["name"] = account.displayName
internal.accounts.push(accountData)
if (account != null) {
accountData["name"] = account.displayName
accountData["index"] = i
internal.accounts.push(accountData)
}
}
internal.accountCount = internal.accounts.length
container.currentAccount = internal.accounts[0]["id"]
container.currentAccountIndex = 0
container.currentAccountIndex = internal.accounts[0]["index"]

if (internal.accountCount == 2) {
internal.otherIndex = 1
Expand All @@ -34,11 +49,13 @@ PullDownMenu {
QtObject {
id: internal
function setIndex(index) {
container.currentAccountIndex = index
internal.index = index
container.currentAccountIndex = internal.accounts[index]["index"]
pageContainer.pop()
}
property int accountCount
property var accounts
property int index
property int otherIndex
},
AccountManager {
Expand All @@ -62,19 +79,19 @@ PullDownMenu {
if (internal.accountCount > 2) {
var page = container.pageContainer.push(Qt.resolvedUrl("SocialAccountPage.qml"),
{"accounts": internal.accounts,
"currentIndex": container.currentAccountIndex,
"currentIndex": internal.index,
"headerText": container.selectAccountString})
page.indexSelected.connect(internal.setIndex)
// TODO
} else {
container.currentAccountIndex = internal.otherIndex
container.currentAccount = internal.accounts[container.currentAccountIndex]["id"]
internal.index = internal.otherIndex
container.currentAccount = internal.accounts[internal.index]["id"]
container.currentAccountIndex = internal.accounts[internal.index]["index"]
internal.otherIndex = (internal.otherIndex == 0 ? 1 : 0)
}
}
}

MenuLabel {
text: container.accountString.arg(internal.accounts[container.currentAccountIndex]["name"])
text: container.accountString.arg(internal.accounts[internal.index]["name"])
}
}
36 changes: 6 additions & 30 deletions src/eventfeedhelper_p.h
@@ -1,33 +1,9 @@
/*
* Copyright (C) 2013 Lucien XU <sfietkonstantin@free.fr>
*
* You may use this file under the terms of the BSD license as follows:
*
* "Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * The names of its contributors may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
*/
/****************************************************************************
**
** Copyright (C) 2013 Jolla Ltd.
** Contact: Lucien Xu <lucien.xu@jollamobile.com>
**
****************************************************************************/

#ifndef EVENTFEEDHELPER_P_H
#define EVENTFEEDHELPER_P_H
Expand Down
7 changes: 0 additions & 7 deletions src/facebook/eventfeed/facebook.qml
Expand Up @@ -28,13 +28,6 @@ Page {
mediaName = container.model.metaData["postAttachmentName"]
mediaCaption = container.model.metaData["postAttachmentCaption"]
mediaDescription = container.model.metaData["postAttachmentDescription"]
account.identifier = container.model.metaData["accountId0"]
console.debug("\n")
for(var k in container.model.metaData) {
console.debug(k + ": " + container.model.metaData[k] + "\n")
}
console.debug("\n")

}

Account {
Expand Down
23 changes: 21 additions & 2 deletions src/facebook/facebooknotificationsyncadaptor.cpp
Expand Up @@ -27,11 +27,30 @@ FacebookNotificationSyncAdaptor::~FacebookNotificationSyncAdaptor()

void FacebookNotificationSyncAdaptor::purgeDataForOldAccounts(const QList<int> &purgeIds)
{
foreach (int pid, purgeIds) {
foreach (int accountId, purgeIds) {
// purge all data from our database
removeAllData(QLatin1String("facebook"),
SyncService::dataType(SyncService::Notifications),
QString::number(pid));
QString::number(accountId));


// Search for the notification and close it
Notification *notification = 0;
QList<QObject *> notifications = Notification::notifications();
foreach (QObject *object, notifications) {
Notification *castedNotification = static_cast<Notification *>(object);
if (castedNotification->category() == "x-nemo.social.facebook.notification"
&& castedNotification->hintValue("x-nemo.sociald.account-id").toInt() == accountId) {
notification = castedNotification;
break;
}
}

if (notification) {
notification->close();
}

qDeleteAll(notifications);
}
}

Expand Down
33 changes: 15 additions & 18 deletions src/facebook/facebookpostsyncadaptor.cpp
Expand Up @@ -150,30 +150,28 @@ void FacebookPostSyncAdaptor::sync(const QString &dataType)

void FacebookPostSyncAdaptor::purgeDataForOldAccounts(const QList<int> &purgeIds)
{
foreach (int pid, purgeIds) {
// first, purge all data from nemo events
QStringList purgeDataIds = syncedDatumLocalIdentifiers(QLatin1String("facebook"),
SyncService::dataType(SyncService::Posts),
QString::number(pid));
foreach (int accountIdentifier, purgeIds) {
bool ok;
QStringList localIdentifiers = removeAllData(serviceName(), SyncService::dataType(dataType),
QString::number(accountIdentifier), &ok);
if (!ok) {
continue;
}

bool ok = true;
int prefixLen = QString(SOCIALD_FACEBOOK_POSTS_ID_PREFIX).size();
foreach (const QString &pdi, purgeDataIds) {
QString eventIdStr = pdi.mid(prefixLen); // pdi is of form: "facebook-posts-EVENTID"
qlonglong eventId = eventIdStr.toLongLong(&ok);

int prefixLength = QString(SOCIALD_FACEBOOK_POSTS_ID_PREFIX).size();
// Remove entries in the event feed
foreach (const QString &localIdentifier, localIdentifiers) {
QString eventIdString = localIdentifier.mid(prefixLength);
qlonglong eventId = eventIdString.toLongLong(&ok);
if (ok) {
MEventFeed::instance()->removeItem(eventId);
} else {
TRACE(SOCIALD_ERROR,
QString(QLatin1String("error: unable to convert event id string to int: %1"))
.arg(pdi));
QString(QLatin1String("error: unable to remove event %1"))
.arg(eventIdString));
}
}

// second, purge all data from our database
removeAllData(QLatin1String("facebook"),
SyncService::dataType(SyncService::Posts),
QString::number(pid)); // XXX TODO: use fb id instead of QString::number(accountId)
}
}

Expand Down Expand Up @@ -283,7 +281,6 @@ void FacebookPostSyncAdaptor::finishedPostsHandler()
bool ok = false;
QJsonObject parsed = FacebookDataTypeSyncAdaptor::parseReplyData(replyData, &ok);
if (ok && parsed.contains(QLatin1String("data"))) {
// we expect "data" and possible "paging"
QJsonArray data = parsed.value(QLatin1String("data")).toArray();

if (!data.size()) {
Expand Down

0 comments on commit c8c72dd

Please sign in to comment.