[Kde-pim] [kdepim-runtime] resources/facebook: [resources/facebook] Remove the code to fetch & store friends

Martin Klapetek mklapetek at kde.org
Thu Oct 30 22:53:46 GMT 2014


Git commit 259d93957d45b85e58d6afdcd258beeb1fcffdb0 by Martin Klapetek.
Committed on 30/10/2014 at 22:49.
Pushed by mklapetek into branch 'master'.

[resources/facebook] Remove the code to fetch & store friends

Facebook in its API v2.0 removed the ability to retrieve user's friends
list. This effectively means that importing Facebook contacts into local
address book is not possible anymore. This change will be forced on all
apps starting April 2015 and there is no replacement, even planned;
there is already API v2.1 out with no hints.

Together with deprecating the Chat APIs (also due in April 2015) they
are clearly forcing everyone to use only their apps/website exclusively
for what are probably the most interesting tasks on Facebook.

The rest of the resource functionality stays in tact - we still get
events, notes, posts and notifications.

This concerns only the frameworks port. However now that I'm thinking
about it, the stable (kdepim4) version will stop working completely in
April 2015 because the libkfbapi in the kde4 version is making calls to
the API v1.0, so the server will simply start returning errors and no
data. I think libkfbapi /could/ be fixed by just doing "s/v1.0/v2.1" on
the request URL, but there are likely some other breaking changes,
especially in the permissions list and permission names, which are set
by the resource. So in order to fix it for people running stable, new
libkfbapi release will be needed together with new Facebook resource.

CCMAIL:kde-pim at kde.org

M  +0    -1    resources/facebook/CMakeLists.txt
M  +2    -40   resources/facebook/facebookresource.cpp
M  +0    -20   resources/facebook/facebookresource.h
D  +0    -260  resources/facebook/facebookresource_friends.cpp

http://commits.kde.org/kdepim-runtime/259d93957d45b85e58d6afdcd258beeb1fcffdb0

diff --git a/resources/facebook/CMakeLists.txt b/resources/facebook/CMakeLists.txt
index ede7178..e5edbee 100644
--- a/resources/facebook/CMakeLists.txt
+++ b/resources/facebook/CMakeLists.txt
@@ -14,7 +14,6 @@ endif()
 set(facebookresource_SRCS
   facebookresource.cpp
   facebookresource_events.cpp
-  facebookresource_friends.cpp
   facebookresource_notes.cpp
   facebookresource_posts.cpp
   facebookresource_notifications.cpp
diff --git a/resources/facebook/facebookresource.cpp b/resources/facebook/facebookresource.cpp
index d2c3b6d..ae1a87a 100644
--- a/resources/facebook/facebookresource.cpp
+++ b/resources/facebook/facebookresource.cpp
@@ -28,9 +28,6 @@
 #include "../shared/getcredentialsjob.h"
 #endif
 
-#include <libkfbapi/friendlistjob.h>
-#include <libkfbapi/friendjob.h>
-#include <libkfbapi/photojob.h>
 #include <libkfbapi/alleventslistjob.h>
 #include <libkfbapi/eventjob.h>
 #include <libkfbapi/allnoteslistjob.h>
@@ -138,12 +135,7 @@ void FacebookResource::abortWithError( const QString &errorMessage, bool authFai
 void FacebookResource::resetState()
 {
   mIdle = true;
-  mNumFriends = -1;
-  mNumPhotosFetched = 0;
   mCurrentJobs.clear();
-  mExistingFriends.clear();
-  mNewOrChangedFriends.clear();
-  mPendingFriends.clear();
 }
 
 void FacebookResource::slotAbortRequested()
@@ -173,16 +165,7 @@ void FacebookResource::retrieveItems( const Akonadi::Collection &collection )
 {
   Q_ASSERT( mIdle );
 
-  if ( collection.remoteId() == friendsRID ) {
-    mIdle = false;
-    emit status( Running, i18n( "Preparing sync of friends list." ) );
-    emit percent( 0 );
-    ItemFetchJob * const fetchJob = new ItemFetchJob( collection );
-    fetchJob->fetchScope().fetchAttribute<TimeStampAttribute>();
-    fetchJob->fetchScope().fetchFullPayload( false );
-    mCurrentJobs << fetchJob;
-    connect( fetchJob, SIGNAL(result(KJob*)), this, SLOT(initialItemFetchFinished(KJob*)) );
-  } else if ( collection.remoteId() == eventsRID ) {
+  if ( collection.remoteId() == eventsRID ) {
     mIdle = false;
     emit status( Running, i18n( "Preparing sync of events list." ) );
     emit percent( 0 );
@@ -236,16 +219,7 @@ bool FacebookResource::retrieveItem( const Akonadi::Item &item, const QSet<QByte
 
   qDebug() << item.mimeType();
 
-  if ( item.mimeType() == KABC::Addressee::mimeType() ) {
-    // TODO: Is this ever called??
-    mIdle = false;
-    KFbAPI::FriendJob * const friendJob =
-      new KFbAPI::FriendJob( item.remoteId(), Settings::self()->accessToken(), this );
-    mCurrentJobs << friendJob;
-    friendJob->setProperty( "Item", QVariant::fromValue( item ) );
-    connect( friendJob, SIGNAL(result(KJob*)), this, SLOT(friendJobFinished(KJob*)) );
-    friendJob->start();
-  } else if ( item.mimeType() == Akonadi::NoteUtils::noteMimeType() ) {
+  if ( item.mimeType() == Akonadi::NoteUtils::noteMimeType() ) {
     mIdle = false;
     KFbAPI::NoteJob * const noteJob =
       new KFbAPI::NoteJob( item.remoteId(), Settings::self()->accessToken(), this );
@@ -271,18 +245,6 @@ bool FacebookResource::retrieveItem( const Akonadi::Item &item, const QSet<QByte
 void FacebookResource::retrieveCollections()
 {
   Collection::List collections;
-  if (Settings::self()->accountServices().contains(QLatin1String("facebook-contacts"))) {
-    Collection friends;
-    friends.setRemoteId( friendsRID );
-    friends.setName( i18nc( "@title: addressbook name", "Friends on Facebook" ) );
-    friends.setParentCollection( Akonadi::Collection::root() );
-    friends.setContentMimeTypes( QStringList() << KABC::Addressee::mimeType() );
-    friends.setRights( Collection::ReadOnly );
-    EntityDisplayAttribute * const friendsDisplayAttribute = new EntityDisplayAttribute();
-    friendsDisplayAttribute->setIconName( QLatin1String("facebookresource") );
-    friends.addAttribute( friendsDisplayAttribute );
-    collections << friends;
-  }
 
   if (Settings::self()->accountServices().contains(QLatin1String("facebook-events"))) {
     Collection events;
diff --git a/resources/facebook/facebookresource.h b/resources/facebook/facebookresource.h
index df69a0e..e6e0cdf 100644
--- a/resources/facebook/facebookresource.h
+++ b/resources/facebook/facebookresource.h
@@ -22,8 +22,6 @@
 #ifndef FACEBOOK_FACEBOOKRESOURCE_H
 #define FACEBOOK_FACEBOOKRESOURCE_H
 
-#include <libkfbapi/userinfo.h>
-#include <libkfbapi/postinfo.h>
 #include <libkfbapi/notificationinfo.h>
 
 #include <Akonadi/SocialUtils/SocialFeedItem>
@@ -34,7 +32,6 @@
 class KStatusNotifierItem;
 
 static const QLatin1String notificationsRID( "notifications" );
-static const QLatin1String friendsRID( "friends" );
 static const QLatin1String eventsRID( "events" );
 static const QLatin1String eventMimeType( "application/x-vnd.akonadi.calendar.event" );
 static const QLatin1String notesRID( "notes" );
@@ -72,10 +69,7 @@ class FacebookResource : public Akonadi::ResourceBase,
 
     void slotAbortRequested();
     void configurationChanged();
-    void friendListJobFinished( KJob *job );
-    void friendJobFinished( KJob *job );
     void photoJobFinished( KJob *job );
-    void detailedFriendListJobFinished( KJob *job );
     void initialItemFetchFinished( KJob *job );
     void eventListFetched( KJob *job );
     void detailedEventListJobFinished( KJob *job );
@@ -114,28 +108,14 @@ class FacebookResource : public Akonadi::ResourceBase,
 
     void displayNotificationsToUser(FbNotificationPresentation displayType);
 
-    void fetchNewOrChangedFriends();
-    void finishFriendFetching();
     void finishEventsFetching();
     void finishNotesFetching();
     void finishPostsFetching();
     void finishNotificationsFetching();
     Akonadi::SocialFeedItem convertToSocialFeedItem( const KFbAPI::PostInfo &postinfo );
 
-    // Friends that are already stored on the Akonadi server
-    QMap<QString, KDateTime> mExistingFriends;
-
-    // Pending new/changed friends we still need to download
-    QList<KFbAPI::UserInfo> mPendingFriends;
-
-    QList<KFbAPI::UserInfo> mNewOrChangedFriends;
-
     QList<KFbAPI::NotificationInfo> mDisplayedNotifications;
 
-    // Total number of new & changed friends
-    int mNumFriends;
-    int mNumPhotosFetched;
-
     bool mIdle;
     QList< QPointer<KJob> > mCurrentJobs;
 
diff --git a/resources/facebook/facebookresource_friends.cpp b/resources/facebook/facebookresource_friends.cpp
deleted file mode 100644
index a8c5f95..0000000
--- a/resources/facebook/facebookresource_friends.cpp
+++ /dev/null
@@ -1,260 +0,0 @@
-/*
-  Copyright 2010, 2011 Thomas McGuire <mcguire at kde.org>
-  Copyright 2011 Roeland Jago Douma <unix at rullzer.com>
-
-  This library is free software; you can redistribute it and/or modify
-  it under the terms of the GNU Library General Public License as published
-  by the Free Software Foundation; either version 2 of the License or
-  ( at your option ) version 3 or, at the discretion of KDE e.V.
-  ( which shall act as a proxy as in section 14 of the GPLv3 ), any later version.
-
-  This library is distributed in the hope that it will be useful,
-  but WITHOUT ANY WARRANTY; without even the implied warranty of
-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-  Library General Public License for more details.
-
-  You should have received a copy of the GNU Library General Public License
-  along with this library; see the file COPYING.LIB.  If not, write to
-  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-  Boston, MA 02110-1301, USA.
-*/
-
-#include "facebookresource.h"
-#include "settings.h"
-#include "settingsdialog.h"
-#include "timestampattribute.h"
-
-#include <libkfbapi/friendlistjob.h>
-#include <libkfbapi/friendjob.h>
-#include <libkfbapi/photojob.h>
-
-#include <AkonadiCore/AttributeFactory>
-#include <AkonadiCore/EntityDisplayAttribute>
-#include <AkonadiCore/ItemFetchJob>
-#include <AkonadiCore/ItemFetchScope>
-#include <AkonadiCore/ChangeRecorder>
-
-using namespace Akonadi;
-
-void FacebookResource::initialItemFetchFinished( KJob *job )
-{
-  Q_ASSERT( !mIdle );
-  Q_ASSERT( mCurrentJobs.indexOf( job ) != -1 );
-  ItemFetchJob * const itemFetchJob = dynamic_cast<ItemFetchJob*>( job );
-  Q_ASSERT( itemFetchJob );
-  mCurrentJobs.removeAll( job );
-
-  if ( itemFetchJob->error() ) {
-    abortWithError( i18n( "Unable to get list of existing friends from the Akonadi server: %1",
-                          itemFetchJob->errorString() ) );
-  } else {
-    foreach ( const Item &item, itemFetchJob->items() ) {
-      if ( item.hasAttribute<TimeStampAttribute>() ) {
-        mExistingFriends.insert( item.remoteId(),
-                                 item.attribute<TimeStampAttribute>()->timeStamp() );
-      }
-    }
-
-    setItemStreamingEnabled( true );
-    KFbAPI::FriendListJob * const friendListJob =
-      new KFbAPI::FriendListJob( Settings::self()->accessToken(), this );
-    mCurrentJobs << friendListJob;
-    connect( friendListJob, SIGNAL(result(KJob*)), this, SLOT(friendListJobFinished(KJob*)) );
-    emit status( Running, i18n( "Retrieving friends list." ) );
-    emit percent( 2 );
-    friendListJob->start();
-  }
-
-  itemFetchJob->deleteLater();
-}
-
-void FacebookResource::friendListJobFinished( KJob *job )
-{
-  Q_ASSERT( !mIdle );
-  Q_ASSERT( mCurrentJobs.indexOf( job ) != -1 );
-  KFbAPI::FriendListJob * const friendListJob = dynamic_cast<KFbAPI::FriendListJob*>( job );
-  Q_ASSERT( friendListJob );
-  mCurrentJobs.removeAll( job );
-
-  if ( friendListJob->error() ) {
-    abortWithError( i18n( "Unable to get list of friends from server: %1",
-                          friendListJob->errorText() ),
-                    friendListJob->error() == KFbAPI::FacebookJob::AuthenticationProblem );
-  } else {
-
-    // Figure out which items are new or changed
-    foreach ( const KFbAPI::UserInfo &user, friendListJob->friends() ) {
-#if 0 // Bah, Facebook's timestamp doesn't seem to get updated when a user's profile changes :(
-      // See http://bugs.developers.facebook.net/show_bug.cgi?id=15475
-      const KDateTime stampOfExisting = mExistingFriends.value( user->id(), KDateTime() );
-      if ( !stampOfExisting.isValid() ) {
-        qDebug() << "Friend" << user->id() << user->name() << "is new!";
-        mNewOrChangedFriends.append( user );
-      } else if ( user->updatedTime() > stampOfExisting ) {
-        qDebug() << "Friend" << user->id() << user->name() << "is updated!";
-        mNewOrChangedFriends.append( user );
-      } else {
-        //qDebug() << "Friend" << user->id() << user->name() << "is old.";
-      }
-#else
-      mNewOrChangedFriends.append( user );
-#endif
-    }
-
-    // Delete items that are in the Akonadi DB but no on FB
-    Item::List removedItems;
-    foreach ( const QString &friendId, mExistingFriends.keys() ) { //krazy:exclude=foreach
-      bool found = false;
-      foreach ( const KFbAPI::UserInfo &user, friendListJob->friends() ) {
-        if ( user.id() == friendId ) {
-          found = true;
-          break;
-        }
-      }
-      if ( !found ) {
-        qDebug() << friendId << "is no longer your friend :(";
-        Item removedItem;
-        removedItem.setRemoteId( friendId );
-        removedItems.append( removedItem );
-      }
-    }
-    itemsRetrievedIncremental( Item::List(), removedItems );
-
-    if ( mNewOrChangedFriends.isEmpty() ) {
-      finishFriendFetching();
-    } else {
-      emit status( Running, i18n( "Retrieving friends' details." ) );
-      emit percent( 5 );
-      fetchNewOrChangedFriends();
-    }
-  }
-
-  friendListJob->deleteLater();
-}
-
-void FacebookResource::fetchNewOrChangedFriends()
-{
-  QStringList mewOrChangedFriendIds;
-  Q_FOREACH ( const KFbAPI::UserInfo &user, mNewOrChangedFriends ) {
-    mewOrChangedFriendIds.append( user.id() );
-  }
-  KFbAPI::FriendJob * const friendJob =
-    new KFbAPI::FriendJob( mewOrChangedFriendIds, Settings::self()->accessToken(), this );
-  mCurrentJobs << friendJob;
-  connect( friendJob, SIGNAL(result(KJob*)), this, SLOT(detailedFriendListJobFinished(KJob*)) );
-  friendJob->start();
-}
-
-void FacebookResource::detailedFriendListJobFinished( KJob *job )
-{
-  Q_ASSERT( !mIdle );
-  Q_ASSERT( mCurrentJobs.indexOf( job ) != -1 );
-  KFbAPI::FriendJob * const friendJob = dynamic_cast<KFbAPI::FriendJob*>( job );
-  Q_ASSERT( friendJob );
-  mCurrentJobs.removeAll( job );
-
-  if ( friendJob->error() ) {
-    abortWithError( i18n( "Unable to retrieve friends' information from server: %1",
-                          friendJob->errorText() ) );
-  } else {
-    mPendingFriends = friendJob->friendInfo();
-    mNumFriends = mPendingFriends.size();
-    emit status( Running, i18n( "Retrieving friends' photos." ) );
-    emit percent( 10 );
-    fetchPhotos();
-  }
-
-  friendJob->deleteLater();
-}
-
-void FacebookResource::fetchPhotos()
-{
-  mIdle = false;
-  mNumPhotosFetched = 0;
-  Q_FOREACH ( const KFbAPI::UserInfo &f, mPendingFriends ) {
-    KFbAPI::PhotoJob * const photoJob =
-      new KFbAPI::PhotoJob( f.id(), Settings::self()->accessToken(), this );
-    mCurrentJobs << photoJob;
-    photoJob->setProperty( "friend", QVariant::fromValue( f ) );
-    connect( photoJob, SIGNAL(result(KJob*)), this, SLOT(photoJobFinished(KJob*)) );
-    photoJob->start();
-  }
-}
-
-void FacebookResource::finishFriendFetching()
-{
-  Q_ASSERT( mCurrentJobs.size() == 0 );
-
-  mPendingFriends.clear();
-  emit percent( 100 );
-  if ( mNumFriends > 0 ) {
-    emit status( Idle, i18np( "Updated one friend from the server.",
-                              "Updated %1 friends from the server.", mNumFriends ) );
-  } else {
-    emit status( Idle, i18n( "Finished, no friends needed to be updated." ) );
-  }
-  resetState();
-}
-
-void FacebookResource::photoJobFinished( KJob *job )
-{
-  Q_ASSERT( !mIdle );
-  Q_ASSERT( mCurrentJobs.indexOf( job ) != -1 );
-  KFbAPI::PhotoJob * const photoJob = dynamic_cast<KFbAPI::PhotoJob*>( job );
-  Q_ASSERT( photoJob );
-  const KFbAPI::UserInfo user = job->property( "friend" ).value<KFbAPI::UserInfo>();
-  mCurrentJobs.removeOne( job );
-
-  if ( photoJob->error() ) {
-    abortWithError( i18n( "Unable to retrieve friends' photo from server: %1",
-                          photoJob->errorText() ) );
-  } else {
-    // Create Item
-    KABC::Addressee addressee = user.toAddressee();
-    addressee.setPhoto( KABC::Picture( photoJob->photo() ) );
-    Item newUser;
-    newUser.setRemoteId( user.id() );
-    newUser.setMimeType( QLatin1String("text/directory") );
-    newUser.setPayload<KABC::Addressee>( addressee );
-    TimeStampAttribute * const timeStampAttribute = new TimeStampAttribute();
-    timeStampAttribute->setTimeStamp( user.updatedTime() );
-    newUser.addAttribute( timeStampAttribute );
-
-    itemsRetrievedIncremental( Item::List() << newUser, Item::List() );
-    mNumPhotosFetched++;
-
-    if ( mNumPhotosFetched != mNumFriends ) {
-      const int alreadyDownloadedFriends = mNumPhotosFetched;
-      const float percentageDone = alreadyDownloadedFriends / ( float )mNumFriends * 100.0f;
-      emit percent( 10 + percentageDone * 0.9f );
-    } else {
-      itemsRetrievalDone();
-      finishFriendFetching();
-    }
-  }
-
-  photoJob->deleteLater();
-}
-
-void FacebookResource::friendJobFinished( KJob *job )
-{
-  Q_ASSERT( !mIdle );
-  Q_ASSERT( mCurrentJobs.indexOf( job ) != -1 );
-  KFbAPI::FriendJob * const friendJob = dynamic_cast<KFbAPI::FriendJob*>( job );
-  Q_ASSERT( friendJob );
-  Q_ASSERT( friendJob->friendInfo().size() == 1 );
-  mCurrentJobs.removeAll( job );
-
-  if ( friendJob->error() ) {
-    abortWithError( i18n( "Unable to get information about friend from server: %1",
-                          friendJob->errorText() ) );
-  } else {
-    Item user = friendJob->property( "Item" ).value<Item>();
-    user.setPayload<KABC::Addressee>( friendJob->friendInfo().first().toAddressee() );
-    // TODO: What about picture here?
-    itemRetrieved( user );
-    resetState();
-  }
-
-  friendJob->deleteLater();
-}
_______________________________________________
KDE PIM mailing list kde-pim at kde.org
https://mail.kde.org/mailman/listinfo/kde-pim
KDE PIM home page at http://pim.kde.org/



More information about the kde-pim mailing list