diff --git a/pub/talklog/hymn.hook b/pub/talklog/hymn.hook new file mode 100644 index 0000000000..7067130d2d --- /dev/null +++ b/pub/talklog/hymn.hook @@ -0,0 +1,32 @@ +:: Talk log front-end +:: +:::: /hook/hymn/talklog/pub + :: +/? 310 +/= mez /: /===/talk /% /; pojo /json/ +|% +++ cdnj |=(a=tape ;script(src "//cdnjs.cloudflare.com/ajax/libs/{a}");) +-- +:: +:::: + :: +^- manx +;html + ;head + ;title: Talk Log + ;* %- turn :_ cdnj ^- wall + :~ "jquery/2.1.1/jquery.min.js" + "lodash.js/2.4.1/lodash.min.js" + "react/0.13.0/react.js" + == == + ;body + ;div#cont; + ;script(type "text/javascript", src "/~/at/home/lib/urb.js"); + ;link/"/home/pub/talk/src/css/main.css"(type "text/css", rel "stylesheet"); + ;script: window.MessageData = {mez} + ;script@"src/MessagesComponent.coffee"(type "text/coffeescript"); + ;script@"src/util.coffee"(type "text/coffeescript"); + ;script@"src/main.coffee"(type "text/coffeescript"); + ;+ (cdnj "coffee-script/1.7.1/coffee-script.min.js") + == +== diff --git a/pub/talklog/src/MessagesComponent.coffee b/pub/talklog/src/MessagesComponent.coffee new file mode 100644 index 0000000000..3851ac251b --- /dev/null +++ b/pub/talklog/src/MessagesComponent.coffee @@ -0,0 +1,82 @@ +recl = React.createClass +{div,pre,br,input,textarea,a} = React.DOM + + +Message = recl + lz: (n) -> if n<10 then "0#{n}" else "#{n}" + + convTime: (time) -> + d = new Date time + h = @lz d.getHours() + m = @lz d.getMinutes() + s = @lz d.getSeconds() + "~#{h}.#{m}.#{s}" + + render: -> + # pendingClass = if @props.pending isnt "received" then "pending" else "" + delivery = _.uniq _.pluck @props.thought.audience, "delivery" + klass = if delivery.indexOf("received") isnt -1 then " received" else " pending" + speech = @props.thought.statement.speech + attachments = [] + while speech.fat? + attachments.push pre {}, speech.fat.tor.tank.txt.join("\n") + speech = speech.fat.taf # XX + if !speech? then return; + if speech.lin?.say is false then klass += " say" + if speech.url then klass += " url" + + name = if @props.name then @props.name else "" + aude = _.keys @props.thought.audience + audi = window.util.clipAudi(aude).map (_audi) -> (div {}, _audi.slice(1)) + + type = ['private','public'] + type = type[Number(aude.indexOf(window.util.mainStationPath(window.urb.ship)) is -1)] + + mess = switch + when (con = speech.lin) or (con = speech.app) or + (con = speech.exp) or (con = speech.tax) + con.txt + when (con = speech.url) + (a {href:con.txt,target:"_blank"}, con.txt) + else "Unknown speech type:" + (" %"+x for x of speech).join '' + + klass += switch + when speech.app? then " say" + when speech.exp? then " exp" + else "" + + {ship} = @props + if ship[0] is "~" then ship = ship.slice(1) + + div {className:"message#{klass}"}, [ + (div {className:"attr"}, [ + div {className:"type #{type}"}, "" + div {className:"iden"}, div {className:"ship"}, ship + div {className:"audi"}, audi + div {className:"time"}, @convTime @props.thought.statement.date + ]) + div {className:"mess"}, mess, + if attachments.length + div {className:"fat"}, attachments + ] + +window.MessagesComponent = recl + pageSize: 50 + paddingTop: 100 + + getInitialState: -> {station:window.location.pathname.split("/").reverse()[0]} + + sortedMessages: (messages) -> + _.sortBy messages, (_message) -> + _message.pending = false + _message.thought.statement.date + + render: -> + _messages = @sortedMessages @props.messages + + messages = _messages.map (_message,k) => + if _message.thought.statement.speech?.app + _message.ship = "system" + _message.station = @state.station + React.createElement Message,_message + div {id: "messages"}, messages diff --git a/pub/talklog/src/main.coffee b/pub/talklog/src/main.coffee new file mode 100644 index 0000000000..e73f1ca279 --- /dev/null +++ b/pub/talklog/src/main.coffee @@ -0,0 +1,3 @@ +$ -> + rend = React.render; rele = React.createElement + rend (rele window.MessagesComponent, messages: window.MessageData), ($ '#cont')[0] diff --git a/pub/talklog/src/util.coffee b/pub/talklog/src/util.coffee new file mode 100644 index 0000000000..984a63e53c --- /dev/null +++ b/pub/talklog/src/util.coffee @@ -0,0 +1,85 @@ +if not window.util then window.util = {} +_.merge window.util, + mainStations: ["court","floor","porch"] + + mainStationPath: (user) -> "~#{user}/#{window.util.mainStation(user)}" + + mainStation: (user) -> + if not user then user = window.urb.ship + switch user.length + when 3 + return "court" + when 6 + return "floor" + when 13 + return "porch" + + clipAudi: (audi) -> + audi = audi.join " " + ms = window.util.mainStationPath window.urb.ship + regx = new RegExp "/#{ms}","g" + audi = audi.replace regx,"" + audi.split " " + + expandAudi: (audi) -> + audi = audi.join " " + ms = window.util.mainStationPath window.urb.ship + if audi.indexOf(ms) is -1 + if audi.length > 0 + audi += " " + audi += "#{ms}" + audi.split " " + + create: (name) -> + window.talk.StationPersistence.createStation name, (err,res) -> + + subscribe: (name) -> + window.talk.StationPersistence.addSource "main",window.urb.ship,["~zod/#{name}"] + + uuid32: -> + str = "0v" + str += Math.ceil(Math.random()*8)+"." + for i in [0..5] + _str = Math.ceil(Math.random()*10000000).toString(32) + _str = ("00000"+_str).substr(-5,5) + str += _str+"." + str.slice(0,-1) + + populate: (station,number) -> + c = 0 + send = -> + if c < number + c++ + else + console.log 'done' + return true + _audi = {} + _audi[station] = "pending" + _message = + serial:window.util.uuid32() + audience:_audi + statement: + speech: + say:"Message "+c + time: Date.now() + now: Date.now() + window.talk.MessagePersistence.sendMessage _message,send + send() + + getScroll: -> + @writingPosition = $('#c').outerHeight(true)+$('#c').offset().top-$(window).height() + + setScroll: -> + window.util.getScroll() + $(window).scrollTop($("#c").height()) + + isScrolling: -> + if not window.util.writingPosition + window.util.getScroll() + return ($(window).scrollTop()+$('#writing').outerHeight() < window.util.writingPosition) + + checkScroll: -> + if window.util.isScrolling() + $('body').addClass 'scrolling' + else + $('body').removeClass 'scrolling'