1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-02-26 04:43:06 +01:00

Interim work at fetching direct messages

This commit is contained in:
Jeff Mitchell 2011-02-12 15:08:59 -05:00
parent 782a38ec5a
commit eee324d9c2
4 changed files with 129 additions and 47 deletions

View File

@ -430,70 +430,84 @@ QString
TomahawkSettings::twitterOAuthToken() const
{
QMutexLocker locker( m_safety );
return value( "twitter/oauthtoken" ).toString();
return value( "twitter/OAuthToken" ).toString();
}
void
TomahawkSettings::setTwitterOAuthToken( const QString& oauthtoken )
{
QMutexLocker locker( m_safety );
setValue( "twitter/oauthtoken", oauthtoken );
setValue( "twitter/OAuthToken", oauthtoken );
}
QString
TomahawkSettings::twitterOAuthTokenSecret() const
{
QMutexLocker locker( m_safety );
return value( "twitter/oauthtokensecret" ).toString();
return value( "twitter/OAuthTokenSecret" ).toString();
}
void
TomahawkSettings::setTwitterOAuthTokenSecret( const QString& oauthtokensecret )
{
QMutexLocker locker( m_safety );
setValue( "twitter/oauthtokensecret", oauthtokensecret );
setValue( "twitter/OAuthTokenSecret", oauthtokensecret );
}
qint64
TomahawkSettings::twitterCachedFriendsSinceId() const
{
QMutexLocker locker( m_safety );
return value( "twitter/cachedfriendssinceid", 0 ).toLongLong();
return value( "twitter/CachedFriendsSinceID", 0 ).toLongLong();
}
void
TomahawkSettings::setTwitterCachedFriendsSinceId( qint64 cachedId )
{
QMutexLocker locker( m_safety );
setValue( "twitter/cachedfriendssinceid", cachedId );
setValue( "twitter/CachedFriendsSinceID", cachedId );
}
qint64
TomahawkSettings::twitterCachedMentionsSinceId() const
{
QMutexLocker locker( m_safety );
return value( "twitter/cachedmentionssinceid", 0 ).toLongLong();
return value( "twitter/CachedMentionsSinceID", 0 ).toLongLong();
}
void
TomahawkSettings::setTwitterCachedMentionsSinceId( qint64 cachedId )
{
QMutexLocker locker( m_safety );
setValue( "twitter/cachedmentionssinceid", cachedId );
setValue( "twitter/CachedMentionsSinceID", cachedId );
}
qint64
TomahawkSettings::twitterCachedDirectMessagesSinceId() const
{
QMutexLocker locker( m_safety );
return value( "twitter/CachedDirectMessagesSinceID", 0 ).toLongLong();
}
void
TomahawkSettings::setTwitterCachedDirectMessagesSinceId( qint64 cachedId )
{
QMutexLocker locker( m_safety );
setValue( "twitter/CachedDirectMessagesSinceID", cachedId );
}
QHash<QString, QVariant>
TomahawkSettings::twitterCachedPeers() const
{
QMutexLocker locker( m_safety );
return value( "twitter/cachedpeers", QHash<QString, QVariant>() ).toHash();
return value( "twitter/CachedPeers", QHash<QString, QVariant>() ).toHash();
}
void
TomahawkSettings::setTwitterCachedPeers( const QHash<QString, QVariant> &cachedPeers )
{
QMutexLocker locker( m_safety );
setValue( "twitter/cachedpeers", cachedPeers );
setValue( "twitter/CachedPeers", cachedPeers );
}
bool

View File

@ -109,6 +109,9 @@ public:
qint64 twitterCachedMentionsSinceId() const;
void setTwitterCachedMentionsSinceId( qint64 sinceid );
qint64 twitterCachedDirectMessagesSinceId() const;
void setTwitterCachedDirectMessagesSinceId( qint64 sinceid );
QHash<QString, QVariant> twitterCachedPeers() const;
void setTwitterCachedPeers( const QHash<QString, QVariant> &cachedPeers );

View File

@ -5,7 +5,6 @@
#include <qtweetaccountverifycredentials.h>
#include <qtweetuser.h>
#include <qtweetfriendstimeline.h>
#include <qtweetstatus.h>
#include <utils/tomahawkutils.h>
@ -18,12 +17,15 @@ TwitterPlugin::TwitterPlugin()
, m_checkTimer( this )
, m_cachedFriendsSinceId( 0 )
, m_cachedMentionsSinceId( 0 )
, m_cachedDirectMessagesSinceId( 0 )
, m_cachedPeers()
, m_finishedFriends( false )
, m_finishedMentions( false )
{
qDebug() << Q_FUNC_INFO;
m_checkTimer.setInterval( 60000 );
m_checkTimer.setSingleShot( false );
QObject::connect( &m_checkTimer, SIGNAL( timeout() ), SLOT( checkTimerFired() ) );
connect( &m_checkTimer, SIGNAL( timeout() ), SLOT( checkTimerFired() ) );
m_checkTimer.start();
}
@ -68,7 +70,7 @@ TwitterPlugin::connectPlugin( bool /*startup*/ )
m_twitterAuth.data()->setOAuthTokenSecret( settings->twitterOAuthTokenSecret().toLatin1() );
QTweetAccountVerifyCredentials *credVerifier = new QTweetAccountVerifyCredentials( m_twitterAuth.data(), this );
QObject::connect( credVerifier, SIGNAL( parsedUser(const QTweetUser &) ), SLOT( connectAuthVerifyReply(const QTweetUser &) ) );
connect( credVerifier, SIGNAL( parsedUser(const QTweetUser &) ), SLOT( connectAuthVerifyReply(const QTweetUser &) ) );
credVerifier->verify();
/*
QObject::connect( m_zeroconf, SIGNAL( tomahawkHostFound( const QString&, int, const QString&, const QString& ) ),
@ -107,9 +109,11 @@ TwitterPlugin::connectAuthVerifyReply( const QTweetUser &user )
{
m_friendsTimeline = QWeakPointer<QTweetFriendsTimeline>( new QTweetFriendsTimeline( m_twitterAuth.data(), this ) );
m_mentions = QWeakPointer<QTweetMentions>( new QTweetMentions( m_twitterAuth.data(), this ) );
QObject::connect( m_friendsTimeline.data(), SIGNAL( parsedStatuses(const QList< QTweetStatus > &) ), SLOT( friendsTimelineStatuses(const QList<QTweetStatus> &) ) );
QObject::connect( m_mentions.data(), SIGNAL( parsedStatuses(const QList< QTweetStatus > &) ), SLOT( mentionsStatuses(const QList<QTweetStatus> &) ) );
QMetaObject::invokeMethod( this, "checkTimerFired", Qt::DirectConnection );
m_directMessages = QWeakPointer<QTweetDirectMessages>( new QTweetDirectMessages( m_twitterAuth.data(), this ) );
connect( m_friendsTimeline.data(), SIGNAL( parsedStatuses(const QList< QTweetStatus > &) ), SLOT( friendsTimelineStatuses(const QList<QTweetStatus> &) ) );
connect( m_mentions.data(), SIGNAL( parsedStatuses(const QList< QTweetStatus > &) ), SLOT( mentionsStatuses(const QList<QTweetStatus> &) ) );
connect( m_directMessages.data(), SIGNAL( parsedStatuses(const QList< QTweetDMStatus > &) ), SLOT( mentionsStatuses(const QList<QTweetDMStatus> &) ) );
QMetaObject::invokeMethod( this, "checkTimerFired", Qt::AutoConnection );
}
else
{
@ -122,24 +126,24 @@ TwitterPlugin::connectAuthVerifyReply( const QTweetUser &user )
void
TwitterPlugin::checkTimerFired()
{
if ( isValid() )
{
if ( m_cachedFriendsSinceId == 0 )
m_cachedFriendsSinceId = TomahawkSettings::instance()->twitterCachedFriendsSinceId();
qDebug() << "TwitterPlugin using friend timeline id of " << m_cachedFriendsSinceId;
if ( !m_friendsTimeline.isNull() )
m_friendsTimeline.data()->fetch( m_cachedFriendsSinceId, 0, 800 );
if ( m_cachedMentionsSinceId == 0 )
m_cachedMentionsSinceId = TomahawkSettings::instance()->twitterCachedMentionsSinceId();
qDebug() << "TwitterPlugin using mentions timeline id of " << m_cachedMentionsSinceId;
if ( !m_mentions.isNull() )
m_mentions.data()->fetch( m_cachedMentionsSinceId, 0, 800 );
}
if ( !isValid() )
return;
if ( m_cachedFriendsSinceId == 0 )
m_cachedFriendsSinceId = TomahawkSettings::instance()->twitterCachedFriendsSinceId();
qDebug() << "TwitterPlugin using friend timeline id of " << m_cachedFriendsSinceId;
if ( !m_friendsTimeline.isNull() )
m_friendsTimeline.data()->fetch( m_cachedFriendsSinceId, 0, 800 );
if ( m_cachedMentionsSinceId == 0 )
m_cachedMentionsSinceId = TomahawkSettings::instance()->twitterCachedMentionsSinceId();
qDebug() << "TwitterPlugin using mentions timeline id of " << m_cachedMentionsSinceId;
if ( !m_mentions.isNull() )
m_mentions.data()->fetch( m_cachedMentionsSinceId, 0, 800 );
}
void
TwitterPlugin::friendsTimelineStatuses( const QList< QTweetStatus >& statuses )
TwitterPlugin::friendsTimelineStatuses( const QList< QTweetStatus > &statuses )
{
qDebug() << Q_FUNC_INFO;
QRegExp regex( QString( "^(@[a-zA-Z0-9]+ )?Got Tomahawk\\?(.*)$" ) );
@ -147,22 +151,27 @@ TwitterPlugin::friendsTimelineStatuses( const QList< QTweetStatus >& statuses )
{
if ( status.id() > m_cachedFriendsSinceId )
m_cachedFriendsSinceId = status.id();
QString statusText = status.text();
if ( regex.exactMatch( statusText ) )
if ( regex.exactMatch( status.text() ) )
{
qDebug() << "TwitterPlugin found an exact tweet from friend " << status.user().screenName();
QHash<QString, QVariant> peerData;
peerData["host"] = QVariant::fromValue<QString>( "somehost" );
peerData["port"] = QVariant::fromValue<QString>( "port" );
m_cachedPeers[status.user().screenName()] = QVariant::fromValue< QHash< QString, QVariant > >( peerData );
if ( ! m_cachedPeers.contains( status.user().screenName() ) )
{
QHash< QString, QVariant > peerData;
peerData["sentuid"] = QVariant::fromValue< QString >( uuid() );
m_cachedPeers[status.user().screenName()] = QVariant::fromValue< QHash< QString, QVariant > >( peerData );
}
}
}
TomahawkSettings::instance()->setTwitterCachedFriendsSinceId( m_cachedFriendsSinceId );
m_finishedFriends = true;
QMetaObject::invokeMethod( this, "pollDirectMessages", Qt::AutoConnection );
}
void
TwitterPlugin::mentionsStatuses( const QList< QTweetStatus >& statuses )
TwitterPlugin::mentionsStatuses( const QList< QTweetStatus > &statuses )
{
qDebug() << Q_FUNC_INFO;
QRegExp regex( QString( "^(@[a-zA-Z0-9]+ )?Got Tomahawk\\?(.*)$" ) );
@ -170,18 +179,66 @@ TwitterPlugin::mentionsStatuses( const QList< QTweetStatus >& statuses )
{
if ( status.id() > m_cachedMentionsSinceId )
m_cachedMentionsSinceId = status.id();
QString statusText = status.text();
if ( regex.exactMatch( statusText ) )
if ( regex.exactMatch( status.text() ) )
{
qDebug() << "TwitterPlugin found an exact matching mention from user " << status.user().screenName();
QHash<QString, QVariant> peerData;
peerData["host"] = QVariant::fromValue<QString>( "somehost" );
peerData["port"] = QVariant::fromValue<QString>( "port" );
m_cachedPeers[status.user().screenName()] = QVariant::fromValue< QHash< QString, QVariant > >( peerData );
if ( ! m_cachedPeers.contains( status.user().screenName() ) )
{
QHash< QString, QVariant > peerData;
peerData["sentuid"] = QVariant::fromValue< QString >( uuid() );
m_cachedPeers[status.user().screenName()] = QVariant::fromValue< QHash< QString, QVariant > >( peerData );
}
}
}
TomahawkSettings::instance()->setTwitterCachedMentionsSinceId( m_cachedMentionsSinceId );
m_finishedMentions = true;
QMetaObject::invokeMethod( this, "pollDirectMessages", Qt::AutoConnection );
}
void
TwitterPlugin::pollDirectMessages()
{
if ( !m_finishedMentions || !m_finishedFriends )
return;
m_finishedFriends = false;
m_finishedMentions = false;
if ( !isValid() )
return;
if ( m_cachedDirectMessagesSinceId == 0 )
m_cachedDirectMessagesSinceId = TomahawkSettings::instance()->twitterCachedDirectMessagesSinceId();
qDebug() << "TwitterPlugin using direct messages id of " << m_cachedDirectMessagesSinceId;
if ( !m_directMessages.isNull() )
m_directMessages.data()->fetch( m_cachedDirectMessagesSinceId, 0, 800 );
}
void
TwitterPlugin::directMessages( const QList< QTweetDMStatus > &messages )
{
qDebug() << Q_FUNC_INFO;
QRegExp regex( QString( "^(@[a-zA-Z0-9]+ )?Got Tomahawk\\?(.*)$" ) );
foreach( QTweetDMStatus status, messages )
{
if ( status.id() > m_cachedDirectMessagesSinceId )
m_cachedDirectMessagesSinceId = status.id();
if ( regex.exactMatch( status.text() ) )
{
qDebug() << "TwitterPlugin found an exact matching mention from user " << status.sender().screenName();
if ( ! m_cachedPeers.contains( status.sender().screenName() ) )
{
QHash< QString, QVariant > peerData;
peerData["sentuid"] = QVariant::fromValue< QString >( uuid() );
m_cachedPeers[status.sender().screenName()] = QVariant::fromValue< QHash< QString, QVariant > >( peerData );
}
}
}
TomahawkSettings::instance()->setTwitterCachedDirectMessagesSinceId( m_cachedDirectMessagesSinceId );
}
void

View File

@ -7,7 +7,9 @@
#include <qtweetuser.h>
#include <qtweetnetbase.h>
#include <qtweetfriendstimeline.h>
#include <qtweetdirectmessages.h>
#include <qtweetmentions.h>
#include <qtweetdmstatus.h>
#include "../sipdllmacro.h"
#include "sip/SipPlugin.h"
@ -51,16 +53,22 @@ private slots:
void checkTimerFired();
void friendsTimelineStatuses( const QList< QTweetStatus > &statuses );
void mentionsStatuses( const QList< QTweetStatus > &statuses );
void pollDirectMessages();
void directMessages( const QList< QTweetDMStatus > &messages );
private:
QWeakPointer<TomahawkOAuthTwitter> m_twitterAuth;
QWeakPointer<QTweetFriendsTimeline> m_friendsTimeline;
QWeakPointer<QTweetMentions> m_mentions;
QWeakPointer< TomahawkOAuthTwitter > m_twitterAuth;
QWeakPointer< QTweetFriendsTimeline > m_friendsTimeline;
QWeakPointer< QTweetMentions > m_mentions;
QWeakPointer< QTweetDirectMessages > m_directMessages;
bool m_isAuthed;
QTimer m_checkTimer;
qint64 m_cachedFriendsSinceId;
qint64 m_cachedMentionsSinceId;
QHash<QString, QVariant> m_cachedPeers;
qint64 m_cachedDirectMessagesSinceId;
QHash< QString, QVariant > m_cachedPeers;
bool m_finishedFriends;
bool m_finishedMentions;
};
#endif