Skip to content

Commit

Permalink
retweets!
Browse files Browse the repository at this point in the history
  • Loading branch information
jchris committed Sep 7, 2010
1 parent 9365ab2 commit 08f743d
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 6 deletions.
12 changes: 11 additions & 1 deletion _attachments/style/main.css
Expand Up @@ -74,10 +74,20 @@ div.twbody {
width:90%;
}

div.twbody .date {
div.twbody .ctrl {
float:right;
font-size:80%;
color:#bbb;
text-align:right;
}

div.twbody .ctrl a {
color:#bbb;
text-decoration:none;
}

div.twbody .ctrl a:hover {
color:#00e;
}

div.twbody p {
Expand Down
8 changes: 6 additions & 2 deletions evently/_partials/tweetli.html
@@ -1,11 +1,15 @@
<li>
<li data-id="{{_id}}">
<div class="avatar">
{{#image_url}}
<a href="#/user/{{name}}"><img src="{{image_url}}" alt="{{name}}"/></a>
{{/image_url}}
</div>
<div class="twbody">
<span class="date" title="{{created_at}}">{{pretty_date}}</span>
<div class="ctrl">
<span class="date" title="{{created_at}}">{{pretty_date}}</span>
<br/>
<a title="reply" href="#reply">&#8617;</a> <a title="retweet" href="#rt">&#x267B;</a>
</div>
<div class="name">
<a href="#/user/{{name}}">{{nickname}}</a>
</div>
Expand Down
@@ -0,0 +1,40 @@
function() {
var a = $(this)
, app = $$(a).app
, twebz = app.require("lib/twebz").init(app.db.name)
, jsond = app.require("lib/jsond")
, sha1 = app.require("lib/sha1")
, udb = $.couch.db(twebz.user_db($$("#account").userCtx.name))
, li = $(a).parents("li")
, id = li.attr("data-id")
, twt = $.cookie("twitter_name")
, txt = $(".twbody p", li).text()
, message = 'Retweet "'+txt+'" as '+twt+'?'
, rtDoc = {
_id : $.couch.newUUID(),
twebz : {
type : "retweet",
state : "unsent",
id : id,
couch_user : $$("#account").userCtx.name,
twitter_acct : $.cookie("twitter_acct")
}
}
;
if (confirm(message)) {
udb.openDoc(twebz.secret_docid, {
success : function(doc) {
var key = doc.token;
var string = jsond.stringify(rtDoc)
, hmac = sha1.b64_hmac_sha1(key, string)
;
rtDoc.twebz_signature = {
method : "b64_hmac_sha1",
token : hmac
};
app.db.saveDoc(rtDoc);
}
})
}
return false;
};
@@ -1,5 +1,8 @@
function() {
var val = $(this).val();
var val = $(this).val()
, txt = $(":selected", this).text()
;
$.cookie("twitter_name", txt);
$.cookie("twitter_acct", val);
return false;
};
@@ -1,4 +1,8 @@
function() {
var val = $(this).val();
var val = $(this).val()
, txt = $(":selected", this).text()
;
$.cookie("twitter_name", txt);
$.cookie("twitter_acct", val);
return false;
};
3 changes: 2 additions & 1 deletion lib/twebz.js
Expand Up @@ -32,6 +32,7 @@ exports.tweetli = function(doc) {
nickname : user.name || user.screen_name,
message : linkup.encode(doc.text, "#/user/", "#/search/"),
pretty_date : utils.prettyDate(doc.created_at),
created_at : doc.created_at
created_at : doc.created_at,
_id : doc._id
};
};
25 changes: 25 additions & 0 deletions node/twebzbot.js
Expand Up @@ -222,6 +222,28 @@ config_db.getDoc(twebz.twitter_keys_docid, function(er, doc) {
}
}

function sendRetweet(doc) {
// first check the hmac
var udb = client.db(twebz.user_db(doc.twebz.couch_user));
udb.getDoc(twebz.secret_docid, function(er, secret) {
if (ok(er, doc)) {
var key = secret.token;
if (validSignature(key, doc)) {
twitterConnection(doc.twebz.couch_user,
doc.twebz.twitter_acct, {}, function(tc) {
tc.retweet(doc.twebz.id, function(er, resp) {
if (ok(er, doc)) {
log("sent retweet for "+doc.twebz.twitter_acct+": "+doc.twebz.id);
doc.twebz.state = 'sent';
db.saveDoc(doc);
}
});
});
}
}
});
};

function sendTweet(doc) {
// first check the hmac
var udb = client.db(twebz.user_db(doc.twebz.profile.name));
Expand Down Expand Up @@ -365,6 +387,9 @@ config_db.getDoc(twebz.twitter_keys_docid, function(er, doc) {
tweet : {
unsent : sendTweet
},
retweet : {
unsent : sendRetweet
},
"user-recent" : {
request : requestRecentTweets
},
Expand Down

0 comments on commit 08f743d

Please sign in to comment.