@@ -75,19 +75,34 @@ function load_contact_item(c) { // [ id, { "alias": "thealias", "initial": "T",
7575 document . getElementById ( 'lst:contacts-trustLevelTwo' ) . appendChild ( item ) ;
7676 }
7777}
78+
79+ function unforget_contact ( id ) {
80+ console . log ( "unforgetting contact " + id ) ;
81+ tremola . contacts [ id ] . forgotten = false ;
82+ persist ( ) ;
83+ load_contact_list ( ) ;
84+ closeOverlay ( ) ;
85+ }
86+
7887// reload trust levels of all contacts, parameter is a list of contact IDs and their trust levels
7988function reloadContactsTrustLevels ( contactsTrustLevelsJSON ) {
8089 const contactsTrustLevels = JSON . parse ( contactsTrustLevelsJSON ) ;
8190 for ( const contactId in contactsTrustLevels ) {
8291 const id = encodeScuttlebuttId ( contactId ) ;
8392 console . log ( tremola . contacts ) ;
84- //check if contact trust level is different from the one in the contacts list
85- if ( tremola . contacts [ id ] [ "trusted" ] != contactsTrustLevels [ contactId ] ) {
93+ //check if contact trust level is lower than the one in the contacts list
94+ if ( tremola . contacts [ id ] [ "trusted" ] < contactsTrustLevels [ contactId ] ) {
95+ //if contact is forgotten
96+ if ( tremola . contacts [ id ] . forgotten ) {
97+ // ask the user if they want to unforget the contact
98+ launch_toast ( "Unforget Contact" , "This contact is in your forgotten list, do you also want to unforget it?" , function ( ) { unforget_contact ( id ) ; } , closeOverlay ) ;
99+ }
86100 launch_snackbar ( "Updated trust level for " + tremola . contacts [ id ] . alias + " to " + contactsTrustLevels [ contactId ] ) ;
87101 }
88102 tremola . contacts [ id ] [ "trusted" ] = contactsTrustLevels [ contactId ] ;
89103 console . log ( "contactsTrustLevel: " + contactId + " " + contactsTrustLevels [ contactId ] ) ;
90104 }
105+ reloadChatTrustLevels ( ) ;
91106 persist ( ) ;
92107 load_contact_list ( ) ;
93108}
@@ -145,7 +160,33 @@ function encodeScuttlebuttId(hexString) {
145160 }
146161}
147162
163+ function deleteContactButton ( contactID ) {
164+ backend ( "contacts:delete " + decodeScuttlebuttId ( new_contact_id ) ) ;
165+ closeOverlay ( ) ;
166+ }
167+
168+ function getChatTrustLevel ( chat ) {
169+ if ( chat != "ALL" ) {
170+ let contacts = tremola . chats [ chat ] . members ;
171+ //get the minimum trust level of all contacts
172+ let trustLevel = 2 ;
173+ for ( var i = 0 ; i < contacts . length ; i ++ ) {
174+ let contact = tremola . contacts [ contacts [ i ] ] ;
175+ if ( contact . trusted < trustLevel ) {
176+ trustLevel = contact . trusted ;
177+ }
178+ }
179+ return trustLevel
180+ } else {
181+ return 0
182+ }
183+ }
184+
148185function show_contact_details ( id ) {
186+ //for each entry in tremola.chats
187+ for ( var chat in tremola . chats ) {
188+ console . log ( "chat: " + chat + "trust levell: " + getChatTrustLevel ( chat ) ) ;
189+ }
149190 if ( id == myId ) {
150191 document . getElementById ( 'old_contact_alias_hdr' ) . innerHTML = "Alias: (own name, visible to others)"
151192 } else {
@@ -161,27 +202,35 @@ function show_contact_details(id) {
161202 details += '<br><div>IAM-Alias: ' + ( c . iam != "" ? c . iam : "—" ) + '</div>\n' ;
162203 details += '<br><div>Shortname: ' + id2b32 ( id ) + '</div>\n' ;
163204 details += '<br><div style="word-break: break-all;">SSB identity: <tt>' + id + '</tt></div>\n' ;
164- details += '<br><div class=settings style="padding: 0px;"><div class=settingsText>Forget this contact</div><div style="float: right;"><label class="switch"><input id="hide_contact" type="checkbox" onchange="toggle_forget_contact(this);"><span class="slider round"></span></label></div></div>'
165-
166- // Add slider with colored gradient
167- details += '<br><div>Trust Level:</div>\n' ;
168- details += '<div style="display: flex; align-items: center;">' ;
169- details += '<input type="range" id="slider" min="0" max="2" step="1" value="' + c [ 'trusted' ] + '" style="flex: 1; margin-right: 10px; appearance: none; -webkit-appearance: none; background: linear-gradient(to right, red 0%, orange 50%, green 100%); height: 8px; border-radius: 5px;">' ;
170- details += '<button id="setButton" style="flex: 0;">Set</button>\n' ;
171- details += '</div>' ;
172-
173- // Add the numbers under the slider with precise positioning using percentage for better alignment
174- details += '<div style="position: relative; width: 100%; padding: 0;">' ;
175- details += '<span style="position: absolute; left: 0;">0</span>' ;
176- details += '<span style="position: absolute; left: 40%; transform: translateX(-40%);">1</span>' ;
177- details += '<span style="position: absolute; right: 20%;">2</span>' ;
178- details += '</div>' ;
205+ if ( id != myId )
206+ details += '<br><div class=settings style="padding: 0px;"><div class=settingsText>Forget this contact</div><div style="float: right;"><label class="switch"><input id="hide_contact" type="checkbox" onchange="toggle_forget_contact(this);"><span class="slider round"></span></label></div></div>'
207+
208+ if ( id != myId ) {
209+ // Add slider with colored gradient
210+ details += '<br><div>Trust Level:</div>\n' ;
211+ details += '<div style="display: flex; align-items: center;">' ;
212+ details += '<input type="range" id="slider" min="0" max="2" step="1" value="' + c [ 'trusted' ] + '" style="flex: 1; margin-right: 10px; appearance: none; -webkit-appearance: none; background: linear-gradient(to right, red 0%, orange 50%, green 100%); height: 8px; border-radius: 5px;">' ;
213+ details += '<button id="setButton" style="flex: 0;">Set</button>\n' ;
214+ details += '</div>' ;
215+
216+ // Add the numbers under the slider with precise positioning using percentage for better alignment
217+ details += '<div style="position: relative; width: 100%; padding: 0;">' ;
218+ details += '<span style="position: absolute; left: 0;">0</span>' ;
219+ details += '<span style="position: absolute; left: 40%; transform: translateX(-40%);">1</span>' ;
220+ details += '<span style="position: absolute; right: 20%;">2</span>' ;
221+ details += '</div>' ;
222+ }
179223
180224 // Add error message field to the details HTML
181225 details += '<br><div id="errorMessage" class="error" style="color: red;"></div>\n' ;
182226
227+ // Add button to delete contact if id is not myId
228+ if ( id != myId )
229+ details += '<br><button class="button" onclick="launch_toast(\'Delete Contact\', \'Are you sure you want to delete this contact?\', function() { deleteContactButton(\'' + decodeScuttlebuttId ( id ) + '\'); }, closeOverlay);">Delete Contact</button>' ;
230+
183231 document . getElementById ( 'old_contact_details' ) . innerHTML = details ;
184232 document . getElementById ( 'old_contact-overlay' ) . style . display = 'initial' ;
233+
185234 document . getElementById ( 'overlay-bg' ) . style . display = 'initial' ;
186235 document . getElementById ( 'hide_contact' ) . checked = c . forgotten ;
187236
@@ -220,7 +269,6 @@ function show_contact_details(id) {
220269 // Attach event listener to the button after it is added to the DOM
221270 document . getElementById ( "setButton" ) . addEventListener ( "click" , setSliderValue ) ;
222271
223- document . getElementById ( 'old_contact_alias' ) . focus ( ) ;
224272 overlayIsActive = true ;
225273}
226274
@@ -239,8 +287,36 @@ function changeTrustLevel(contactID, value) {
239287}
240288
241289function toggle_forget_contact ( e ) {
242- var c = tremola . contacts [ new_contact_id ] ;
243- c . forgotten = ! c . forgotten ;
290+ if ( e . checked ) {
291+ //get the contrast's trust level
292+ let trustLevel = tremola . contacts [ new_contact_id ] [ "trusted" ] ;
293+ if ( trustLevel == 2 || trustLevel == 1 ) {
294+ var c = tremola . contacts [ new_contact_id ] ;
295+ c . forgotten = ! c . forgotten ;
296+ persist ( ) ;
297+ closeOverlay ( ) ;
298+ load_contact_list ( ) ;
299+ return ;
300+ } else if ( trustLevel == 0 ) {
301+ //send backend request to delete the contact's feed
302+ backend ( "contacts:delete " + decodeScuttlebuttId ( new_contact_id ) ) ;
303+ closeOverlay ( ) ;
304+ //reload the contact list
305+ load_contact_list ( ) ;
306+ }
307+ } else {
308+ var c = tremola . contacts [ new_contact_id ] ;
309+ c . forgotten = ! c . forgotten ;
310+ persist ( ) ;
311+ closeOverlay ( ) ;
312+ load_contact_list ( ) ;
313+ }
314+ }
315+
316+ //function to forget contact with id as paramter
317+ function forget_contact ( contact_id ) {
318+ var c = tremola . contacts [ encodeScuttlebuttId ( contact_id ) ] ;
319+ c . forgotten = true ;
244320 persist ( ) ;
245321 closeOverlay ( ) ;
246322 load_contact_list ( ) ;
@@ -290,4 +366,15 @@ function save_content_alias() {
290366 closeOverlay ( ) ;
291367}
292368
369+ function deleteContact ( contactID ) {
370+ //convert the contactID to scuttlebutt format
371+ contactID = encodeScuttlebuttId ( contactID ) ;
372+ //remove the contact from the contacts list
373+ delete tremola . contacts [ contactID ] ;
374+ persist ( ) ;
375+ closeOverlay ( ) ;
376+ load_contact_list ( ) ;
377+ launch_snackbar ( "Contact deleted successfully" ) ;
378+ }
379+
293380// --- eof
0 commit comments