Skip to content

Commit

Permalink
message rework, made inline replies more sane + d-tail now follows me…
Browse files Browse the repository at this point in the history
…ssage clicks
  • Loading branch information
sgentle committed May 15, 2013
1 parent 396a972 commit 5bc1966
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 22 deletions.
4 changes: 2 additions & 2 deletions robots/chatformatic.bot
Expand Up @@ -6,5 +6,5 @@ escapeHTML = (html) -> $('<div/>').text(html).html() if html?

@transmit "handling display for type", "chat"

@listen "chat", ({user, data, id, re}) ->
@transmit type:"build message", user:user, data:{source:user or "anonymous", text:data, id, re}
@listen "chat", ({user, data, id, re, from}) ->
@transmit type:"build message", user:user, data:{source:user or "anonymous", text:data, id, re, from}
5 changes: 5 additions & 0 deletions robots/d-tail.bot
Expand Up @@ -7,6 +7,11 @@
@transmit "get robot info", id, ({type, data: robot}) ->
detailView robot if type isnt "error"

@listen type: 'message clicked', local: true, ({data: {from: id}}) ->
return unless id
@transmit "get robot info", id, ({type, data: robot}) ->
detailView robot if type isnt "error"

@transmit "add style", "
#detailpanel {
width: 100%;
Expand Down
21 changes: 15 additions & 6 deletions robots/displayinator.bot
Expand Up @@ -23,30 +23,39 @@ container.append messages
@transmit "want layout", {id: 'message-container', name: "messages"}, ({data:{parent}}) ->
$(parent).append container

messages.on 'click', '.message', (ev) =>
if id = $(ev.currentTarget).attr 'id'
messages.on 'click', '.source', (ev) =>
return if window.getSelection?()?.isCollapsed is false

message = $(ev.currentTarget).parents('.message')
id = message.attr 'id'
data = message.data()

if id
id = id.replace /^msg-/, ''
@transmit 'message clicked', id
source = message.children('.source').text()
@transmit 'message clicked', {id, source, from: data.from}
else
@transmit 'message clicked'
ev.stopPropagation()

container.click (ev) =>
@transmit 'message clicked'
container.on 'click', (ev) =>
@transmit 'message clicked' unless window.getSelection?()?.isCollapsed is false

@listen "display message", ({user, data: {message, id, re}}) ->
@listen "display message", ({user, data: {message, id, re, from}}) ->
scroll = (container.scrollTop() + container.height() == container[0].scrollHeight)

id = if id then "msg-#{id}" else ""
re = if re then "msg-#{re}" else ""

html = $("<div id='#{id}' class='message'>#{message}</div>")
html.attr 'data-from', from

sel = "##{re}, ##{re} ~ [data-re=\"#{re}\"]"

if re and (reEl = $(sel).last()) and reEl.length
console.log "appending after", re
html.attr 'data-re', re
html.addClass 're'
reEl.after html
else
messages.append html
Expand Down
6 changes: 4 additions & 2 deletions robots/inputnik.bot
Expand Up @@ -25,8 +25,10 @@ rebox = $("<div id='rebox' />")
display: table-cell;
height: 100%;
width: 1px;
max-width: 150em;
white-space: nowrap;
background-color: #55F;
color: #ccc;
vertical-align: middle;:
}
"
Expand All @@ -48,9 +50,9 @@ rebox = $("<div id='rebox' />")

ev.preventDefault() if ev.which is 13

@listen "message clicked", ({data: id}) ->
@listen "message clicked", ({data: {id, source}}) ->
if typeof id is 'string'
rebox.text "RE: #{id}"
rebox.text "RE: #{source}"
rebox.show()
else
rebox.hide()
Expand Down
5 changes: 3 additions & 2 deletions robots/jsonformatic.bot
Expand Up @@ -98,17 +98,18 @@ json2html = (obj) ->
return if msg.type == "display message"
return if (ignores[msg.type] or msg.local) and !deluge

from = (x for x in [msg.user, msg.robot] when x?).join(" + ") || "anonybot"
source = (x for x in [msg.user, msg.robot] when x?).join(" + ") || "anonybot"
sourceclass = "local" if msg.local




@transmit type: "build message", user: msg.user, data:
id: msg.id,
from: msg.from,
re: msg.re,
sourceclass: sourceclass,
source: from,
source: source,
textclass: 'json',
html: msg2html msg

Expand Down
18 changes: 9 additions & 9 deletions robots/messagebuilder.bot
Expand Up @@ -31,18 +31,18 @@ nl2br = (html) -> html.replace /\n/g, "<br />"
.message .source.me {
background-color: #eaf2f5;
}
.message .text {
.message .body {
display: table-cell;
padding: 0 10px;
word-break: break-all;
}
.message .text.json {
.message .body.json {
color: #4155A6;
}
.message .text.status {
.message .body.status {
color: green;
}
.message .text.re {
.message.re .body {
padding-left: 2em;
}
"
Expand All @@ -53,17 +53,17 @@ me = undefined
@transmit type: "user name?", local: true


@listen "build message", ({user, data: {id, re, source, sourceclass, text, textclass, html}}) ->
@listen "build message", ({user, data: {id, re, from, source, sourceclass, text, textclass, html}}) ->
source ||= ''
text ||= ''
sourceclass ||= ''
textclass ||= ''

sourceclass += "me" if me? and user is me
reclass = if re then "re" else ""

message = "
<div class='source #{sourceclass} #{reclass}'>#{escapeHTML source}</div>
<div class='text #{textclass} #{reclass}'>#{html or (nl2br escapeHTML text)}</div>
<div class='source #{sourceclass}'>#{escapeHTML source}</div>
<div class='body #{textclass}'>#{html or (nl2br escapeHTML text)}</div>
"
@transmit type:"display message", user:user, data:{message, id, re}

@transmit type:"display message", user:user, data:{message, id, re, from}
2 changes: 1 addition & 1 deletion robots/sendax.bot
Expand Up @@ -4,7 +4,7 @@

re = null

@listen "message clicked", ({data: id}) ->
@listen "message clicked", ({data: {id}}) ->
if typeof id is 'string'
re = id
else
Expand Down

0 comments on commit 5bc1966

Please sign in to comment.