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 gErrorCount = 0;
|
||||
var gCommandHistory = [];
|
||||
var gSendKeyEvents = false;
|
||||
|
||||
var kMaxCommandHistory = 16;
|
||||
|
||||
@ -85,7 +86,8 @@ function split(container, children) {
|
||||
var grow = children[i].grow || "1";
|
||||
var shrink = children[i].shrink || "1";
|
||||
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"];
|
||||
if (children[i].type == "vertical") {
|
||||
@ -156,12 +158,36 @@ function receive(data) {
|
||||
if (iframe) {
|
||||
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 {
|
||||
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) {
|
||||
terminal.appendChild(document.createElement("br"));
|
||||
}
|
||||
@ -173,13 +199,18 @@ function print(terminal, data) {
|
||||
}
|
||||
|
||||
function printSvg(container, data, name, namespace) {
|
||||
var node = document.createElementNS("http://www.w3.org/2000/svg", name);
|
||||
for (var i in data.attributes) {
|
||||
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));
|
||||
var node;
|
||||
if (typeof data == "string") {
|
||||
node = document.createTextNode(data);
|
||||
} else {
|
||||
node = document.createElementNS("http://www.w3.org/2000/svg", name);
|
||||
for (var i in data.attributes) {
|
||||
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;
|
||||
@ -201,7 +232,7 @@ function printStructured(container, data) {
|
||||
if (data.href) {
|
||||
node = document.createElement("a");
|
||||
node.setAttribute("href", data.href);
|
||||
node.setAttribute("target", "_blank");
|
||||
node.setAttribute("target", data.target || "_blank");
|
||||
} else if (data.iframe) {
|
||||
node = document.createElement("iframe");
|
||||
node.setAttribute("srcdoc", data.iframe);
|
||||
@ -481,6 +512,7 @@ function connectSocket() {
|
||||
['setPrompt', 'value'],
|
||||
['setTitle', 'value'],
|
||||
['split', 'options'],
|
||||
['setSendKeyEvents', 'value'],
|
||||
],
|
||||
}));
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ function updateTitle() {
|
||||
terminal.setTitle((gUnread ? "(" + gUnread.toString() + ") " : "") + "Chat");
|
||||
}
|
||||
|
||||
let kMaxHistory = 32;
|
||||
let kAccountsKey = JSON.stringify(["accounts", core.user.name]);
|
||||
let kStateKey = JSON.stringify(["state", core.user.name]);
|
||||
|
||||
@ -218,6 +219,9 @@ function updateConversation() {
|
||||
let history = data[0];
|
||||
let participants = data[1];
|
||||
gCurrentConversation.messages = history || [];
|
||||
if (gCurrentConversation.messages.length > kMaxHistory) {
|
||||
gCurrentConversation.messages.splice(0, gCurrentConversation.messages.length - kMaxHistory);
|
||||
}
|
||||
gCurrentConversation.participants = participants || [];
|
||||
terminal.cork();
|
||||
terminal.select("terminal");
|
||||
@ -227,7 +231,7 @@ function updateConversation() {
|
||||
if (message.action == "message") {
|
||||
printMessage(message.message);
|
||||
} else {
|
||||
terminal.print(message);
|
||||
terminal.print(message.message);
|
||||
}
|
||||
}
|
||||
updateUsers();
|
||||
@ -283,6 +287,7 @@ function getConversation(session, conversationName) {
|
||||
sendMessage: function(message) {
|
||||
return session.sendMessage(key, message);
|
||||
},
|
||||
participants: [],
|
||||
};
|
||||
updateWindows();
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ function index() {
|
||||
}
|
||||
terminal.print(
|
||||
"* ",
|
||||
{href: "/~" + app.owner + "/" + app.name},
|
||||
{href: "/~" + app.owner + "/" + app.name, target: "_self"},
|
||||
message,
|
||||
app.manifest && app.manifest.description ? " - " + app.manifest.description.toString() : "");
|
||||
});
|
||||
|
@ -29,6 +29,7 @@ class IrcService {
|
||||
self._service = new ChatService(options.callback);
|
||||
self._name = options.name;
|
||||
self._nick = options.nick;
|
||||
self._nameReplies = {};
|
||||
|
||||
network.newConnection().then(function(socket) {
|
||||
self._socket = socket;
|
||||
@ -66,7 +67,7 @@ class IrcService {
|
||||
// Is it a channel type?
|
||||
if ("&#!+.".indexOf(parts[1].charAt(0)) != -1) {
|
||||
conversation = parts[1];
|
||||
} else {
|
||||
} else if (prefix.indexOf('!') != -1) {
|
||||
conversation = prefix.split('!')[0];
|
||||
}
|
||||
this._service.notifyMessageReceived(conversation, {
|
||||
@ -81,10 +82,29 @@ class IrcService {
|
||||
let person = prefix.split('!')[0];
|
||||
let conversation = parts[1];
|
||||
this._service.notifyPresenceChanged(conversation, person, "present");
|
||||
} else if (parts[0] == "JOIN") {
|
||||
} else if (parts[0] == "PART") {
|
||||
let person = prefix.split('!')[0];
|
||||
let conversation = parts[1];
|
||||
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 {
|
||||
this._service.notifyMessageReceived("", {from: prefix, message: lineNoPrefix});
|
||||
}
|
||||
@ -127,7 +147,7 @@ class IrcService {
|
||||
} else {
|
||||
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() {
|
||||
|
@ -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) {
|
||||
this._state = state;
|
||||
this._invokeCallback({action: state});
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
terminal.print("Hello, world!");
|
||||
|
||||
let kServer = "rowlf.unprompted.com";
|
||||
let kServer = "localhost";
|
||||
|
||||
class Smtp {
|
||||
constructor() {
|
||||
@ -29,7 +29,7 @@ class Smtp {
|
||||
reject(error.message);
|
||||
}
|
||||
});
|
||||
socket.connect("localhost", 25).catch(reject);
|
||||
socket.connect(kServer, 25).catch(reject);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -1,16 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
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 makeSaveCallback = function(oldName, oldValue) {
|
||||
@ -39,6 +29,16 @@ function fileList(settings) {
|
||||
core.register("hashChange", hashChange);
|
||||
|
||||
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) {
|
||||
if (input == "new") {
|
||||
terminal.setHash(name);
|
||||
@ -97,6 +97,7 @@ function fileList(settings) {
|
||||
}
|
||||
}
|
||||
}
|
||||
terminal.uncork();
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user