status.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. (function (state) {
  2. var p2p = state.p2p.broker && state.p2p.broker.open
  3. //, ppl = state.people / 2; // counts socket connections, which are 2 per user
  4. //if (ppl < 0) {
  5. //ppl = "less than zero people online. само нечовеци. or rather a bug"
  6. //} else if (ppl === 0 && state.server) {
  7. //ppl = "if a tree falls in a forest and nobody is there to hear it, do the crushed squirrels make a sound?"
  8. //} else if (ppl === 1) {
  9. //ppl = "you are alone. better post something! this will make you less alone."
  10. //} else {
  11. //ppl = "~ " + ppl + " people here"
  12. //}
  13. var username = $.h("input#username",
  14. { type: "text"
  15. , placeholder: "onanimus"
  16. , value: $.state.user.nick()
  17. , onchange: $.emit("username") });
  18. var newThread = $.h("a.statusThread",
  19. { href: "#submitForm"
  20. , onclick: function () { document.getElementById("submitText").focus() } },
  21. statusThreadDetails("+ submit", "new thread..."))
  22. var threads = Object.keys(state.threads).reverse().map(statusThread);
  23. return $.h(".status",
  24. [ username
  25. //, $.h(".statusItem", [ $.h("input#password", { type: "password", placeholder: "secret (for tripcode)" }) ])
  26. , $.h(".statusItem", (state.server ? "" : "not ") + "connected to server")
  27. //, $.h(".statusItem", ppl)
  28. //, $.h(".statusItem", (p2p ? "" : "not ") + "connected to peer broker")
  29. //, $.h(".statusItem", "connected to " + state.p2p.peers.length + " peers") ])
  30. , $.h(".statusThreads", [newThread].concat(threads))
  31. ])
  32. function statusThread (threadId) {
  33. var thread = state.threads[threadId]
  34. , first = thread.posts[0]
  35. , last = thread.posts[thread.posts.length - 1]
  36. , newPosts = $.util.getNewPosts(threadId)
  37. , firstNew = $.util.getFirstNewPost(threadId);
  38. return $.h("a.statusThread",
  39. { href: newPosts
  40. ? '#post_' + firstNew
  41. : '#thread_' + thread.id
  42. , onclick: $.util.scrollToFirstNewPost(thread.id) },
  43. [ newPosts ? $.h(".statusThreadNewPosts", String(newPosts)) : null
  44. , $.h(".statusThreadDetails", statusThreadDetails(
  45. first.user || $.h("em", "onan."),
  46. first.text || $.h("em", "(кура ми янко)")
  47. ).concat([ first === last ? null : $.h("div", statusThreadDetails(
  48. last.user || $.h("em", "onan."),
  49. last.text || $.h("em", "(кура ми янко)"))) ])) ]) }
  50. function statusThreadDetails (user, text) {
  51. return [ $.h(".statusThreadUser", user)
  52. , $.h(".statusThreadText", text) ]; }
  53. })