Saturday 18 August 2012

GSoC Coding Phase Ends


GSoC coding phase officially ends on Monday, 20th August 2012. I enjoyed working on the Twitter-Backend project over the past three months. Thanks my mentor Jan Kaluza (hanzz) and the library twitcurl, I was able to complete the project successfully.

A brief description about the work done during the summer follows. The past three months I worked on creating a Twitter backend for spectrum 2. The backend allows spectrum users to communicate with their friends belonging to Twitter. The main task was to map XMPP messages on the spectrum side to Twitter API calls on the Twitter side. Spectrum 2 already had an abstract class NetworkPlugin, which made the task of writing the backend simple. All I needed to do was implement the virtual functions by providing the necessary code to interact with Twitter, thus effectively mapping XMPP messages to Twitter API calls. In order to interact with Twitter, I used the library called twitcurl. The library provides a set of easy-to-use functions that abstract all the details involved in sending a REST query (corresponding to actions such as status update, fetching timeline etc.) to Twitter and fetching the response. At present, the backend is running at jabber.hot-chilli.net.

Monday 6 August 2012

Spectrum 1 DB Compatibilty

Twitter-Backend (written for spectrum 2) is now compatible with spectrum 1 user database. So,  spectrum 1 (twitter) users can now login into their twitter accounts via spectrum 2 without the need for re-registration. Finally, my code was merged with libtransport main branch! :) The code will now be tested on jabber.hot-chilli.net.

Twitcurl Patch

I finally finished implementing all the important tasks that I claimed I would in my GSoC Application :) The twitter library twitcurl simplified the task of creating the Twitter-Backend. I had to add a few additional functions to the library to support certain features (Eg. retweets) and I sent a patch containing these changes to twitcurl. Next, I will be working on making spectrum 1 user database compatible with spectrum 2.

Thursday 19 July 2012

Avatars

The past few days I worked on fetching user avatars from Twitter. Twitter-Backend can now handle vCard-Based avatar requests, thus allowing an XMPP user, who is connected to the Twitter network via spectrum, to view his Twitter friend's profile image.



Wednesday 11 July 2012

Per-User Mode Configuration

As I have mentioned in my earlier posts, Twitter-Backend supports three different modes viz. Single Contact, Multiple Contact and Chatroom. This was, until now, a gobal setting i.e. the mode setting applies to all users connected to Twitter-Backend. In other words, all the users together could be in one of the above three modes and it wasn't possible to have few users in Single Contact, few in Multiple Contact and few in Chatroom modes simultaneously. Further, this mode setting was controlled by the admin managing Twitter-Backend with no user level control.  Past few days, I worked on making mode configurable per-user. Now, each user can use '#mode  <mode-number>' command to switch to the mode that he wants to!

Monday 2 July 2012

Improved Response Messages from Twitter Backend

Today I worked on improving Twitter Backend by providing messages regarding the status of various commands Eg. "Status updated successfully", "Retweet successful" etc. Also, I tested Chatroom mode. Now all three modes (single, multiple and chatroom)  are supported by Twitter Backend.

Thursday 21 June 2012

Chatroom Mode

Today, I worked on the Chatroom mode where the user's twitter account is mapped to a chatroom. In this mode, the user can access his twitter account by joining the chatroom twitter-account. The user can then use the same commands that are available in the Single and Multiple contact modes for performing actions actions such as status update, direct messages, fetching home timeline, fetching user timeline etc. The code is still in its initial stages and needs to be tested properly.

Tuesday 19 June 2012

Screencast


A demo of how spectrum's Twitter-Backend can be used to access Twitter. I use Psi for testing/development, but it is also possible to use other clients like pidgin, gajim etc.


 


The steps involved in adding a twitter-account in Psi are outline below.
  1. Under General choose Account Setup.
  2. In the dialog that appears, click on Add to add a new account.
  3. Give a suitable name to the account and proceed to the next step.
  4. An  Account Properties dialog shows up. 
  5. In the Jabber ID field (Account tab) enter - <your twitter username>@twitter.com.
  6. In the Connection tab choose Manually Specify Server Host/Port and enter the IP address (hostname) of the machine on which the spectrum server is running along with the port on which the spectrum listens to incoming connections (Default - 5222).
  7. Click on save and exit Account Properties dialog.

Multiple Contact Mode

Currently, twitter-backend supports two types of modes:
  • Single Contact
  • Multiple Contact
In the Single Contact mode, the XMPP user's roster will have only one contact corresponding to his twitter account labelled twitter. The user can interact with the Twitter network via this special contact that represents his account.

In this Multiple Contact mode, the XMPP user's roster will have the aforementioned special twitter contact and one contact each for the user's followers. Some of the features in this mode include adding /removing contact via the UI (depends on the client used the user), sending/receiving direct messages by clicking on the contact corresponding to the user.

The next step would be to work on the chatroom mode, where the users twitter account will be mapped onto a chatroom.

Friday 15 June 2012

Some more features....

  • Twitter-backend now supports retweeting. The user can use the command #retweet <unique_tweet_id> to retweet. 
  • The user can also follow/unfollow users now using the #follow and #unfollow commands. 

Monday 11 June 2012

Direct Message Updates

Twitter Backend now periodically polls and updates user regarding any new Direct Messages sent to the user by one of his followers. I also added code to populate user's roster with all his twitter friends. As a result, sending direct messages is easier now! The user can just click on one of his contacts and send him a direct message instead of sending direct messages via the special twitter contact using the '@username' command.

Sunday 10 June 2012

Tweet Updates

After making the twitter requests asynchronous, last week I worked on polling the user's home timeline and sending the user updates regarding the new tweets by one of his followers.  I also fixed a minor bug with the POST version of fetch friend request.

Sunday 3 June 2012

Asynchronous Twitter Requests

Over the past three days I worked on making twitter requests asynchronous, which was not the case earlier, mainly due to the CURL calls in libtwitcurl library. The main idea - "Run each request in a separate thread without blocking the main thread". One of the main tasks was to create a generic thread pool framework that provides an easy, clean interface to manage thread life-cycle. The next task was to re-write/re-organize some of the existing code to create requests that can make use of  this thread pool library, thus allowing multiple requests to run concurrently without blocking the main thread. The end result: Twitter-Backend is now more scalable and robust!

Thursday 31 May 2012

Directed Message

Spectrum twitter backend now allows spectrum users to send direct messages to their twitter contacts! Also, I re-organized the code a bit to make it cleaner and easier to read.

Wednesday 30 May 2012

XML Parser to Parse Twitter Responses

Twitter offers wide range response formats viz. XML, json, rss and atom to choose from. However, twitcurl, the library that spectrum-twitter backend uses to interact with Twitter, uses XML. Hence, it was necessary to have an XML parser to  parse twitter response data and send this parsed data back to the user. Luckily, Swiften, one of the libraries used by spectrum, already had the necessary code to write XML parsers. I finally (with a bit of help from my mentor;)) finished writing a basic XML parser that can parse status messages returned by twitter in XML. The user can now view his timeline:)

Tuesday 29 May 2012

Added Database Support to Store OAuth Access Token

Twitter backend uses OAuth access token to perform operations such as status update, sending directed messages etc. on behalf of the user who authorizes the app. Obtaining the OAuth access token is a three step process which is given below:
  1. When the user tries to access his twitter-account via spectrum, spectrum asks the users to visits an authorization URL that it receives by contacting twitter and asks the user to authorize spectrum. 
  2. The User visits the authorization URL to authorizes spectrum. When the user grants spectrum the requested permissions, twitter redirects the user to another page where it provides a unique number called PIN that has to be returned to the application (spectrum). 
  3. The user then returns to spectrum and gives the PIN that he/she obtained from twitter. Spectrum then exchanges this PIN for OAuth access token from twitter, which grants spectrum access to the the user's twitter account. 
In order to avoid having to go through this three step process each time the user logs in, twitter-backend stores the OAuth access token in a database and uses it directly the next time user logs in. 

Thursday 24 May 2012

Logging into Twitter and Status update

Finally pushed code for 'logging into twitter' and 'status update' via spectrum! The code as of now is in its initial stages without exception handling etc. Nevertheless, I now have a basic setup in place to proceed further :)

Saturday 19 May 2012

GSoC 2012 Coding Phase (2 days to go)

I got accepted to GSoC 2012, my first GSoC! I will be working on the spectrum project, which comes under XSF. During this summer, as a part of GSoC, I will be working on adding twitter support to spectrum! Super excited and can't wait to start off!!