Fixing private chat.

master
Tomasz Półgrabia 2017-09-18 22:34:08 +02:00
parent ca4e032dd6
commit 43297fa76e
4 changed files with 36 additions and 12 deletions

View File

@ -42,7 +42,8 @@ public class PrivMessageHandler implements SessionCommandHandler {
// user
UserCtx userCtx = globalCtx.getUserSessions().get(destination);
UserCtx userCtx = globalCtx.getUserSessions().get(globalCtx.getUserNameSessions().get(destination));
UserCtx sourceUserCtx = globalCtx.getUserSessions().get(session);
if (userCtx == null) {
sendMessage(session,
globalCtx, destination,"MSG invalid destination");
@ -50,7 +51,9 @@ public class PrivMessageHandler implements SessionCommandHandler {
}
sendMessage(userCtx.getSession(),
globalCtx, destination, payload);
globalCtx, sourceUserCtx.getNick(), payload); // destination and source
sendMessage(session,
globalCtx, sourceUserCtx.getNick(), payload); // destination and source
return true;
}

View File

@ -44,7 +44,7 @@ public class UserCommandHandler implements SessionCommandHandler {
sendMessage(session, globalCtx,
globalCtx.getUserSessions().get(session).getNick(),
"MSG OK");
"PRIVMSG " + userCtx.getNick() + " hello");
return true;
}
}

View File

@ -6,6 +6,16 @@ function tabRef (destination) {
}
};
function nextToken(data, token) {
var idx = data.indexOf(token);
return data.substr(idx+1);
}
function currentToken(data, token) {
var idx = data.indexOf(token);
return data.substr(0, idx);
}
function IrcClient(sockJs, nick, userName, realName) {
this.sockJs = sockJs;
this.nick = nick;
@ -107,14 +117,16 @@ function IrcClient(sockJs, nick, userName, realName) {
};
this.fetchDestination = function (data) {
var preDestIdx = data.indexOf(" ");
if (preDestIdx < 0) {
return null;
}
// var server = currentToken(data, " ");
var source = nextToken(data, " ");
var command = nextToken(source, " ");
var dest = nextToken(command, " ");
return currentToken(dest, " ");
};
var destIdx = preDestIdx + 1;
var preDataIdx = data.indexOf(" ", destIdx);
return data.substr(destIdx, preDataIdx - destIdx);
this.fetchSource = function (data) {
sourceData = nextToken(data, " ");
return sourceData.substr(0, sourceData.indexOf(" ")+1).trim();
};
this.sockJs.onmessage = function (e) {
@ -126,10 +138,15 @@ function IrcClient(sockJs, nick, userName, realName) {
console.log("Received message: " + msg);
var destination = ircClientRef.fetchDestination(e.data);
var tabName = destination;
var source = ircClientRef.fetchSource(e.data);
var tabName = ircClientRef.nick == destination ? source : destination;
console.log("Destination of the message: " + destination);
var server = ircClientRef.displayDestinationMessage(tabName, msg);
};
this.createUserTab = function(dest) {
this.checkForDestElseCreate(dest);
};
};

View File

@ -31,7 +31,11 @@ window.onload = function () {
var command = messageInput.value;
if (command.startsWith("/")) {
// special command
window.ircClient.sendMsg(command.substr(1));
if (command.toUpperCase().startsWith("/QUERY")) {
window.ircClient.createUserTab(command.substr(6).trim());
} else {
window.ircClient.sendMsg(command.substr(1));
}
} else {
window.ircClient.sendPrivMsg(command);
}