diff --git a/index.html b/index.html index 4d57c7b..fd85794 100644 --- a/index.html +++ b/index.html @@ -31,11 +31,11 @@

diff --git a/js/language.js b/js/language.js index c3f84a2..1d6fd39 100644 --- a/js/language.js +++ b/js/language.js @@ -1,210 +1,210 @@ -/* Language specific functions -- start -- */ -function getLocalLanguageSelection() { - let linput = window.localStorage.getItem('localization'); - if (linput != undefined && linput != '') { - return linput; - } - else { - return "gb"; - } -} - -function setLanguage() { - let language = $("#channel_localization").val(); - - switch (language) { - case "fi": - $("#channel_user_name").text("Nimesi?"); - $("#channel_name").text("Kanava?"); - $("#channel_key").text("Jaettu avain?"); - $("#channel_server").text("Mles WebSocket palvelimen osoite"); - $("#channel_exit").val("poistu"); - $("#app_info").text("lisätietoja sovelluksesta"); - $("#legal").text("lakitiedot"); - gWeekday[0] = "su"; - gWeekday[1] = "ma"; - gWeekday[2] = "ti"; - gWeekday[3] = "ke"; - gWeekday[4] = "to"; - gWeekday[5] = "pe"; - gWeekday[6] = "la"; - gBgTitle = "MlesTalk taustalla"; - gBgText = "Ilmoitukset aktiivisena"; - gImageStr = ""; - break; - case "se": - $("#channel_user_name").text("Ditt namn?"); - $("#channel_name").text("Kanal?"); - $("#channel_key").text("Delad nyckel?"); - $("#channel_server").text("Mles WebSocket server adress"); - $("#channel_exit").val("utgång"); - $("#app_info").text("appinfo"); - $("#legal").text("rättslig"); - gWeekday[0] = "sö"; - gWeekday[1] = "må"; - gWeekday[2] = "ti"; - gWeekday[3] = "on"; - gWeekday[4] = "to"; - gWeekday[5] = "fr"; - gWeekday[6] = "lö"; - gBgTitle = "MlesTalk i bakgrunden"; - gBgText = "Meddelanden aktiva"; - gImageStr = ""; - break; - case "es": - $("#channel_user_name").text("¿Su nombre?"); - $("#channel_name").text("¿Canal?"); - $("#channel_key").text("¿Llave compartida?"); - $("#channel_server").text("Dirección del servidor Mles Websocket"); - $("#channel_exit").val("salida"); - $("#app_info").text("info de la app"); - $("#legal").text("legal"); - gWeekday[0] = "D"; - gWeekday[1] = "L"; - gWeekday[2] = "M"; - gWeekday[3] = "X"; - gWeekday[4] = "J"; - gWeekday[5] = "V"; - gWeekday[6] = "S"; - gBgTitle = "MlesTalk en el fondo"; - gBgText = "Notificaciones activas"; - gImageStr = ""; - break; - case "de": - $("#channel_user_name").text("Dein name?"); - $("#channel_name").text("Kanal?"); - $("#channel_key").text("Gemeinsamer Schlüssel?"); - $("#channel_server").text("Mles WebSocket Serveradresse"); - $("#channel_exit").val("abgehen"); - $("#app_info").text("app info"); - $("#legal").text("legal"); - gWeekday[0] = "So"; - gWeekday[1] = "Mo"; - gWeekday[2] = "Di"; - gWeekday[3] = "Mi"; - gWeekday[4] = "Do"; - gWeekday[5] = "Fr"; - gWeekday[6] = "Sa"; - gBgTitle = "MlesTalk im Hintergrund"; - gBgText = "Benachrichtigungen aktiv"; - gImageStr = ""; - break; - case "fr": - $("#channel_user_name").text("Votre nom?"); - $("#channel_name").text("Canal?"); - $("#channel_key").text("Clé partagée?"); - $("#channel_server").text("Mles WebSocket adresse du serveur"); - $("#channel_exit").val("sortie"); - $("#app_info").text("info sur l'app"); - $("#legal").text("légal"); - gWeekday[0] = "dim"; - gWeekday[1] = "lun"; - gWeekday[2] = "mar"; - gWeekday[3] = "mer"; - gWeekday[4] = "jeu"; - gWeekday[5] = "ven"; - gWeekday[6] = "sam"; - gBgTitle = "MlesTalk en arrière-plan"; - gBgText = "Notifications actives"; - gImageStr = ""; - break; - case "pt": - $("#channel_user_name").text("Seu nome?"); - $("#channel_name").text("Canal?"); - $("#channel_key").text("Chave compartilhada?"); - $("#channel_server").text("Endereço do servidor Mles Websocket"); - $("#channel_exit").val("saída"); - $("#app_info").text("informação da aplicação"); - $("#legal").text("legal"); - gWeekday[0] = "Dom."; - gWeekday[1] = "Seg."; - gWeekday[2] = "Ter."; - gWeekday[3] = "Qua."; - gWeekday[4] = "Qui."; - gWeekday[5] = "Sex."; - gWeekday[6] = "Sáb."; - gBgTitle = "MlesTalk correndo em segundo plano"; - gBgText = "Notificações ativas"; - gImageStr = ""; - break; - case "ru": - $("#channel_user_name").text("Твое имя?"); - $("#channel_name").text("Канал?"); - $("#channel_key").text("Общий ключ?"); - $("#channel_server").text("Адрес сервера Mles Websocket"); - $("#channel_exit").val("выход"); - $("#app_info").text("информация о приложении"); - $("#legal").text("правовой"); - gWeekday[0] = "ВСК"; - gWeekday[1] = "ПНД"; - gWeekday[2] = "ВТР"; - gWeekday[3] = "СРД"; - gWeekday[4] = "ЧТВ"; - gWeekday[5] = "ПТН"; - gWeekday[6] = "СБТ"; - gBgTitle = "MlesTalk в фоновом режиме"; - gBgText = "Уведомления активны"; - gImageStr = "<изображение>"; - break; - case "gb": - default: - $("#channel_user_name").text("Your name?"); - $("#channel_name").text("Channel?"); - $("#channel_key").text("Shared key?"); - $("#channel_server").text("Mles WebSocket server address"); - $("#channel_exit").val("exit"); - $("#app_info").text("app info"); - $("#legal").text("legal"); - gWeekday[0] = "Sun"; - gWeekday[1] = "Mon"; - gWeekday[2] = "Tue"; - gWeekday[3] = "Wed"; - gWeekday[4] = "Thu"; - gWeekday[5] = "Fri"; - gWeekday[6] = "Sat"; - gBgTitle = "MlesTalk in the background"; - gBgText = "Notifications active"; - gImageStr = ""; - break; - } - - if (isCordova) { - cordova.plugins.backgroundMode.setDefaults({ - title: gBgTitle, - text: gBgText - }); - } -} - -function popAlert() { - let language = $("#channel_localization").val(); - switch (language) { - case "fi": - alert('Nimi, kanava ja jaettu avain?'); - break; - case "se": - alert('Namn, kanal och delad nyckel?'); - break; - case "es": - alert('Nombre, canal y clave compartida?'); - break; - case "de": - alert('Name, Kanal und gemeinsamer Schlüssel?'); - break; - case "fr": - alert('Nom, canal et clé partagée?'); - break; - case "pt": - alert('Seu nome, canal e chave compartilhada?'); - break; - case "ru": - alert('Твое имя, канал и общий ключ?'); - break; - case "gb": - default: - alert('Name, channel and shared key?'); - break; - } -} - -/* Language specific functions -- end -- */ +/* Language specific functions -- start -- */ +function getLocalLanguageSelection() { + let linput = window.localStorage.getItem('localization'); + if (linput != undefined && linput != '') { + return linput; + } + else { + return "gb"; + } +} + +function setLanguage() { + let language = $("#channel_localization").val(); + + switch (language) { + case "fi": + $("#channel_user_name").text("Nimesi?"); + $("#channel_name").text("Kanava?"); + $("#channel_key").text("Jaettu avain?"); + $("#channel_server").text("WebSocket palvelimen osoite"); + $("#channel_exit").val("poistu"); + $("#app_info").text("lisätietoja sovelluksesta"); + $("#legal").text("lakitiedot"); + gWeekday[0] = "su"; + gWeekday[1] = "ma"; + gWeekday[2] = "ti"; + gWeekday[3] = "ke"; + gWeekday[4] = "to"; + gWeekday[5] = "pe"; + gWeekday[6] = "la"; + gBgTitle = "MlesTalk taustalla"; + gBgText = "Ilmoitukset aktiivisena"; + gImageStr = ""; + break; + case "se": + $("#channel_user_name").text("Ditt namn?"); + $("#channel_name").text("Kanal?"); + $("#channel_key").text("Delad nyckel?"); + $("#channel_server").text("WebSocket server adress"); + $("#channel_exit").val("utgång"); + $("#app_info").text("appinfo"); + $("#legal").text("rättslig"); + gWeekday[0] = "sö"; + gWeekday[1] = "må"; + gWeekday[2] = "ti"; + gWeekday[3] = "on"; + gWeekday[4] = "to"; + gWeekday[5] = "fr"; + gWeekday[6] = "lö"; + gBgTitle = "MlesTalk i bakgrunden"; + gBgText = "Meddelanden aktiva"; + gImageStr = ""; + break; + case "es": + $("#channel_user_name").text("¿Su nombre?"); + $("#channel_name").text("¿Canal?"); + $("#channel_key").text("¿Llave compartida?"); + $("#channel_server").text("Dirección del servidor Websocket"); + $("#channel_exit").val("salida"); + $("#app_info").text("info de la app"); + $("#legal").text("legal"); + gWeekday[0] = "D"; + gWeekday[1] = "L"; + gWeekday[2] = "M"; + gWeekday[3] = "X"; + gWeekday[4] = "J"; + gWeekday[5] = "V"; + gWeekday[6] = "S"; + gBgTitle = "MlesTalk en el fondo"; + gBgText = "Notificaciones activas"; + gImageStr = ""; + break; + case "de": + $("#channel_user_name").text("Dein name?"); + $("#channel_name").text("Kanal?"); + $("#channel_key").text("Gemeinsamer Schlüssel?"); + $("#channel_server").text("WebSocket Serveradresse"); + $("#channel_exit").val("abgehen"); + $("#app_info").text("app info"); + $("#legal").text("legal"); + gWeekday[0] = "So"; + gWeekday[1] = "Mo"; + gWeekday[2] = "Di"; + gWeekday[3] = "Mi"; + gWeekday[4] = "Do"; + gWeekday[5] = "Fr"; + gWeekday[6] = "Sa"; + gBgTitle = "MlesTalk im Hintergrund"; + gBgText = "Benachrichtigungen aktiv"; + gImageStr = ""; + break; + case "fr": + $("#channel_user_name").text("Votre nom?"); + $("#channel_name").text("Canal?"); + $("#channel_key").text("Clé partagée?"); + $("#channel_server").text("WebSocket adresse du serveur"); + $("#channel_exit").val("sortie"); + $("#app_info").text("info sur l'app"); + $("#legal").text("légal"); + gWeekday[0] = "dim"; + gWeekday[1] = "lun"; + gWeekday[2] = "mar"; + gWeekday[3] = "mer"; + gWeekday[4] = "jeu"; + gWeekday[5] = "ven"; + gWeekday[6] = "sam"; + gBgTitle = "MlesTalk en arrière-plan"; + gBgText = "Notifications actives"; + gImageStr = ""; + break; + case "pt": + $("#channel_user_name").text("Seu nome?"); + $("#channel_name").text("Canal?"); + $("#channel_key").text("Chave compartilhada?"); + $("#channel_server").text("Endereço do servidor Websocket"); + $("#channel_exit").val("saída"); + $("#app_info").text("informação da aplicação"); + $("#legal").text("legal"); + gWeekday[0] = "Dom."; + gWeekday[1] = "Seg."; + gWeekday[2] = "Ter."; + gWeekday[3] = "Qua."; + gWeekday[4] = "Qui."; + gWeekday[5] = "Sex."; + gWeekday[6] = "Sáb."; + gBgTitle = "MlesTalk correndo em segundo plano"; + gBgText = "Notificações ativas"; + gImageStr = ""; + break; + case "ru": + $("#channel_user_name").text("Твое имя?"); + $("#channel_name").text("Канал?"); + $("#channel_key").text("Общий ключ?"); + $("#channel_server").text("Адрес сервера Websocket"); + $("#channel_exit").val("выход"); + $("#app_info").text("информация о приложении"); + $("#legal").text("правовой"); + gWeekday[0] = "ВСК"; + gWeekday[1] = "ПНД"; + gWeekday[2] = "ВТР"; + gWeekday[3] = "СРД"; + gWeekday[4] = "ЧТВ"; + gWeekday[5] = "ПТН"; + gWeekday[6] = "СБТ"; + gBgTitle = "MlesTalk в фоновом режиме"; + gBgText = "Уведомления активны"; + gImageStr = "<изображение>"; + break; + case "gb": + default: + $("#channel_user_name").text("Your name?"); + $("#channel_name").text("Channel?"); + $("#channel_key").text("Shared key?"); + $("#channel_server").text("WebSocket server address"); + $("#channel_exit").val("exit"); + $("#app_info").text("app info"); + $("#legal").text("legal"); + gWeekday[0] = "Sun"; + gWeekday[1] = "Mon"; + gWeekday[2] = "Tue"; + gWeekday[3] = "Wed"; + gWeekday[4] = "Thu"; + gWeekday[5] = "Fri"; + gWeekday[6] = "Sat"; + gBgTitle = "MlesTalk in the background"; + gBgText = "Notifications active"; + gImageStr = ""; + break; + } + + if (isCordova) { + cordova.plugins.backgroundMode.setDefaults({ + title: gBgTitle, + text: gBgText + }); + } +} + +function popAlert() { + let language = $("#channel_localization").val(); + switch (language) { + case "fi": + alert('Nimi, kanava ja jaettu avain?'); + break; + case "se": + alert('Namn, kanal och delad nyckel?'); + break; + case "es": + alert('Nombre, canal y clave compartida?'); + break; + case "de": + alert('Name, Kanal und gemeinsamer Schlüssel?'); + break; + case "fr": + alert('Nom, canal et clé partagée?'); + break; + case "pt": + alert('Seu nome, canal e chave compartilhada?'); + break; + case "ru": + alert('Твое имя, канал и общий ключ?'); + break; + case "gb": + default: + alert('Name, channel and shared key?'); + break; + } +} + +/* Language specific functions -- end -- */ diff --git a/js/mlestalk.js b/js/mlestalk.js index 912b3da..646d798 100644 --- a/js/mlestalk.js +++ b/js/mlestalk.js @@ -23,16 +23,16 @@ let gPrevBdKey = null; let gForwardSecrecy = false; /* Msg type flags */ -const MSGISFULL = 0x1; -const MSGISPRESENCE = (0x1 << 1); -const MSGISIMAGE = (0x1 << 2); -const MSGISMULTIPART = (0x1 << 3); -const MSGISFIRST = (0x1 << 4); -const MSGISLAST = (0x1 << 5); +const MSGISFULL = 0x1; +const MSGISPRESENCE = (0x1 << 1); +const MSGISIMAGE = (0x1 << 2); +const MSGISMULTIPART = (0x1 << 3); +const MSGISFIRST = (0x1 << 4); +const MSGISLAST = (0x1 << 5); const MSGISPRESENCEACK = (0x1 << 6); -const MSGPRESACKREQ = (0x1 << 7); -const MSGISBDONE = (0x1 << 8); -const MSGISBDACK = (0x1 << 9); +const MSGPRESACKREQ = (0x1 << 7); +const MSGISBDONE = (0x1 << 8); +const MSGISBDACK = (0x1 << 9); let gUidQueue = {}; @@ -40,13 +40,13 @@ const IMGMAXSIZE = 960; /* px */ const IMGFRAGSIZE = 512 * 1024; let gInitOk = false; -const PRESENCETIME = (3 * 60 + 1) * 1000 ; /* ms */ +const PRESENCETIME = (3 * 60 + 1) * 1000; /* ms */ const IDLETIME = (11 * 60 + 1) * 1000; /* ms */ const PRESENCE_SHOW_TIMER = 5000; /* ms */ const RETIMEOUT = 1500; /* ms */ const MAXTIMEOUT = 1000 * 60 * 5; /* ms */ const MAXQLEN = 32; -const RESYNC_TIMEOUT = 15000; /* ms */ +const RESYNC_TIMEOUT = 2000; /* ms */ const LED_ON_TIME = 500; /* ms */ const LED_OFF_TIME = 2500; /* ms */ const SCROLL_TIME = 500; /* ms */ @@ -143,7 +143,7 @@ function queueFindAndMatch(msgTimestamp, uid, channel, message, isFull) { lastSeen = i + 1; continue; } - if(message.length > 0) { + if (message.length > 0) { let hash = hashMessage(uid, isFull ? msgTimestamp + message + '\n' : msgTimestamp + message); if (obj[2] == hash) { lastSeen = i + 1; @@ -174,12 +174,12 @@ function queueSweepAndSend(uid, channel) { let tmp = obj[1]; if (tmp[2] == uid) { const fs = obj[4]; - if(fs) { + if (fs) { tmp[0] = "resend_prev"; } cnt++; gWebWorker.postMessage(tmp); - if(fs) { + if (fs) { q.remove(i); i -= 1; len -= 1; @@ -273,10 +273,10 @@ function onResume() { let gIsPresenceView = false; function onBackKeyDown() { - if(!gInitOk) + if (!gInitOk) return; /* Open presence info */ - if(!gIsPresenceView) { + if (!gIsPresenceView) { gIsPresenceView = true; presenceShow(); } @@ -406,11 +406,11 @@ function askChannel() { } /* Presence */ -function sendEmptyJoin() { +function sendEmptyJoin() { sendMessage("", false, true); } -function sendPresAck() { +function sendPresAck() { sendMessage("", false, true, true); } @@ -441,17 +441,20 @@ function chanExit() { function outputPresenceList() { let date = Date.now(); - for (let userid in gPresenceTs) { - let userpres = userid.split('|'); - if(userpres[0] == gMyName) + for (let val in gPresenceTs) { + let arr = gPresenceTs[val]; + const user = arr[0]; + const channel = arr[1]; + const timestamp = arr[2]; + if (user == gMyName) continue; //console.log("Timestamp" + gPresenceTs[userid].valueOf() + " Saved timestamp " + date.valueOf()) - if(gPresenceTs[userid].valueOf() + PRESENCETIME >= date.valueOf()) - li = '
  • ' + userpres[0] + "@" + userpres[1] + ' green
  • '; - else if(gPresenceTs[userid].valueOf() + IDLETIME >= date.valueOf()) - li = '
  • ' + userpres[0] + "@" + userpres[1] + ' light green
  • '; + if (timestamp.valueOf() + PRESENCETIME >= date.valueOf()) + li = '
  • ' + user + "@" + channel + ' green
  • '; + else if (timestamp.valueOf() + IDLETIME >= date.valueOf()) + li = '
  • ' + user + "@" + channel + ' light green
  • '; else - li = '
  • ' + userpres[0] + "@" + userpres[1] + ' grey
  • '; + li = '
  • ' + user + "@" + channel + ' grey
  • '; $('#presence_avail').append(li); } $('#message_cont').fadeOut(400, function () { @@ -460,7 +463,7 @@ function outputPresenceList() { } async function presenceShow() { - while(gIsPresenceView) { + while (gIsPresenceView) { //console.log("Building presence list.."); $('#presence_avail').html(''); outputPresenceList(); @@ -514,7 +517,7 @@ function closeSocket() { $("#input_channel").val(''); $("#input_key").val(''); if (!gIsTokenChannel) - $('#qrcode').fadeOut(); + $('#qrcode').fadeOut(); $('#presence_cont').fadeOut(); $('#message_cont').fadeOut(400, function () { $('#name_channel_cont').fadeIn(); @@ -584,17 +587,17 @@ function processForwardSecrecyOff() { function msgHashHandle(uid, channel, msgTimestamp, mhash) { let timedict = gIdTimestamp[get_uniq(uid, channel)]; - if(!timedict) { + if (!timedict) { gIdTimestamp[get_uniq(uid, channel)] = {}; timedict = gIdTimestamp[get_uniq(uid, channel)]; } let arr = timedict[msgTimestamp]; - if(!arr) { + if (!arr) { timedict[msgTimestamp] = [mhash]; return true; } for (const hash of arr) { - if(hash == mhash) { + if (hash == mhash) { return false; } } @@ -602,16 +605,34 @@ function msgHashHandle(uid, channel, msgTimestamp, mhash) { return true; } +let prevUid = ""; +let prevChannel = ""; +let prevTime = ""; +function checkTime(uid, channel, time, isFull) { + /* Skip time output for the same minute */ + if(prevUid == uid && + prevChannel == channel && + prevTime == time) + { + return ""; + } + if(isFull) { + prevUid = uid; + prevChannel = channel; + prevTime = time; + } + return time; +} + function processData(uid, channel, msgTimestamp, message, isFull, isPresence, isPresenceAck, presAckRequired, isImage, - isMultipart, isFirst, isLast, fsEnabled) -{ + isMultipart, isFirst, isLast, fsEnabled) { //update hash let duid = get_duid(uid, channel); if (gIdHash[duid] == null) { gIdHash[duid] = 0; gIdAppend[duid] = false; - gPresenceTs[get_uniq(uid, channel)] = msgTimestamp; + gPresenceTs[get_uniq(uid, channel)] = [uid, channel, msgTimestamp]; gIdNotifyTs[get_uniq(uid, channel)] = 0; } @@ -646,7 +667,7 @@ function processData(uid, channel, msgTimestamp, gMultipartDict[get_uniq(uid, channel)] = ""; } // handle multipart hashing here - if(msgHashHandle(uid, channel, msgTimestamp, mHash)) { + if (msgHashHandle(uid, channel, msgTimestamp, mHash)) { gMultipartDict[get_uniq(uid, channel)] += message; if (!isLast) { return 0; @@ -666,12 +687,12 @@ function processData(uid, channel, msgTimestamp, let time; let li; - gPresenceTs[get_uniq(uid, channel)] = msgTimestamp; + gPresenceTs[get_uniq(uid, channel)] = [uid, channel, msgTimestamp]; if (gLastMessageSeenTs < msgTimestamp) gLastMessageSeenTs = msgTimestamp; - if(!gIsResync && presAckRequired) { + if (!gIsResync && presAckRequired) { sendPresAck(); //console.log("Sending presence ack to " + uid + " timestamp " + stampTime(new Date(msgTimestamp)) + "!"); } @@ -689,37 +710,53 @@ function processData(uid, channel, msgTimestamp, } time = updateTime(dateString); + if(!date) + time = checkTime(uid, channel, time, isFull); + /* Check first is it a text or image */ if (isImage) { - if (uid != gMyName) { - li = '
  • ' + uid + ' ' + time + - ''; + if (!fsEnabled) { + if (uid != gMyName) { + li = '
  • ' + uid + ' ' + time + + ''; - } - else { - li = '
  • ' + time - + ''; + } + else { + li = '
  • ' + time + + ''; + + } + } else { + if (uid != gMyName) { + li = '
  • ' + uid + ' ' + time + + ''; + } + else { + li = '
  • ' + time + + ''; + + } } li += '
  • '; } else { - if(!fsEnabled) { + if (!fsEnabled) { if (uid != gMyName) { li = '
  • ' + uid + ' ' - + time + "" + autolinker.link(message) + '
  • '; + + time + '' + autolinker.link(message) + ''; } else { - li = '
  • ' + time + "" + autolinker.link(message) + '
  • '; + li = '
  • ' + time + '' + autolinker.link(message) + '
  • '; } } else { if (uid != gMyName) { - li = '
  • ' + uid + ' ' - + time + '' + autolinker.link(message) + '
  • '; + li = '
  • ' + uid + ' ' + + time + '' + autolinker.link(message) + '
  • '; } else { - li = '
  • ' + time + '' + autolinker.link(message) + '
  • '; + li = '
  • ' + time + '' + autolinker.link(message) + '
  • '; } } } @@ -743,7 +780,7 @@ function processData(uid, channel, msgTimestamp, scrollToBottom(); } - const notifyTimestamp = parseInt(msgTimestamp/1000/60); //one notify per minute + const notifyTimestamp = parseInt(msgTimestamp / 1000 / 60); //one notify per minute if (uid != gMyName && isFull && gIdNotifyTs[get_uniq(uid, channel)] < notifyTimestamp) { if (gWillNotify && gCanNotify) { if (true == isImage) { @@ -811,7 +848,7 @@ gWebWorker.onmessage = function (e) { msgtype & MSGISIMAGE ? true : false, msgtype & MSGISMULTIPART ? true : false, msgtype & MSGISFIRST ? true : false, - msgtype & MSGISLAST ? true : false, + msgtype & MSGISLAST ? true : false, fsEnabled); if (ret < 0) { console.log("Process data failed: " + ret); @@ -844,20 +881,20 @@ gWebWorker.onmessage = function (e) { } break; case "forwardsecrecy": - { - let uid = e.data[1]; - let channel = e.data[2]; - //let myuid = e.data[3]; - //let mychan = e.data[4]; - const prevBdKey = e.data[5]; - - let ret = processForwardSecrecy(uid, channel, prevBdKey); - //console.log("Got forward secrecy!") - if (ret < 0) { - console.log("Process close failed: " + ret); - } + { + let uid = e.data[1]; + let channel = e.data[2]; + //let myuid = e.data[3]; + //let mychan = e.data[4]; + const prevBdKey = e.data[5]; + + let ret = processForwardSecrecy(uid, channel, prevBdKey); + //console.log("Got forward secrecy!") + if (ret < 0) { + console.log("Process close failed: " + ret); } - break; + } + break; case "forwardsecrecyoff": { let uid = e.data[1]; @@ -960,12 +997,12 @@ function scrollToBottom() { function sendData(cmd, uid, channel, data, msgtype) { if (gInitOk) { - const msgDate = parseInt(Date.now()/1000) * 1000; //in seconds + const msgDate = parseInt(Date.now() / 1000) * 1000; //in seconds let mHash; let arr = [cmd, data, uid, channel, gIsTokenChannel, msgtype, msgDate.valueOf()]; - if(!(msgtype & MSGISPRESENCE) && gSipKeyIsOk) { + if (!(msgtype & MSGISPRESENCE) && gSipKeyIsOk) { mHash = hashMessage(uid, msgtype & MSGISFULL ? msgDate.valueOf() + data + '\n' : msgDate.valueOf() + data); msgHashHandle(uid, channel, msgDate.valueOf(), mHash); } @@ -991,17 +1028,26 @@ function updateAfterSend(message, isFull, isImage) { $('#messages').append(li); } + if(!date) + time = checkTime(gMyName, gMyChannel, time, isFull); + if (!isImage) { if (!gForwardSecrecy) { li = '
  • ' + time + "" + autolinker.link(message) + '
  • '; } else { - li = '
  • ' + time + '' + autolinker.link(message) + '
  • '; + li = '
  • ' + time + '' + autolinker.link(message) + '
  • '; } } else { + if (!gForwardSecrecy) { li = '
  • ' + time + '
  • '; + } + else { + li = '
  • ' + time + + '
  • '; + } } @@ -1036,7 +1082,7 @@ function sendMessage(message, isFull, isPresence, isPresenceAck = false) { const MULTIPART_SLICE = 768; //B async function sendDataurl(dataUrl, uid, channel) { - let msgtype = MSGISFULL|MSGISIMAGE; + let msgtype = MSGISFULL | MSGISIMAGE; if (dataUrl.length > MULTIPART_SLICE) { msgtype |= MSGISMULTIPART; @@ -1134,14 +1180,14 @@ function getLocalAddrPortInput() { function getLocalBdKey() { const bdKey = window.localStorage.getItem('gPrevBdKey'); - if(bdKey) { + if (bdKey) { gPrevBdKey = bdKey; //console.log("Loading key from local storage!"); } } function setLocalBdKey(bdKey) { - if(bdKey) { + if (bdKey) { window.localStorage.setItem('gPrevBdKey', bdKey); //console.log("Saving keys to local storage!"); }