From 2d918156d130e80d1816aec5f919780ae83cafb0 Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Sat, 12 Feb 2011 19:15:08 -0500 Subject: [PATCH] Add some error logging and the connection timer --- src/sip/twitter/twitter.cpp | 43 +++++++++++++++++++++++++++++++++++-- src/sip/twitter/twitter.h | 3 +++ 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/src/sip/twitter/twitter.cpp b/src/sip/twitter/twitter.cpp index 821ed002b..fa2d3d6d3 100644 --- a/src/sip/twitter/twitter.cpp +++ b/src/sip/twitter/twitter.cpp @@ -18,6 +18,7 @@ TwitterPlugin::TwitterPlugin() : SipPlugin() , m_isAuthed( false ) , m_checkTimer( this ) + , m_connectTimer( this ) , m_cachedFriendsSinceId( 0 ) , m_cachedMentionsSinceId( 0 ) , m_cachedDirectMessagesSinceId( 0 ) @@ -30,6 +31,11 @@ TwitterPlugin::TwitterPlugin() m_checkTimer.setSingleShot( false ); connect( &m_checkTimer, SIGNAL( timeout() ), SLOT( checkTimerFired() ) ); m_checkTimer.start(); + + m_connectTimer.setInterval( 60000 ); + m_connectTimer.setSingleShot( false ); + connect( &m_connectTimer, SIGNAL( timeout() ), SLOT( connectTimerFired() ) ); + m_connectTimer.start(); } bool @@ -116,6 +122,7 @@ TwitterPlugin::connectAuthVerifyReply( const QTweetUser &user ) connect( m_mentions.data(), SIGNAL( parsedStatuses(const QList< QTweetStatus > &) ), SLOT( mentionsStatuses(const QList &) ) ); connect( m_directMessages.data(), SIGNAL( parsedStatuses(const QList< QTweetDMStatus > &) ), SLOT( directMessages(const QList &) ) ); connect( m_directMessageNew.data(), SIGNAL( parsedStatuses(const QList< QTweetDMStatus > &) ), SLOT( directMessagePosted(const QTweetDMStatus &) ) ); + connect( m_directMessageNew.data(), SIGNAL( error(QTweetNetBase::ErrorCode, const QString &) ), SLOT( directMessagePostError(QTweetNetBase::ErrorCode, const QString &) ) ); connect( m_directMessageDestroy.data(), SIGNAL( parsedStatuses(const QList< QTweetDMStatus > &) ), SLOT( directMessageDestoyed(const QTweetDMStatus &) ) ); QMetaObject::invokeMethod( this, "checkTimerFired", Qt::AutoConnection ); } @@ -146,6 +153,30 @@ TwitterPlugin::checkTimerFired() m_mentions.data()->fetch( m_cachedMentionsSinceId, 0, 800 ); } +void +TwitterPlugin::connectTimerFired() +{ + if ( !isValid() || m_cachedPeers.isEmpty() ) + return; + + QList peerlist = m_cachedPeers.keys(); + qStableSort( peerlist.begin(), peerlist.end() ); + foreach( QString screenName, peerlist ) + { + QHash< QString, QVariant > peerData = m_cachedPeers[screenName].toHash(); + if ( !peerData.contains( "node" ) || !peerData.contains( "host" ) || !peerData.contains( "port" ) || !peerData.contains( "pkey" ) ) + continue; + + if ( !peerData.contains( "ohst" ) || !peerData.contains( "oprt" ) || + peerData["ohst"].toString() != Servent::instance()->externalAddress() || + peerData["oprt"].toInt() != Servent::instance()->externalPort() + ) + QMetaObject::invokeMethod( this, "sendOffer", Q_ARG( QString, screenName ), QGenericArgument( "QHash< QString, QVariant >", (const void*)&peerData ) ); + else + QMetaObject::invokeMethod( this, "makeConnection", Q_ARG( QString, screenName ), QGenericArgument( "QHash< QString, QVariant >", (const void*)&peerData ) ); + } +} + void TwitterPlugin::friendsTimelineStatuses( const QList< QTweetStatus > &statuses ) { @@ -330,11 +361,19 @@ TwitterPlugin::sendOffer( const QString &screenName, const QHash< QString, QVari } void -TwitterPlugin::directMessagePosted(const QTweetDMStatus& message) +TwitterPlugin::directMessagePosted( const QTweetDMStatus& message ) { qDebug() << Q_FUNC_INFO; - qDebug() << "Message sent to " << message.recipientScreenName() << " containing: " << message.text();} + qDebug() << "Message sent to " << message.recipientScreenName() << " containing: " << message.text(); + +} +void +TwitterPlugin::directMessagePostError( QTweetNetBase::ErrorCode errorCode, const QString &message ) +{ + qDebug() << Q_FUNC_INFO; + qDebug() << "Received an error posting direct message: " << m_directMessageNew.data()->lastErrorMessage(); +} void TwitterPlugin::directMessageDestroyed(const QTweetDMStatus& message) diff --git a/src/sip/twitter/twitter.h b/src/sip/twitter/twitter.h index f67a70877..c9b7f365f 100644 --- a/src/sip/twitter/twitter.h +++ b/src/sip/twitter/twitter.h @@ -52,11 +52,13 @@ public slots: private slots: void connectAuthVerifyReply( const QTweetUser &user ); void checkTimerFired(); + void connectTimerFired(); void friendsTimelineStatuses( const QList< QTweetStatus > &statuses ); void mentionsStatuses( const QList< QTweetStatus > &statuses ); void pollDirectMessages(); void directMessages( const QList< QTweetDMStatus > &messages ); void directMessagePosted( const QTweetDMStatus &message ); + void directMessagePostError( QTweetNetBase::ErrorCode errorCode, const QString &message ); void directMessageDestroyed( const QTweetDMStatus &message ); void registerOffer( const QString &screenName, const QHash< QString, QVariant > &peerdata ); void sendOffer( const QString &screenName, const QHash< QString, QVariant > &peerdata ); @@ -71,6 +73,7 @@ private: QWeakPointer< QTweetDirectMessageDestroy > m_directMessageDestroy; bool m_isAuthed; QTimer m_checkTimer; + QTimer m_connectTimer; qint64 m_cachedFriendsSinceId; qint64 m_cachedMentionsSinceId; qint64 m_cachedDirectMessagesSinceId;