forked from cory/tildefriends
More chat fixes.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3316 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
parent
380e98b7cf
commit
d74825eadc
@ -242,26 +242,22 @@ function updateConversation() {
|
|||||||
gCurrentConversation.session.getHistory(gCurrentConversation.name),
|
gCurrentConversation.session.getHistory(gCurrentConversation.name),
|
||||||
gCurrentConversation.session.getParticipants(gCurrentConversation.name),
|
gCurrentConversation.session.getParticipants(gCurrentConversation.name),
|
||||||
]).then(function(data) {
|
]).then(function(data) {
|
||||||
let history = data[0];
|
let [history, participants] = data;
|
||||||
let participants = data[1];
|
|
||||||
gCurrentConversation.messages = history || [];
|
|
||||||
if (gCurrentConversation.messages.length > kMaxHistory) {
|
|
||||||
gCurrentConversation.messages.splice(0, gCurrentConversation.messages.length - kMaxHistory);
|
|
||||||
}
|
|
||||||
gCurrentConversation.participants = participants || [];
|
gCurrentConversation.participants = participants || [];
|
||||||
terminal.cork();
|
try {
|
||||||
terminal.select("terminal");
|
terminal.cork();
|
||||||
terminal.clear();
|
terminal.select("terminal");
|
||||||
for (var i in gCurrentConversation.messages) {
|
terminal.clear();
|
||||||
let message = gCurrentConversation.messages[i];
|
printToConversation(gCurrentConversation, ["[", gCurrentConversation.name, "]"]);
|
||||||
if (message.action == "message") {
|
if (history) {
|
||||||
printMessage(message.message);
|
for (let message of history) {
|
||||||
} else {
|
printToConversation(gCurrentConversation, message);
|
||||||
terminal.print(message.message);
|
}
|
||||||
}
|
}
|
||||||
|
updateUsers();
|
||||||
|
} finally {
|
||||||
|
terminal.uncork();
|
||||||
}
|
}
|
||||||
updateUsers();
|
|
||||||
terminal.uncork();
|
|
||||||
}).catch(function(error) {
|
}).catch(function(error) {
|
||||||
terminal.print(error);
|
terminal.print(error);
|
||||||
});
|
});
|
||||||
@ -334,13 +330,16 @@ function printToConversation(conversation, message, notify) {
|
|||||||
if (conversation == gCurrentConversation) {
|
if (conversation == gCurrentConversation) {
|
||||||
if (message.action == "message") {
|
if (message.action == "message") {
|
||||||
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.");
|
||||||
|
} else {
|
||||||
|
terminal.print(new Date().toString(), ": ", message.user, " has joined the room.");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
terminal.print(message);
|
terminal.print(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (conversation) {
|
|
||||||
conversation.messages.push(message);
|
|
||||||
}
|
|
||||||
if (notify && !gFocus) {
|
if (notify && !gFocus) {
|
||||||
gUnread++;
|
gUnread++;
|
||||||
updateTitle();
|
updateTitle();
|
||||||
|
@ -89,10 +89,13 @@ exports.ChatService = class {
|
|||||||
let leaving = state == "unavailable";
|
let leaving = state == "unavailable";
|
||||||
let participants = this._getConversation(conversation).participants;
|
let participants = this._getConversation(conversation).participants;
|
||||||
let index = participants.indexOf(user);
|
let index = participants.indexOf(user);
|
||||||
|
let different = true;
|
||||||
if (leaving) {
|
if (leaving) {
|
||||||
participants.splice(index, 1);
|
participants.splice(index, 1);
|
||||||
} else if (index == -1) {
|
} else if (index == -1) {
|
||||||
participants.push(user);
|
participants.push(user);
|
||||||
|
} else {
|
||||||
|
different = false;
|
||||||
}
|
}
|
||||||
let message = {
|
let message = {
|
||||||
action: "presence",
|
action: "presence",
|
||||||
@ -100,7 +103,9 @@ exports.ChatService = class {
|
|||||||
user: user,
|
user: user,
|
||||||
presence: state,
|
presence: state,
|
||||||
};
|
};
|
||||||
this._pushMessage(conversation, message);
|
if (different) {
|
||||||
|
this._pushMessage(conversation, message);
|
||||||
|
}
|
||||||
this._invokeCallback(message);
|
this._invokeCallback(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user