-
-
Save Raynos/795fa1402c2663799201 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var ever = require("ever") | |
var extend = require("xtend") | |
var autocomplete = require("../lib/autocomplete") | |
var ENTER = 13 | |
module.exports = Input | |
function Input(onMessage, options) { | |
return function (button, input, state) { | |
var participant = state.participant | |
var participants = state.participants | |
var doc = state.doc | |
var hangout = state.hangout | |
var isTeacher = state.isTeacher | |
var name = participant.person.displayName | |
var hangoutLink = hangout.link | |
ever(button).on("click", send) | |
ever(input).on("keypress", function (ev) { | |
if (ev.which !== ENTER || ev.shiftKey) { | |
return | |
} | |
send() | |
ev.preventDefault() | |
}) | |
if (options && options.autocomplete) { | |
autocomplete(input, function () { | |
return participants().map(function (p) { | |
return p.person | |
}) | |
}) | |
} | |
function send() { | |
var message = input.value | |
if (message.length === 0) { | |
return | |
} | |
var ts = Date.now() | |
/* Because I want to put all this bullshit meta | |
data about who the user is and where the user is | |
on the message going into the crdt.Doc I have to pass | |
it in as arguments which is bullshit | |
*/ | |
var msg = { | |
message: message | |
, name: name | |
, hangoutParticipant: participant | |
, hangoutLink: hangoutLink | |
, ts: ts | |
, isTeacher: isTeacher | |
, _sort: ts | |
} | |
var result = onMessage(msg, state) | |
if (!result) { | |
return | |
} | |
doc.add(extend(msg, result)) | |
input.value = "" | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment