2019-08-08 03:45:18 +00:00
|
|
|
/*
|
|
|
|
Onionr - Private P2P Communication
|
|
|
|
|
|
|
|
Main Onionr chat UI script
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>
|
|
|
|
*/
|
2019-06-20 07:59:32 +00:00
|
|
|
friendList = {}
|
2019-05-18 18:46:48 +00:00
|
|
|
convoListElement = document.getElementsByClassName('conversationList')[0]
|
2019-08-17 07:27:33 +00:00
|
|
|
firstConvoLoad = true
|
2019-09-05 09:40:31 +00:00
|
|
|
activeConvo = null;
|
2019-05-18 18:46:48 +00:00
|
|
|
|
|
|
|
function createConvoList(){
|
2019-08-17 07:27:33 +00:00
|
|
|
convoListElement.innerHTML = ""
|
2019-06-20 07:59:32 +00:00
|
|
|
for (friend in friendList){
|
2019-08-17 07:27:33 +00:00
|
|
|
let convoEntry = document.createElement('li')
|
|
|
|
let connectStatus = document.createElement('span')
|
2019-08-18 05:27:33 +00:00
|
|
|
connectStatus.classList.add("connectStatus")
|
|
|
|
if (firstConvoLoad){
|
|
|
|
connectStatus.innerText = " ⌛"
|
|
|
|
}
|
|
|
|
else{
|
2019-08-17 07:27:33 +00:00
|
|
|
connectStatus.innerText = " X"
|
|
|
|
connectStatus.style.color = "red"
|
|
|
|
console.log(direct_connections)
|
|
|
|
if (direct_connections.hasOwnProperty(friend)){
|
|
|
|
connectStatus.innerText = " ✅"
|
|
|
|
connectStatus.style.color = "green"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-18 18:46:48 +00:00
|
|
|
convoEntry.classList.add('convoEntry')
|
2019-06-20 07:59:32 +00:00
|
|
|
convoEntry.setAttribute('data-pubkey', friend)
|
|
|
|
convoEntry.innerText = friendList[friend]
|
2019-08-17 07:27:33 +00:00
|
|
|
convoEntry.appendChild(connectStatus)
|
2019-05-18 18:46:48 +00:00
|
|
|
convoListElement.append(convoEntry)
|
2019-08-17 07:27:33 +00:00
|
|
|
firstConvoLoad = false
|
2019-05-18 18:46:48 +00:00
|
|
|
}
|
2019-08-17 07:27:33 +00:00
|
|
|
setTimeout(function(){createConvoList()}, 3000)
|
2019-05-18 18:46:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fetch('/friends/list', {
|
|
|
|
headers: {
|
|
|
|
"token": webpass
|
|
|
|
}})
|
|
|
|
.then((resp) => resp.json()) // Transform the data into json
|
|
|
|
.then(function(resp) {
|
|
|
|
var keys = []
|
|
|
|
for(var k in resp) keys.push(k)
|
|
|
|
for (var i = 0; i < keys.length; i++){
|
2019-06-20 07:59:32 +00:00
|
|
|
friendList[keys[i]] = resp[keys[i]]['name']
|
2019-08-16 22:40:17 +00:00
|
|
|
// Create a connection to each peer
|
|
|
|
createConnection(keys[i])
|
2019-05-18 18:46:48 +00:00
|
|
|
}
|
|
|
|
createConvoList()
|
2019-07-27 21:56:06 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
// Correct conversation list height
|
|
|
|
function correctConvoList(){
|
|
|
|
margin = 50
|
|
|
|
els = document.getElementsByClassName('convoListContainer')
|
|
|
|
for (x = 0; x < els.length; x++){
|
|
|
|
els[x].style.height = window.innerHeight - (2 * margin) + 'px'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
setInterval(function(){correctConvoList()}, 30)
|