Skip to content

Commit

Permalink
make things more friendly for the public deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
jchris committed Sep 17, 2010
1 parent 1e2ed61 commit 459d3e9
Show file tree
Hide file tree
Showing 7 changed files with 134 additions and 14 deletions.
4 changes: 4 additions & 0 deletions _attachments/index.html
Expand Up @@ -13,6 +13,10 @@ <h1><a href="#/">Twebz</a> - Decentralizing Twitter, One Tweet at a Time</h1>
<div id="items"></div>

<div id="sidebar">
<div id="hello">
<p><a href="#/search/twebz">Click here to see discussion of Twebz.</a></p>
<p><a href="http://github.com/jchris/twebz">Get the source code here.</a></p>
</div>
<div id="wordcloud"></div>
</div>
</body>
Expand Down
Expand Up @@ -6,7 +6,7 @@ function() {
, sha1 = app.require("lib/sha1")
, udb = $.couch.db(twebz.user_db($$("#account").userCtx.name))
, li = $(a).parents("li")
, id = li.attr("data-id")
, id = li.attr("data-twitterid")
, twt = $.cookie("twitter_name")
, txt = $(".twbody p", li).text()
, message = 'Retweet "'+txt+'" as '+twt+'?'
Expand Down
8 changes: 8 additions & 0 deletions evently/profile/loggedOut/mustache.html
@@ -0,0 +1,8 @@
<p>You are logged out. You can browse and search the tweets already stored
in the Twebz database, but in order for any of the "load more tweets
from Twitter" options to work, you'll need to sign in.</p>
<form class="search">
<label>Search: <input type="text" name="search" size=20></label>
<input type="submit" value="Search">
<span class="matches"></span>
</form>
21 changes: 21 additions & 0 deletions evently/profile/loggedOut/selectors/form.search/keyup.js
@@ -0,0 +1,21 @@
function() {
var widget = $(this)
, term = $("input[name=search]", widget).val()
, app = $$(widget).app
, nonce = Math.random()
;
$$(widget).nonce = nonce;
app.db.list("twebz/topN","globalWordCount", {
startkey : [term],
endkey : [term+"\u9999"],
group_level : 1,
top : 10,
success : function(list) {
if ($$(widget).nonce == nonce) {
$("form.search span.matches").html(list.map(function(t) {
return '<a href="#/search/'+t+'">'+t+'</a>';
}).join(' '));
}
}
});
};
5 changes: 5 additions & 0 deletions evently/profile/loggedOut/selectors/form.search/submit.js
@@ -0,0 +1,5 @@
function() {
var term = $("input[name=search]", this).val();
$.pathbinder.go("/search/"+term);
return false;
};
45 changes: 45 additions & 0 deletions node/migrate.js
@@ -0,0 +1,45 @@
var couchdb = require("couchdb")
, client = couchdb.createClient(5984, "127.0.0.1", "jchris", "jchris")
, db = client.db("twebz")
;

function renameDoc(rows) {
process.nextTick(function() {
while (r = rows.pop()) {
if (r.id == parseInt(r.id).toString()) {
break;
}
}
// var r = rows.pop();
console.log(r.id);
db.getDoc(r.id, function(er, doc) {
if (er) {
console.log(["err getDoc", er])
} else {
var rev = doc._rev;
var oldid = doc._id;
delete doc._rev;
doc._id = "twitter-"+doc._id;
db.saveDoc(doc, function(er, resp) {
if (er && er.error != "conflict") {
console.log(er)
} else {
db.removeDoc(oldid, rev, function(er) {
if (er) {
console.log(["error deleting", oldid, er])
} else {
console.log("renamed", oldid)
renameDoc(rows);
}
});
}
});
}
});
});
};

db.allDocs(function(er, view) {
console.log("got rows", view.rows.length)
renameDoc(view.rows)
});
63 changes: 50 additions & 13 deletions node/twebzbot.js
Expand Up @@ -514,12 +514,39 @@ config_db.getDoc(twebz.twitter_keys_docid, function(er, doc) {
}
});
}
var oldHighSeq = 0, highSeq = 0;
setInterval(function() {
if (oldHighSeq != highSeq) {
db.getDoc("_local/twebz-seq", function(er, doc) {
if (doc) {
doc.seq = highSeq;
db.saveDoc(doc, function(er) {
if (!er) {
oldHighSeq = highSeq
}
});
} else {
db.saveDoc("_local/twebz-seq", {
seq : highSeq
}, function(er) {
if (!er) {
oldHighSeq = highSeq
}
});
}
});
}
}, 5000);

var machine = stately.define({
_before : function(change, cb) {
change.doc.twebz.seq = change.seq;
log("doc: "+change.doc._id+ " state: "+change.doc.twebz.state);
cb(change.doc);
highSeq = change.seq;
// log("chnage"+change.seq)
if (change.doc.twebz) {
// change.doc.twebz.seq = change.seq;
log("doc: "+change.doc._id+ " state: "+change.doc.twebz.state);
cb(change.doc);
}
},
_getState : function(doc, cb) {
cb(doc.twebz.state);
Expand Down Expand Up @@ -566,22 +593,30 @@ config_db.getDoc(twebz.twitter_keys_docid, function(er, doc) {

// listen for _changes on twebz db
function getSince(cb) {
db.view("twebz","seq", {random : Math.random()}, function(er, resp) {
if (er) {
log("getSince")
log(er)
db.getDoc("_local/twebz-seq", function(er, doc) {
if (doc) {
cb(doc.seq);
} else {
if (resp.rows && resp.rows.length > 0) {
cb(resp.rows[0].value.max);
} else {
cb(0);
}
cb(0);
}
});
// db.view("twebz","seq", {random : Math.random()}, function(er, resp) {
// if (er) {
// log("getSince")
// log(er)
// } else {
// if (resp.rows && resp.rows.length > 0) {
// cb(resp.rows[0].value.max);
// } else {
// cb(0);
// }
// }
// });
};

function workFromChanges() {
getSince(function(since) {
log("starting changes at "+since);
var stream = db.changesStream({
filter : "twebz/twebz",
include_docs : true,
Expand Down Expand Up @@ -611,7 +646,9 @@ config_db.getDoc(twebz.twitter_keys_docid, function(er, doc) {
}
});
var acct = resp.rows[0].value;
startSearchStream(acct.couch_user, acct.twitter_user.user_id);
if (acct.couch_user && acct.twitter_user && acct.twitter_user.user_id) {
startSearchStream(acct.couch_user, acct.twitter_user.user_id);
}
} else {
log("no users signed up yet");
}
Expand Down

0 comments on commit 459d3e9

Please sign in to comment.