forked from cory/tildefriends
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:
@ -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();
|
||||
});
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user