Backlog of miscellaneous fixes.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3234 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
parent
fb94e1cde9
commit
dca3ad9b79
@ -5,6 +5,7 @@ var gSessionId;
|
|||||||
var gCredentials;
|
var gCredentials;
|
||||||
var gErrorCount = 0;
|
var gErrorCount = 0;
|
||||||
var gCommandHistory = [];
|
var gCommandHistory = [];
|
||||||
|
var gSendKeyEvents = false;
|
||||||
|
|
||||||
var kMaxCommandHistory = 16;
|
var kMaxCommandHistory = 16;
|
||||||
|
|
||||||
@ -85,7 +86,8 @@ function split(container, children) {
|
|||||||
var grow = children[i].grow || "1";
|
var grow = children[i].grow || "1";
|
||||||
var shrink = children[i].shrink || "1";
|
var shrink = children[i].shrink || "1";
|
||||||
var basis = children[i].basis || "auto";
|
var basis = children[i].basis || "auto";
|
||||||
node.setAttribute("style", "flex: " + grow + " " + shrink + " " + basis);
|
var style = children[i].style || "";
|
||||||
|
node.setAttribute("style", style + "; flex: " + grow + " " + shrink + " " + basis);
|
||||||
|
|
||||||
var classes = ["terminal"];
|
var classes = ["terminal"];
|
||||||
if (children[i].type == "vertical") {
|
if (children[i].type == "vertical") {
|
||||||
@ -156,12 +158,36 @@ function receive(data) {
|
|||||||
if (iframe) {
|
if (iframe) {
|
||||||
iframe.contentWindow.postMessage(line[0].message, "*");
|
iframe.contentWindow.postMessage(line[0].message, "*");
|
||||||
}
|
}
|
||||||
|
} else if (line && line[0] && line[0].action == "setSendKeyEvents") {
|
||||||
|
var value = line[0].value;
|
||||||
|
if (value && !gSendKeyEvents) {
|
||||||
|
window.addEventListener("keydown", keyEvent);
|
||||||
|
window.addEventListener("keypress", keyEvent);
|
||||||
|
window.addEventListener("keyup", keyEvent);
|
||||||
|
} else if (!value && gSendKeyEvents) {
|
||||||
|
window.removeEventListener("keydown", keyEvent);
|
||||||
|
window.removeEventListener("keypress", keyEvent);
|
||||||
|
window.removeEventListener("keyup", keyEvent);
|
||||||
|
}
|
||||||
|
gSendKeyEvents = value;
|
||||||
} else {
|
} else {
|
||||||
print(document.getElementById(target), line);
|
print(document.getElementById(target), line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function keyEvent(event) {
|
||||||
|
send({
|
||||||
|
event: "key",
|
||||||
|
type: event.type,
|
||||||
|
which: event.which,
|
||||||
|
keyCode: event.keyCode,
|
||||||
|
charCode: event.charCode,
|
||||||
|
character: String.fromCharCode(event.keyCode || event.which),
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function autoNewLine(terminal) {
|
function autoNewLine(terminal) {
|
||||||
terminal.appendChild(document.createElement("br"));
|
terminal.appendChild(document.createElement("br"));
|
||||||
}
|
}
|
||||||
@ -173,13 +199,18 @@ function print(terminal, data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function printSvg(container, data, name, namespace) {
|
function printSvg(container, data, name, namespace) {
|
||||||
var node = document.createElementNS("http://www.w3.org/2000/svg", name);
|
var node;
|
||||||
for (var i in data.attributes) {
|
if (typeof data == "string") {
|
||||||
node.setAttribute(i, data.attributes[i]);
|
node = document.createTextNode(data);
|
||||||
}
|
} else {
|
||||||
if (data.children) {
|
node = document.createElementNS("http://www.w3.org/2000/svg", name);
|
||||||
for (var i in data.children) {
|
for (var i in data.attributes) {
|
||||||
node.appendChild(printSvg(node, data.children[i], data.children[i].name));
|
node.setAttribute(i, data.attributes[i]);
|
||||||
|
}
|
||||||
|
if (data.children) {
|
||||||
|
for (var i in data.children) {
|
||||||
|
node.appendChild(printSvg(node, data.children[i], data.children[i].name));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return node;
|
return node;
|
||||||
@ -201,7 +232,7 @@ function printStructured(container, data) {
|
|||||||
if (data.href) {
|
if (data.href) {
|
||||||
node = document.createElement("a");
|
node = document.createElement("a");
|
||||||
node.setAttribute("href", data.href);
|
node.setAttribute("href", data.href);
|
||||||
node.setAttribute("target", "_blank");
|
node.setAttribute("target", data.target || "_blank");
|
||||||
} else if (data.iframe) {
|
} else if (data.iframe) {
|
||||||
node = document.createElement("iframe");
|
node = document.createElement("iframe");
|
||||||
node.setAttribute("srcdoc", data.iframe);
|
node.setAttribute("srcdoc", data.iframe);
|
||||||
@ -481,6 +512,7 @@ function connectSocket() {
|
|||||||
['setPrompt', 'value'],
|
['setPrompt', 'value'],
|
||||||
['setTitle', 'value'],
|
['setTitle', 'value'],
|
||||||
['split', 'options'],
|
['split', 'options'],
|
||||||
|
['setSendKeyEvents', 'value'],
|
||||||
],
|
],
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@ function updateTitle() {
|
|||||||
terminal.setTitle((gUnread ? "(" + gUnread.toString() + ") " : "") + "Chat");
|
terminal.setTitle((gUnread ? "(" + gUnread.toString() + ") " : "") + "Chat");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let kMaxHistory = 32;
|
||||||
let kAccountsKey = JSON.stringify(["accounts", core.user.name]);
|
let kAccountsKey = JSON.stringify(["accounts", core.user.name]);
|
||||||
let kStateKey = JSON.stringify(["state", core.user.name]);
|
let kStateKey = JSON.stringify(["state", core.user.name]);
|
||||||
|
|
||||||
@ -218,6 +219,9 @@ function updateConversation() {
|
|||||||
let history = data[0];
|
let history = data[0];
|
||||||
let participants = data[1];
|
let participants = data[1];
|
||||||
gCurrentConversation.messages = history || [];
|
gCurrentConversation.messages = history || [];
|
||||||
|
if (gCurrentConversation.messages.length > kMaxHistory) {
|
||||||
|
gCurrentConversation.messages.splice(0, gCurrentConversation.messages.length - kMaxHistory);
|
||||||
|
}
|
||||||
gCurrentConversation.participants = participants || [];
|
gCurrentConversation.participants = participants || [];
|
||||||
terminal.cork();
|
terminal.cork();
|
||||||
terminal.select("terminal");
|
terminal.select("terminal");
|
||||||
@ -227,7 +231,7 @@ function updateConversation() {
|
|||||||
if (message.action == "message") {
|
if (message.action == "message") {
|
||||||
printMessage(message.message);
|
printMessage(message.message);
|
||||||
} else {
|
} else {
|
||||||
terminal.print(message);
|
terminal.print(message.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
updateUsers();
|
updateUsers();
|
||||||
@ -283,6 +287,7 @@ function getConversation(session, conversationName) {
|
|||||||
sendMessage: function(message) {
|
sendMessage: function(message) {
|
||||||
return session.sendMessage(key, message);
|
return session.sendMessage(key, message);
|
||||||
},
|
},
|
||||||
|
participants: [],
|
||||||
};
|
};
|
||||||
updateWindows();
|
updateWindows();
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,7 @@ function index() {
|
|||||||
}
|
}
|
||||||
terminal.print(
|
terminal.print(
|
||||||
"* ",
|
"* ",
|
||||||
{href: "/~" + app.owner + "/" + app.name},
|
{href: "/~" + app.owner + "/" + app.name, target: "_self"},
|
||||||
message,
|
message,
|
||||||
app.manifest && app.manifest.description ? " - " + app.manifest.description.toString() : "");
|
app.manifest && app.manifest.description ? " - " + app.manifest.description.toString() : "");
|
||||||
});
|
});
|
||||||
|
@ -29,6 +29,7 @@ class IrcService {
|
|||||||
self._service = new ChatService(options.callback);
|
self._service = new ChatService(options.callback);
|
||||||
self._name = options.name;
|
self._name = options.name;
|
||||||
self._nick = options.nick;
|
self._nick = options.nick;
|
||||||
|
self._nameReplies = {};
|
||||||
|
|
||||||
network.newConnection().then(function(socket) {
|
network.newConnection().then(function(socket) {
|
||||||
self._socket = socket;
|
self._socket = socket;
|
||||||
@ -66,7 +67,7 @@ class IrcService {
|
|||||||
// Is it a channel type?
|
// Is it a channel type?
|
||||||
if ("&#!+.".indexOf(parts[1].charAt(0)) != -1) {
|
if ("&#!+.".indexOf(parts[1].charAt(0)) != -1) {
|
||||||
conversation = parts[1];
|
conversation = parts[1];
|
||||||
} else {
|
} else if (prefix.indexOf('!') != -1) {
|
||||||
conversation = prefix.split('!')[0];
|
conversation = prefix.split('!')[0];
|
||||||
}
|
}
|
||||||
this._service.notifyMessageReceived(conversation, {
|
this._service.notifyMessageReceived(conversation, {
|
||||||
@ -81,10 +82,29 @@ class IrcService {
|
|||||||
let person = prefix.split('!')[0];
|
let person = prefix.split('!')[0];
|
||||||
let conversation = parts[1];
|
let conversation = parts[1];
|
||||||
this._service.notifyPresenceChanged(conversation, person, "present");
|
this._service.notifyPresenceChanged(conversation, person, "present");
|
||||||
} else if (parts[0] == "JOIN") {
|
} else if (parts[0] == "PART") {
|
||||||
let person = prefix.split('!')[0];
|
let person = prefix.split('!')[0];
|
||||||
let conversation = parts[1];
|
let conversation = parts[1];
|
||||||
this._service.notifyPresenceChanged(conversation, person, "unavailable");
|
this._service.notifyPresenceChanged(conversation, person, "unavailable");
|
||||||
|
} else if (parts[0] == "353") { // RPL_NAMREPLY
|
||||||
|
if (!this._nameReplies[parts[3]]) {
|
||||||
|
this._nameReplies[parts[3]] = [];
|
||||||
|
}
|
||||||
|
let users = parts[4].split(' ');
|
||||||
|
for (let i in users) {
|
||||||
|
let user = users[i];
|
||||||
|
let state = "present";
|
||||||
|
if ("@+".indexOf(user.charAt(0)) != -1) {
|
||||||
|
state = user.charAt(0);
|
||||||
|
user = user.substring(1);
|
||||||
|
}
|
||||||
|
this._nameReplies[parts[3]][user] = state;
|
||||||
|
}
|
||||||
|
} else if (parts[0] == "366") { // RPL_ENDOFNAMES
|
||||||
|
for (let conversation in this._nameReplies) {
|
||||||
|
this._service.notifyParticipantList(conversation, this._nameReplies[conversation]);
|
||||||
|
}
|
||||||
|
this._nameReplies = {};
|
||||||
} else {
|
} else {
|
||||||
this._service.notifyMessageReceived("", {from: prefix, message: lineNoPrefix});
|
this._service.notifyMessageReceived("", {from: prefix, message: lineNoPrefix});
|
||||||
}
|
}
|
||||||
@ -127,7 +147,7 @@ class IrcService {
|
|||||||
} else {
|
} else {
|
||||||
this._socket.write("PRIVMSG " + target + " :" + text + "\r\n");
|
this._socket.write("PRIVMSG " + target + " :" + text + "\r\n");
|
||||||
}
|
}
|
||||||
this._service.notifyMessageReceived(target || "", {from: self._nick, message: text, timestamp: new Date().toString()});
|
this._service.notifyMessageReceived(target || "", {from: this._nick, message: text, timestamp: new Date().toString()});
|
||||||
}
|
}
|
||||||
|
|
||||||
disconnect() {
|
disconnect() {
|
||||||
|
@ -86,6 +86,18 @@ exports.ChatService = class {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
notifyParticipantList(conversation, participants) {
|
||||||
|
let current = this._getConversation(conversation).participants;
|
||||||
|
for (let i in current) {
|
||||||
|
if (!participants[i]) {
|
||||||
|
this.notifyPresenceChanged(conversation, i, "unavailable");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (let i in participants) {
|
||||||
|
this.notifyPresenceChanged(conversation, i, participants[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
notifyStateChanged(state) {
|
notifyStateChanged(state) {
|
||||||
this._state = state;
|
this._state = state;
|
||||||
this._invokeCallback({action: state});
|
this._invokeCallback({action: state});
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
terminal.print("Hello, world!");
|
terminal.print("Hello, world!");
|
||||||
|
|
||||||
let kServer = "rowlf.unprompted.com";
|
let kServer = "localhost";
|
||||||
|
|
||||||
class Smtp {
|
class Smtp {
|
||||||
constructor() {
|
constructor() {
|
||||||
@ -29,7 +29,7 @@ class Smtp {
|
|||||||
reject(error.message);
|
reject(error.message);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
socket.connect("localhost", 25).catch(reject);
|
socket.connect(kServer, 25).catch(reject);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,6 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
function fileList(settings) {
|
function fileList(settings) {
|
||||||
|
|
||||||
terminal.setEcho(false);
|
|
||||||
terminal.clear();
|
|
||||||
terminal.print(settings.title);
|
|
||||||
if (core.user.credentials
|
|
||||||
&& core.user.credentials.permissions
|
|
||||||
&& core.user.credentials.permissions.authenticated) {
|
|
||||||
terminal.print({command: "new"});
|
|
||||||
}
|
|
||||||
|
|
||||||
let prefix = settings.prefix || "";
|
let prefix = settings.prefix || "";
|
||||||
|
|
||||||
let makeSaveCallback = function(oldName, oldValue) {
|
let makeSaveCallback = function(oldName, oldValue) {
|
||||||
@ -39,6 +29,16 @@ function fileList(settings) {
|
|||||||
core.register("hashChange", hashChange);
|
core.register("hashChange", hashChange);
|
||||||
|
|
||||||
return database.getAll().then(function(entries) {
|
return database.getAll().then(function(entries) {
|
||||||
|
terminal.cork();
|
||||||
|
terminal.setEcho(false);
|
||||||
|
terminal.clear();
|
||||||
|
terminal.print(settings.title);
|
||||||
|
if (core.user.credentials
|
||||||
|
&& core.user.credentials.permissions
|
||||||
|
&& core.user.credentials.permissions.authenticated) {
|
||||||
|
terminal.print({command: "new"});
|
||||||
|
}
|
||||||
|
|
||||||
terminal.readLine().then(function(input) {
|
terminal.readLine().then(function(input) {
|
||||||
if (input == "new") {
|
if (input == "new") {
|
||||||
terminal.setHash(name);
|
terminal.setHash(name);
|
||||||
@ -97,6 +97,7 @@ function fileList(settings) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
terminal.uncork();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user