Skip to content

Commit

Permalink
updated chat
Browse files Browse the repository at this point in the history
  • Loading branch information
tsloughter committed Nov 16, 2011
1 parent 99365ad commit 7303c19
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/examples/pubnub_chat.opa
Expand Up @@ -11,18 +11,31 @@ user_update(x) =
Dom.scroll_to_bottom(#conversation)
| _ -> void

user_update_2(x) =
match x with
| {Record = [("username", username), ("message", message)]} ->
void
| {String = s}->
void
| _ -> void

broadcast(author, msg) =
username : RPC.Json.json = {String = author}
message : RPC.Json.json = {String = msg}
record_json : RPC.Json.json = {Record = [("username", username), ("message", message)]}
do PubNub.publish("chat", record_json)
Dom.clear_value(#entry)

add_history(x: string) =
match Json.deserialize(x) with
| {some={List=history}} ->
do List.iter(user_update_2, history)
void
| _ -> void

launch(author) =
init_client() =
//PubNub.history("chat", 20, (history ->
// history = List.rev(List.take(20, history))
// do List.iter(user_update, history)
//do PubNub.history("chat", 20, (h -> add_history(h)))
PubNub.subscribe("chat", (x -> user_update(x)))
send_message() =
broadcast(author, Dom.get_value(#entry))
Expand Down

0 comments on commit 7303c19

Please sign in to comment.