diff --git a/src/main/java/pl/polgrabiat/websockets/chat/websocketschat/handlers/PrivMessageHandler.java b/src/main/java/pl/polgrabiat/websockets/chat/websocketschat/handlers/PrivMessageHandler.java index 2ca4a5c..23b9ee6 100644 --- a/src/main/java/pl/polgrabiat/websockets/chat/websocketschat/handlers/PrivMessageHandler.java +++ b/src/main/java/pl/polgrabiat/websockets/chat/websocketschat/handlers/PrivMessageHandler.java @@ -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; } diff --git a/src/main/java/pl/polgrabiat/websockets/chat/websocketschat/handlers/UserCommandHandler.java b/src/main/java/pl/polgrabiat/websockets/chat/websocketschat/handlers/UserCommandHandler.java index 7fe54a4..d30b641 100644 --- a/src/main/java/pl/polgrabiat/websockets/chat/websocketschat/handlers/UserCommandHandler.java +++ b/src/main/java/pl/polgrabiat/websockets/chat/websocketschat/handlers/UserCommandHandler.java @@ -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; } } diff --git a/src/main/resources/static/IrcClient.js b/src/main/resources/static/IrcClient.js index e358006..4b7a6cf 100644 --- a/src/main/resources/static/IrcClient.js +++ b/src/main/resources/static/IrcClient.js @@ -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); + }; + }; \ No newline at end of file diff --git a/src/main/resources/static/index.js b/src/main/resources/static/index.js index 6e0871d..fef79a4 100644 --- a/src/main/resources/static/index.js +++ b/src/main/resources/static/index.js @@ -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); }