Skip to content

Commit

Permalink
enable private chats (and the "for my eyes only" channel)
Browse files Browse the repository at this point in the history
  • Loading branch information
tschudin committed Aug 1, 2024
1 parent b25be12 commit da1a7e8
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 60 deletions.
2 changes: 1 addition & 1 deletion android/tinySSB/app/src/main/assets/web/games/games.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

function load_game_list() {
document.getElementById("lst:games").innerHTML = '';
load_game_item('Battelship (dpi24.06)', 'games/dpi24-06-battelship/battleship.svg',
load_game_item('Battleship (dpi24.06)', 'games/dpi24-06-battelship/battleship.svg',
'text text text h aghjwd gldfhjs hlgsf hgljksf hgls fdhglf sdhgl hfgskj hls dfhgjl shgjkls hgl sfdhgjk sdfjklg hljs hfgl dfjlsfs');
load_game_item('Snake (dpi24.07)', 'games/dpi24-07-snake/snake.png',
'text text text h aghjwd gldfhjs hlgsf hgljksf hgls fdhglf sdhgl hfgskj hls dfhgjl shgjkls hgl sfdhgjk sdfjklg hljs hfgl dfjlsfs');
Expand Down
4 changes: 2 additions & 2 deletions android/tinySSB/app/src/main/assets/web/tremola.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<div id="div:qr" style="align: left;"><button id='btn:qr' class="flat" onclick="showQR();" style="background-color: transparent;"><font size=+2><strong>&nbsp;&#x2680;&nbsp;</strong></font></button></div>
<div id="div:back" style="display: none; padding-right: 10px;"><button id='back' class="flat buttontext" style="background-image: url('img/back.svg'); background-color: transparent; height: 25px; width: 25px; margin-left: 5px; margin-top: 2px;" onclick="onBackPressed();">&nbsp;<!--font size=+2><strong>&nbsp;&#x276E;&nbsp;</strong></font --></button></div>
<div id='tremolaTitle' align=center style="padding-top: 2pt; width: 100%;font-family: Helvetica;font-weight: 900;"><font size=+2 color=#e85132>t i n y S S B<!-- &#x26F0; --></font></div>
<div id='conversationTitle' style="display: none; padding-left: 5px; padding-right: 5px; padding-top: 2px; color: #e85132; font-size: small; overflow: hidden; width: 100%;">ABC</div>
<div id='conversationTitle' style="display: none; padding-left: 5px; padding-right: 5px; padding-top: 2px; color: #e85132; font-size: small; overflow: hidden; width: 100%;">List of Chat Channels</div>
<button id='btn:syncStat' onclick='menu_connection()' style='padding: 0px;border: 0px;'><div id='progressBars' style="position: relative; width: 24px; height: 18px; background: gray;">
<div id='progBarAhead' style="position: absolute; top: 0px; left: 0px; height: 6px; width: 50%; background: #7fd9eb;"></div>
<div id='progBarMissing' style="position: absolute; top: 6px; left: 0px; height: 6px; width: 100%; background: #2ecc71;"></div>
Expand Down Expand Up @@ -82,7 +82,7 @@

<div id='the:connex' style="display: none; margin: 5pt;"></div>

<div id='lst:members' style="display: none; margin: 3px;">
<div id='lst:members' style="height: 100%; overflow-y: scroll; overflow-x: hidden; display: none; margin: 3px;">
<div style="margin-top: 10pt;"><label><input type="checkbox" id="toggleSwitches1" style="margin-right: 10pt;">
<div class="contact_item_button light" style="display: inline-block;padding: 5pt;">Choice1<br>more text</div></label>
</div>
Expand Down
96 changes: 69 additions & 27 deletions android/tinySSB/app/src/main/assets/web/tremola.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function menu_new_conversation() {
document.getElementById("tremolaTitle").style.display = 'none';
var c = document.getElementById("conversationTitle");
c.style.display = null;
c.innerHTML = "<font size=+1><strong>Create New Conversation</strong></font><br>Select up to 7 members";
c.innerHTML = "<font size=+1><strong>Create Private Channel</strong></font><br>Select up to 7 members";
document.getElementById('plus').style.display = 'none';
closeOverlay();
}
Expand Down Expand Up @@ -122,8 +122,10 @@ function edit_confirmed() {
var ch = tremola.chats[curr_chat];
ch.alias = val;
persist();
load_chat_title(ch); // also have to update entry in chats
menu_redraw();
// load_chat_title(ch); // also have to update entry in chats
load_chat_list() // regenerate list for when we come back from the posts
load_chat(curr_chat)
// menu_redraw();
} else if (edit_target == 'new_contact_alias' || edit_target == 'trust_wifi_peer') {
document.getElementById('contact_id').value = '';
if (val == '')
Expand All @@ -135,13 +137,10 @@ function edit_confirmed() {
};
var recps = [myId, new_contact_id];
var nm = recps2nm(recps);
// TODO reactivate when encrypted chats are implemented
/*
tremola.chats[nm] = {
"alias": "Chat w/ " + val, "posts": {}, "members": recps,
"touched": Date.now(), "lastRead": 0, "timeline": new Timeline()
};
*/
persist();
backend("add:contact " + new_contact_id + " " + btoa(val))
menu_redraw();
Expand Down Expand Up @@ -508,13 +507,20 @@ function load_chat_title(ch) {
}

function load_chat_list() {
var meOnly = recps2nm([myId])
// console.log('meOnly', meOnly)
document.getElementById('lst:chats').innerHTML = '';
// load_chat_item(meOnly) TODO reactivate when encrypted chats are implemented
load_chat_item("ALL")
var meOnly = recps2nm([myId])
if (!(meOnly in tremola.chats)) {
tremola.chats[meOnly] = {
"alias": "--- local notes (for my eyes only)", "posts": {}, "forgotten": false,
"members": [myId], "touched": Date.now(), "lastRead": 0,
"timeline": new Timeline()
};
}
load_chat_item(meOnly)
var lop = [];
for (var p in tremola.chats) {
if (p != meOnly && !tremola.chats[p]['forgotten'])
if (p != "ALL" && p != meOnly && !tremola.chats[p]['forgotten'])
lop.push(p)
}
lop.sort(function (a, b) {
Expand Down Expand Up @@ -770,7 +776,7 @@ function new_conversation() {
var nm = recps2nm(recps);
if (!(nm in tremola.chats)) {
tremola.chats[nm] = {
"alias": "Unnamed conversation", "posts": {},
"alias": "Private", "posts": {},
"members": recps, "touched": Date.now(), "timeline": new Timeline()
};
persist();
Expand Down Expand Up @@ -898,7 +904,7 @@ function recps2display(rcps) {
var lst = rcps.map(function (fid) {
return fid2display(fid)
});
return '[' + lst.join(', ') + ']';
return '🔒 [' + lst.join(', ') + ']';
}

function fid2display(fid) {
Expand Down Expand Up @@ -998,16 +1004,13 @@ function resetTremola() { // wipes browser-side content
"settings": {},
"board": {}
}
var n = recps2nm([myId])

//TODO reactivate when encrypted chats are implemented
/*
var n = recps2nm([myId])
tremola.chats[n] = {
"alias": "local notes (for my eyes only)", "posts": {}, "forgotten": false,
"alias": "Local notes (for my eyes only)", "posts": {}, "forgotten": false,
"members": [myId], "touched": Date.now(), "lastRead": 0,
"timeline": new Timeline()
};
*/

tremola.chats["ALL"] = {
"alias": "Public channel", "posts": {},
Expand Down Expand Up @@ -1192,9 +1195,11 @@ function b2f_new_incomplete_event(e) {
*/
function b2f_new_event(e) { // incoming SSB log event: we get map with three entries
// console.log('hdr', JSON.stringify(e.header))
console.log('pub', JSON.stringify(e.public))
// console.log('cfd', JSON.stringify(e.confid))
console.log("New Frontend Event: " + JSON.stringify(e.header))
if (e.public)
console.log('pub', JSON.stringify(e.public))
if (e.confid)
console.log('cfd', JSON.stringify(e.confid))

//add
if (!(e.header.fid in tremola.contacts)) {
Expand Down Expand Up @@ -1227,11 +1232,6 @@ function b2f_new_event(e) { // incoming SSB log event: we get map with three ent
console.log("new post 1 ", ch)
if (!(e.header.ref in ch.posts)) { // new post
var a = e.public;
// var d = new Date(e.header.tst);
// d = d.toDateString() + ' ' + d.toTimeString().substring(0,5);
// var txt = null;
// if (a[1] != null)
// txt = a[1];
var p = {
"key": e.header.ref, "from": e.header.fid, "body": a[1],
"voice": a[2], "when": a[3] * 1000
Expand Down Expand Up @@ -1269,7 +1269,6 @@ function b2f_new_event(e) { // incoming SSB log event: we get map with three ent
// update names in connected devices menu
for (var l in localPeers) {
if (localPeers[l].alias == old_alias) {

localPeers[l].alias = contact.alias
refresh_connection_entry(l)
}
Expand All @@ -1280,6 +1279,49 @@ function b2f_new_event(e) { // incoming SSB log event: we get map with three ent
persist();
must_redraw = true;
}
if (e.confid) {
if (e.confid[0] == 'TAV') { // text and voice
console.log("new priv post 0 ", tremola)
var conv_name = recps2nm(e.confid[4]);
if (!(conv_name in tremola.chats)) { // create new conversation if needed
console.log("xx")
tremola.chats[conv_name] = {
"alias": "🔒 " + recps2display(e.confid[4]), "posts": {},
"members": e.confid[4], "touched": Date.now(), "lastRead": 0,
"timeline": new Timeline()
};
load_chat_list()
}
console.log("new priv post 1")
var ch = tremola.chats[conv_name];
if (ch.timeline == null)
ch["timeline"] = new Timeline();
console.log("new priv post 1 ", ch)
if (!(e.header.ref in ch.posts)) { // new post
var a = e.confid;
var p = {
"key": e.header.ref, "from": e.header.fid, "body": a[1],
"voice": a[2], "when": a[3] * 1000
};
console.log("new priv post 2 ", p)
console.log("time: ", a[3])
ch["posts"][e.header.ref] = p;
if (ch["touched"] < e.header.tst)
ch["touched"] = e.header.tst
if (curr_scenario == "posts" && curr_chat == conv_name) {
load_chat(conv_name); // reload all messages (not very efficient ...)
ch["lastRead"] = Date.now();
}
set_chats_badge(conv_name)
} else {
console.log("known already?")
}
// if (curr_scenario == "chats") // the updated conversation could bubble up
load_chat_list();
}
persist();
must_redraw = true;
}
}

// backend callback method when calling backend("settings:get")
Expand Down Expand Up @@ -1351,8 +1393,8 @@ function b2f_initialize(id, settings) {
load_game_list()
load_contact_list()

load_kanban_list()
dpi_load_event_list(tremola)
// load_kanban_list()
// dpi_load_event_list() // problem with access to tremola object

closeOverlay();
setScenario('chats');
Expand Down
22 changes: 15 additions & 7 deletions android/tinySSB/app/src/main/assets/web/tremola_ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
var overlayIsActive = false;

var display_or_not = [
'div:qr', 'div:back', 'core',
'div:qr', 'div:back', 'core', 'plus',
'lst:chats', 'lst:prod', 'lst:games', 'lst:contacts',
'lst:members', 'the:connex',
'div:posts', 'lst:kanban', 'div:board',
'lst:scheduling', 'div:event',
'div:footer', 'div:textarea', 'div:confirm-members', 'plus', 'div:settings'
'div:footer', 'div:textarea', 'div:confirm-members', 'div:settings'
];

var prev_scenario = 'chats';
var curr_scenario = 'chats';

var scenarioDisplay = {
'chats': ['div:qr', 'core', 'lst:chats', 'div:footer'], // 'plus' TODO reactivate when encrypted chats are implemented
'chats': ['div:qr', 'core', 'lst:chats', 'div:footer', 'plus'],
'contacts': ['div:qr', 'core', 'lst:contacts', 'div:footer', 'plus'],
'posts': ['div:back', 'core', 'div:posts', 'div:textarea'],
'connex': ['div:qr', 'core', 'the:connex', 'div:footer', 'plus'],
Expand All @@ -32,7 +32,7 @@ var scenarioDisplay = {
}

var scenarioMenu = {
'chats': [// ['Connected Devices', 'menu_connection'], // '['New conversation', 'menu_new_conversation'],' TODO reactivate when encrypted chats are implemented
'chats': [// ['New Channel', 'menu_new_conversation'],
['Settings', 'menu_settings'],
['About', 'menu_about']],
'productivity': [// ['Connected Devices', 'menu_connection'],
Expand Down Expand Up @@ -62,7 +62,7 @@ var scenarioMenu = {

'settings': [],

'kanban': [['New Kanban board', 'menu_new_board'],
'kanban': [// ['New Kanban board', 'menu_new_board'], // no redundant functionality
['Invitations', 'menu_board_invitations'],
// ['Connected Devices', 'menu_connection'],
['Settings', 'menu_settings'],
Expand Down Expand Up @@ -108,7 +108,7 @@ function onBackPressed() {
else if (curr_scenario == 'board')
setScenario('kanban')
else if (curr_scenario == 'event')
setScenario('scheduling')
setScenario('scheduling')
else
setScenario('chats')
} else {
Expand Down Expand Up @@ -150,7 +150,7 @@ function setScenario(s) {
if (s == "posts" || s == "settings" || s == "board" || s == "event") {
document.getElementById('tremolaTitle').style.display = 'none';
document.getElementById('conversationTitle').style.display = null;
// document.getElementById('plus').style.display = 'none';
document.getElementById('plus').style.display = 'none';
} else {
document.getElementById('tremolaTitle').style.display = null;
// if (s == "connex") { /* document.getElementById('plus').style.display = 'none'; */}
Expand All @@ -166,6 +166,14 @@ function setScenario(s) {
cl.toggle('active', true);
cl.toggle('passive', false);
}
if (s == 'chats') {
document.getElementById('tremolaTitle').style.display = null;
document.getElementById('conversationTitle').style.display = 'none';
/*
c.style.display = null;
c.innerHTML = "<font size=+1><strong>List of Chat Channels</strong></font><br>Pick or create a channel";
*/
}
if (s == 'board')
document.getElementById('core').style.height = 'calc(100% - 60px)';
else
Expand Down
Loading

0 comments on commit da1a7e8

Please sign in to comment.