From 3fd55d3389e5d1d496a62bbb7ee95234c304ca8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anton=20L=2E=20=C5=A0ijanec?= Date: Sun, 5 Apr 2020 20:23:30 +0200 Subject: chats.js not done yet --- js/chats.js | 373 ++++++++++++++++++++++++++++++++++++++++++++++++++++ js/gsec.js | 18 ++- js/lang/bundle.js | 26 +++- js/messaging.js | 2 +- js/setup-storage.js | 3 +- 5 files changed, 411 insertions(+), 11 deletions(-) create mode 100644 js/chats.js (limited to 'js') diff --git a/js/chats.js b/js/chats.js new file mode 100644 index 0000000..73dc791 --- /dev/null +++ b/js/chats.js @@ -0,0 +1,373 @@ +const API_ENDPOINT = "https://gimb.tk/test.php"; +const DIRECTORY_URL = "/directory.json"; +// "Global" object for name directory +var directory = null; +var currentlyChattingWith = null; // msgid +var sogovornik = null; // name +var firstPageOfMessages = null; // so we can test if new messages ever arrive + +async function checkLogin() { + localforage.getItem("logged_in").then(function (value) { + // This code runs once the value has been loaded + // from the offline store. + if (value !== true) { + window.location.replace("/index.html"); + } + }).catch(function (err) { + // This code runs if there were any errors + console.log(err); + }); +} +function getKeyByValue(object, value) { + return Object.keys(object).find(key => object[key] === value); +} +// -----------HTML HELPERS----------- +function htmlEncode(value) { + // Create a in-memory element, set its inner text (which is automatically encoded) + // Then grab the encoded contents back out. The element never exists on the DOM. + return $("