diff --git a/pages/css/style.css b/pages/css/style.css index 12d3ad7..84cd14f 100644 --- a/pages/css/style.css +++ b/pages/css/style.css @@ -4,6 +4,8 @@ body { #errormsg, #successmsg { display: none; + box-shadow: 5px 5px 3px #888888; + z-index: 999; } #errormsg { @@ -26,7 +28,7 @@ body { color: #00ff00; } -#sidebar { +#sidebarr { float: right; width: 20%; } @@ -64,18 +66,48 @@ html, body { margin: 0; } -#conversations +#sidebarl { width: 20%; float: left; } -#conversation +.chmessage { - + } -#unreadmsg +.unreadmsg { background-color: #DDD; -} \ No newline at end of file +} + +#hoverdialogcont +{ + display: none; + position: absolute; + top: 0px; + left: 0px; + height: 100%; + width: 100%; + background-color: rgba(0, 0, 0, 0.5); +} + +#hoverdialogmid { + display: table-cell; + vertical-align: middle; +} + +#hoverdialog +{ + width: 30%; + background-color: #EEE; + margin-left: auto; + margin-right: auto; + box-shadow: 5px 5px 3px #888888; +} + +.list +{ + width: 100%; +} diff --git a/pages/index.html b/pages/index.html index 146d694..c1a8e26 100644 --- a/pages/index.html +++ b/pages/index.html @@ -13,23 +13,25 @@ +
Logged in as
Loading...
+Not in a conversation!
", exchange); + return; + } + if (!post.has("userid")) { + IOHelper.SendResponse(200, "User ID not found: " + post + "
", exchange); + return; + } + long userid = post.get("userid").getAsLong(); + User adduser = DataManager.load(User.class, userid, false); + if (adduser == null) { + IOHelper.SendResponse(200, "User not found: " + userid + "
", exchange); + return; + } + Conversation currentconversation = user.getCurrentConversation().get(); + if (currentconversation.getUsers().contains(userid)) { + IOHelper.SendResponse(200, "The user is already in the conversation
", exchange); + return; + } + currentconversation.getUsers().add(adduser); + adduser.getConversations().add(currentconversation); + IOHelper.SendResponse(200, doc -> currentconversation.getAsHtml(doc).ownerDocument(), exchange); + break; + } default: { IOHelper.SendResponse(400, "Unknown action: " + post.get("action").getAsString() + "
", @@ -54,5 +98,4 @@ public class ConversationsAjaxPage extends Page { } } } - } diff --git a/src/io/github/norbipeti/chat/server/page/IndexPage.java b/src/io/github/norbipeti/chat/server/page/IndexPage.java index 2be99f5..f9afb19 100644 --- a/src/io/github/norbipeti/chat/server/page/IndexPage.java +++ b/src/io/github/norbipeti/chat/server/page/IndexPage.java @@ -46,6 +46,12 @@ public class IndexPage extends Page { message.getAsHTML(channelmessages); } } + for (int i = 0; i < conv.getUsers().size(); i++) + doc.getElementById("usersinconv").appendElement("div").attr("id", "convuser" + i) + .addClass("convuser").appendElement("p").text(conv.getUsers().get(i).getName()); + doc.getElementById("sidebarr").appendElement("div").attr("id", "addconvuser").appendElement("a") + .text("Add user to conversation").attr("href", "javascript:showAddUserToConv()"); + // TODO: Update users and conversations automatically on conv change } cide.attr("style", "display: none"); cide.attr("id", "convidp"); @@ -53,17 +59,12 @@ public class IndexPage extends Page { Element conversations = doc.getElementById("conversations"); for (Conversation conv : user.getConversations()) conv.getAsHtml(conversations); + conversations.appendElement("div").attr("id", "addconv").appendElement("a").attr("href", "#") + .attr("onclick", "return addConversation();").text("Add conversation"); return doc; }, exchange); - } // TODO: - // Validation - // at - // registration - // (no - // special - // chars, - // etc.) + } // TODO: Validation at registration (no special chars, etc.) @Override public String GetName() { diff --git a/src/io/github/norbipeti/chat/server/page/Page.java b/src/io/github/norbipeti/chat/server/page/Page.java index f720f95..871f4b5 100644 --- a/src/io/github/norbipeti/chat/server/page/Page.java +++ b/src/io/github/norbipeti/chat/server/page/Page.java @@ -41,7 +41,7 @@ public abstract class Page implements HttpHandler { str.print(""); IOHelper.SendResponse(500, baos.toString(StandardCharsets.ISO_8859_1), exchange); } catch (Exception e1) { - e1.printStackTrace(); // TODO: Message listener JS + e1.printStackTrace(); } } } diff --git a/src/io/github/norbipeti/chat/server/page/UsersAjaxPage.java b/src/io/github/norbipeti/chat/server/page/UsersAjaxPage.java new file mode 100644 index 0000000..1fd7c08 --- /dev/null +++ b/src/io/github/norbipeti/chat/server/page/UsersAjaxPage.java @@ -0,0 +1,68 @@ +package io.github.norbipeti.chat.server.page; + +import java.io.IOException; + +import org.jsoup.nodes.Document; +import org.jsoup.nodes.Element; + +import com.google.gson.JsonObject; +import com.sun.net.httpserver.HttpExchange; + +import io.github.norbipeti.chat.server.data.DataManager; +import io.github.norbipeti.chat.server.db.domain.Conversation; +import io.github.norbipeti.chat.server.db.domain.ManagedData; +import io.github.norbipeti.chat.server.db.domain.User; +import io.github.norbipeti.chat.server.io.IOHelper; + +public class UsersAjaxPage extends Page { + + @Override + public String GetName() { + return "users"; + } + + @Override + public void handlePage(HttpExchange exchange) throws IOException { + JsonObject post = IOHelper.GetPOSTJSON(exchange); + User user = IOHelper.GetLoggedInUser(exchange); + if (user == null) { + IOHelper.SendResponse(403, "Not a JSON string: " + IOHelper.GetPOST(exchange) + "
", exchange); + return; + } + if (!post.has("action")) { + IOHelper.SendResponse(400, "Action missing: " + post + "
", exchange); + return; + } + switch (post.get("action").getAsString()) { + case "search": { + if (!post.has("searchstr")) { + IOHelper.SendResponse(400, "Search string missing: " + post + "
", + exchange); + return; + } + String searchstr = post.get("searchstr").getAsString().toLowerCase(); + Document doc = new Document(""); + if (searchstr.length() != 0) + for (User suser : DataManager.getAll(User.class)) + if (suser.getEmail().toLowerCase().contains(searchstr) + || suser.getName().toLowerCase().contains(searchstr)) + doc.appendElement("option").addClass("resuser").attr("value", suser.getId() + "") + .text(suser.getName()); + IOHelper.SendResponse(200, doc.toString(), exchange); + break; + } + default: { + IOHelper.SendResponse(400, + "Unknown action: " + post.get("action").getAsString() + "
", + exchange); + break; + } + } + } + +}