Skip to content
Browse files

make things more friendly for the public deployment

  • Loading branch information...
1 parent 1e2ed61 commit 459d3e9ca008f628df27e9b7c32965202fd68f80 @jchris committed Sep 17, 2010
View
4 _attachments/index.html
@@ -13,6 +13,10 @@
<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>
View
2 evently/items/_common/selectors/ul/_changes/selectors/a[href=#rt]/click.js
@@ -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+'?'
View
8 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>
View
21 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(' '));
+ }
+ }
+ });
+};
View
5 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;
+};
View
45 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)
+});
View
63 node/twebzbot.js
@@ -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);
@@ -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,
@@ -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");
}

0 comments on commit 459d3e9

Please sign in to comment.
Something went wrong with that request. Please try again.