Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[sociald] Implemented plugins for event view status posting. Contribu…
…tes to JB#8922
- Loading branch information
Antti Seppälä
committed
Sep 24, 2013
1 parent
02f8d08
commit 778af4d
Showing
7 changed files
with
149 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import QtQuick 2.0 | ||
import Sailfish.Accounts 1.0 | ||
import com.jolla.settings.accounts 1.0 | ||
|
||
Item { | ||
id: updater | ||
|
||
property string statusUpdate | ||
property alias accountId: _account.identifier | ||
property QtObject keyProvider: _keyProvider | ||
property QtObject account: _account | ||
property SignInParameters signInParams | ||
property variant signInData | ||
|
||
signal postRequestDone(Item item) | ||
signal postRequestError(Item item) | ||
|
||
StoredKeyProvider { | ||
id: _keyProvider | ||
} | ||
|
||
Account { | ||
id: _account | ||
function performSignIn() { | ||
if (updater.signInParams === null) { | ||
console.log("SocialStatusUpdater: No sign-in params provided.") | ||
updater.postRequestError(updater) | ||
} else if (status === Account.Initialized && identifier !== -1) { | ||
updater.signInParams.setParameter("UiPolicy", SignInParameters.NoUserInteractionPolicy) | ||
signIn("Jolla", "Jolla", updater.signInParams) | ||
} | ||
} | ||
|
||
onStatusChanged: performSignIn() | ||
onSignInResponse: updater.signInData = data | ||
onSignInError: { | ||
console.log("SocialStatusUpdater: sign-in error: " + message + "\n") | ||
updater.postRequestDone(updater) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import QtQuick 2.0 | ||
import "shared" | ||
|
||
SocialStatusUpdater { | ||
id: updater | ||
|
||
onSignInDataChanged: { | ||
// FIXME: Done with XMLHttpRequest for now. Start using social API | ||
// as soon as it is available. | ||
var doc = new XMLHttpRequest() | ||
doc.onreadystatechange = function() { | ||
if (doc.readyState === XMLHttpRequest.DONE) { | ||
if (status === 200) { | ||
updater.postRequestDone(updater) | ||
} else { | ||
updater.postRequestError(updater) | ||
} | ||
} | ||
} | ||
|
||
var postData = "access_token=" + | ||
signInData["AccessToken"] + | ||
"&message="+updater.statusUpdate | ||
|
||
var url = "https://graph.facebook.com/me/feed" | ||
doc.open("POST", url) | ||
doc.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded') | ||
doc.setRequestHeader('Content-Length', postData.length) | ||
doc.send(postData) | ||
} | ||
|
||
Component.onCompleted: { | ||
signInParams = updater.account.signInParameters("facebook-microblog") | ||
signInParams.setParameter("ClientId", updater.keyProvider.storedKey("facebook", "facebook-microblog", "client_id")) | ||
account.performSignIn() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import QtQuick 2.0 | ||
import org.nemomobile.social 1.0 | ||
import "shared" | ||
|
||
SocialStatusUpdater { | ||
id: updater | ||
|
||
property bool _posted | ||
|
||
onSignInDataChanged: { | ||
var accessTok = signInData["AccessToken"] | ||
if (accessTok !== "") { | ||
twitter.oauthToken = accessTok | ||
} | ||
var tokenSec = signInData["TokenSecret"] | ||
if (tokenSec !== "") { | ||
twitter.oauthTokenSecret = tokenSec | ||
} | ||
if (twitter.oauthToken === "" || twitter.oauthTokenSecret === "") { | ||
updater.postRequestError(posted) | ||
} | ||
} | ||
|
||
Twitter { | ||
id: twitter | ||
|
||
property bool credentialsReady: initialized | ||
&& consumerKey.length > 0 | ||
&& consumerSecret.length > 0 | ||
&& oauthToken.length > 0 | ||
&& oauthTokenSecret.length > 0 | ||
|
||
consumerKey: keyProvider.storedKey("twitter", "twitter-microblog", "consumer_key") | ||
consumerSecret: keyProvider.storedKey("twitter", "twitter-microblog", "consumer_secret") | ||
|
||
onCredentialsReadyChanged: { | ||
updater._posted = true | ||
user.uploadTweet(updater.statusUpdate) | ||
} | ||
} | ||
|
||
TwitterUser { | ||
id: user | ||
socialNetwork: twitter | ||
|
||
onErrorChanged: { | ||
console.log("TwitterUser error: " + error + "\n") | ||
updater.postRequestError(updater) | ||
} | ||
|
||
onStatusChanged: { | ||
if (status === Twitter.Idle && updater._posted) { | ||
// success | ||
updater.postRequestDone(updater) | ||
} | ||
} | ||
} | ||
|
||
Component.onCompleted: { | ||
signInParams = updater.account.signInParameters("twitter-microblog") | ||
signInParams.setParameter("ConsumerKey", twitter.consumerKey) | ||
signInParams.setParameter("ConsumerSecret", twitter.consumerSecret) | ||
account.performSignIn() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters