Chat cleanups and minor fixes.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3363 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
Cory McWilliams 2016-12-23 18:42:37 +00:00
parent 5eb25de38b
commit 8a46fd4560
2 changed files with 9 additions and 19 deletions

View File

@ -319,7 +319,7 @@ function getConversation(session, conversationName) {
if (!gCurrentConversation) {
if (!gState.window) {
setWindow(session.account.id, key);
} else if (gState.window.account = session.account.id && gState.window.conversation == key) {
} else if (gState.window.account == session.account.id && gState.window.conversation == key) {
setWindow(session.account.id, key);
}
}
@ -327,11 +327,10 @@ function getConversation(session, conversationName) {
return result;
}
async function printToConversation(conversation, message, notify) {
print(message);
function printToConversation(conversation, message, notify) {
if (conversation == gCurrentConversation) {
if (message.action == "message") {
await printMessage(message.message);
printMessage(message.message);
} else if (message.action == "presence") {
if (message.presence == "unavailable") {
terminal.print(new Date().toString(), ": ", message.user, " has left the room.");
@ -407,24 +406,16 @@ function niceTime(lastTime, thisTime) {
return result.join(" ");
}
async function formatMessage(message) {
function formatMessage(message) {
var result;
if (typeof message == "string") {
result = [];
var regex = /(\w+:\/*\S+?)(?=(?:[\.!?])?(?:$|\s))/gi;
var match;
var lastIndex = 0;
// let libunfurl;
while ((match = regex.exec(message)) !== null) {
// if (!libunfurl) {
// libunfurl = await core.getService("libunfurl", "libunfurl");
// }
result.push({class: "base1", value: message.substring(lastIndex, match.index)});
// if (!libunfurl) {
result.push({href: match[0]});
// } else {
// result.push(await libunfurl.postMessage(match[0]));
// }
result.push({href: match[0]});
lastIndex = regex.lastIndex;
}
result.push({class: "base1", value: message.substring(lastIndex)});
@ -435,7 +426,7 @@ async function formatMessage(message) {
}
var lastTimestamp = null;
async function printMessage(message) {
function printMessage(message) {
var now = message.timestamp || new Date().toString();
var from = message.from || "unknown";
@ -446,7 +437,7 @@ async function printMessage(message) {
{class: "base3", value: from},
{class: "base00", value: ">"},
" ",
await formatMessage(message.message));
formatMessage(message.message));
lastTimestamp = now;
}
@ -463,9 +454,9 @@ core.register("blur", function() {
core.register("key", function(event) {
if (event.type == "keydown") {
if (event.altKey) {
if (event.character == "I") {
if (event.character == "I" || event.keyCode == 38) {
cycleConversation(-1);
} else if (event.character == "K") {
} else if (event.character == "K" || event.keyCode == 40) {
cycleConversation(1);
}
}

View File

@ -737,7 +737,6 @@ class XmppService {
self._socket.onError(self._reportError);
self._socket.read(function(data) {
try {
print(data.__prototype__ ? "YEAH!" : "nope");
if (!data) {
self._service.notifyStateChanged("disconnected");
return;