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:
parent
5eb25de38b
commit
8a46fd4560
@ -319,7 +319,7 @@ function getConversation(session, conversationName) {
|
|||||||
if (!gCurrentConversation) {
|
if (!gCurrentConversation) {
|
||||||
if (!gState.window) {
|
if (!gState.window) {
|
||||||
setWindow(session.account.id, key);
|
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);
|
setWindow(session.account.id, key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -327,11 +327,10 @@ function getConversation(session, conversationName) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function printToConversation(conversation, message, notify) {
|
function printToConversation(conversation, message, notify) {
|
||||||
print(message);
|
|
||||||
if (conversation == gCurrentConversation) {
|
if (conversation == gCurrentConversation) {
|
||||||
if (message.action == "message") {
|
if (message.action == "message") {
|
||||||
await printMessage(message.message);
|
printMessage(message.message);
|
||||||
} else if (message.action == "presence") {
|
} else if (message.action == "presence") {
|
||||||
if (message.presence == "unavailable") {
|
if (message.presence == "unavailable") {
|
||||||
terminal.print(new Date().toString(), ": ", message.user, " has left the room.");
|
terminal.print(new Date().toString(), ": ", message.user, " has left the room.");
|
||||||
@ -407,24 +406,16 @@ function niceTime(lastTime, thisTime) {
|
|||||||
return result.join(" ");
|
return result.join(" ");
|
||||||
}
|
}
|
||||||
|
|
||||||
async function formatMessage(message) {
|
function formatMessage(message) {
|
||||||
var result;
|
var result;
|
||||||
if (typeof message == "string") {
|
if (typeof message == "string") {
|
||||||
result = [];
|
result = [];
|
||||||
var regex = /(\w+:\/*\S+?)(?=(?:[\.!?])?(?:$|\s))/gi;
|
var regex = /(\w+:\/*\S+?)(?=(?:[\.!?])?(?:$|\s))/gi;
|
||||||
var match;
|
var match;
|
||||||
var lastIndex = 0;
|
var lastIndex = 0;
|
||||||
// let libunfurl;
|
|
||||||
while ((match = regex.exec(message)) !== null) {
|
while ((match = regex.exec(message)) !== null) {
|
||||||
// if (!libunfurl) {
|
|
||||||
// libunfurl = await core.getService("libunfurl", "libunfurl");
|
|
||||||
// }
|
|
||||||
result.push({class: "base1", value: message.substring(lastIndex, match.index)});
|
result.push({class: "base1", value: message.substring(lastIndex, match.index)});
|
||||||
// if (!libunfurl) {
|
|
||||||
result.push({href: match[0]});
|
result.push({href: match[0]});
|
||||||
// } else {
|
|
||||||
// result.push(await libunfurl.postMessage(match[0]));
|
|
||||||
// }
|
|
||||||
lastIndex = regex.lastIndex;
|
lastIndex = regex.lastIndex;
|
||||||
}
|
}
|
||||||
result.push({class: "base1", value: message.substring(lastIndex)});
|
result.push({class: "base1", value: message.substring(lastIndex)});
|
||||||
@ -435,7 +426,7 @@ async function formatMessage(message) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var lastTimestamp = null;
|
var lastTimestamp = null;
|
||||||
async function printMessage(message) {
|
function printMessage(message) {
|
||||||
var now = message.timestamp || new Date().toString();
|
var now = message.timestamp || new Date().toString();
|
||||||
var from = message.from || "unknown";
|
var from = message.from || "unknown";
|
||||||
|
|
||||||
@ -446,7 +437,7 @@ async function printMessage(message) {
|
|||||||
{class: "base3", value: from},
|
{class: "base3", value: from},
|
||||||
{class: "base00", value: ">"},
|
{class: "base00", value: ">"},
|
||||||
" ",
|
" ",
|
||||||
await formatMessage(message.message));
|
formatMessage(message.message));
|
||||||
lastTimestamp = now;
|
lastTimestamp = now;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -463,9 +454,9 @@ core.register("blur", function() {
|
|||||||
core.register("key", function(event) {
|
core.register("key", function(event) {
|
||||||
if (event.type == "keydown") {
|
if (event.type == "keydown") {
|
||||||
if (event.altKey) {
|
if (event.altKey) {
|
||||||
if (event.character == "I") {
|
if (event.character == "I" || event.keyCode == 38) {
|
||||||
cycleConversation(-1);
|
cycleConversation(-1);
|
||||||
} else if (event.character == "K") {
|
} else if (event.character == "K" || event.keyCode == 40) {
|
||||||
cycleConversation(1);
|
cycleConversation(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -737,7 +737,6 @@ class XmppService {
|
|||||||
self._socket.onError(self._reportError);
|
self._socket.onError(self._reportError);
|
||||||
self._socket.read(function(data) {
|
self._socket.read(function(data) {
|
||||||
try {
|
try {
|
||||||
print(data.__prototype__ ? "YEAH!" : "nope");
|
|
||||||
if (!data) {
|
if (!data) {
|
||||||
self._service.notifyStateChanged("disconnected");
|
self._service.notifyStateChanged("disconnected");
|
||||||
return;
|
return;
|
||||||
|
Loading…
Reference in New Issue
Block a user