Skip to content

Commit 1617d34

Browse files
committed
Fix minor issues
Fixing Issue with alias when scanning contact Making error message more accurate when a contact at trust level 2 is being set to trust level 2
1 parent d5a84fc commit 1617d34

6 files changed

Lines changed: 25 additions & 18 deletions

File tree

android/tinySSB/app/src/main/assets/web/prod/contacts.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,11 @@ function show_contact_details(id) {
194194

195195
// Example condition for error
196196
if (sliderValue == 2) {
197+
//check if current trust level is 2
198+
if (c['trusted'] == 2) {
199+
errorMessage.textContent = "Error: Contact's trust level is already 2.";
200+
return;
201+
}
197202
errorMessage.textContent = "Error: To set a contact's trust level to 2, you must scan their QR Code.";
198203
} else {
199204
errorMessage.textContent = ''; // Clear any previous errors

android/tinySSB/app/src/main/assets/web/tremola.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,22 +69,24 @@ function edit_confirmed() {
6969
load_chat(curr_chat)
7070
// menu_redraw();
7171
} else if (edit_target == 'new_contact_alias' || edit_target == 'trust_wifi_peer') {
72+
backend("add:contact " + new_contact_id + " " + btoa(val) + " T");
7273
document.getElementById('contact_id').value = '';
7374
if (val == '')
7475
val = id2b32(new_contact_id);
76+
console.log("new contact alias: " + val)
7577
tremola.contacts[new_contact_id] = {
7678
"alias": val, "initial": val.substring(0, 1).toUpperCase(),
7779
"color": colors[Math.floor(colors.length * Math.random())],
7880
"iam": "", "forgotten": false
7981
};
82+
console.log("new contact: " + JSON.stringify(tremola.contacts[new_contact_id]))
8083
var recps = [myId, new_contact_id];
8184
var nm = recps2nm(recps);
8285
tremola.chats[nm] = {
8386
"alias": "Chat w/ " + val, "posts": {}, "members": recps,
8487
"touched": Date.now(), "lastRead": 0, "timeline": new Timeline()
8588
};
8689
persist();
87-
backend("add:contact " + new_contact_id + " " + btoa(val))
8890
menu_redraw();
8991
} else if (edit_target == 'new_invite_target') {
9092
backend("invite:redeem " + val)
@@ -382,7 +384,7 @@ function resetTremola() { // wipes browser-side content
382384
"members": ["ALL"], "touched": Date.now(), "lastRead": 0,
383385
"timeline": new Timeline()
384386
};
385-
tremola.contacts[myId] = {"alias": "me", "initial": "M", "color": "#bd7578", "iam": "", "forgotten": false};
387+
tremola.contacts[myId] = {"alias": "me", "initial": "M", "color": "#bd7578", "iam": "", "forgotten": false, "trusted": 2};
386388
persist();
387389
}
388390

@@ -733,15 +735,17 @@ function b2f_get_settings(settings) {
733735
tremola.settings = settings
734736
}
735737

736-
function b2f_new_contact(fid, trustLevel="untrusted") {
738+
function b2f_new_contact(fid, trustLevel="untrusted", alias="") {
737739
console.log(trustLevel);
738740
let trusted = 0;
739741
if (trustLevel == "trusted") {
740742
trusted = 2;
741743
}
742-
var id = id2b32(fid);
744+
if (alias == "") {
745+
alias = id2b32(fid);
746+
}
743747
tremola.contacts[fid] = {
744-
"alias": id, "initial": id.substring(0, 1).toUpperCase(),
748+
"alias": alias, "initial": alias.substring(0, 1).toUpperCase(),
745749
"color": colors[Math.floor(colors.length * Math.random())],
746750
"iam": "", "forgotten": false, "trusted": trusted
747751
};

android/tinySSB/app/src/main/assets/web/tremola_ui.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -448,8 +448,8 @@ function qr_scan_success(s) {
448448
tips = JSON.stringify(ch.timeline.get_tips())
449449
}
450450
backend("contacts:setTrust " + decodeScuttlebuttId(new_contact_id) + " 2" + " " + tips);
451-
} else {
452-
launch_snackbar("This contact already exists");
451+
} else if (tremola.contacts[new_contact_id].trusted == 2) {
452+
launch_snackbar("This contact already exists and is verified");
453453
}
454454
return;
455455
}
@@ -477,9 +477,6 @@ function qr_scan_confirmed() {
477477
// c = {alias: a, id: s};
478478
var i = (a + "?").substring(0, 1).toUpperCase()
479479
var c = {"alias": a, "initial": i, "color": colors[Math.floor(colors.length * Math.random())], "iam": "", "forgotten": false, "trusted": 2};
480-
tremola.contacts[s] = c;
481-
persist();
482-
backend("add:contact " + s + " " + btoa(a) + "T") //T for trusted
483480
load_contact_item([s, c]);
484481
closeOverlay();
485482
}

android/tinySSB/app/src/main/java/nz/scuttlebutt/tremolavossbol/WebAppInterface.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,11 +188,12 @@ class WebAppInterface(val act: MainActivity, val webView: WebView) {
188188
}
189189
"add:contact" -> {
190190
val contactID = args[1].substring(1,args[1].length-8)
191-
val isTrusted = args.getOrNull(2) != null
192-
Log.d("ADD", "$contactID $isTrusted")
193-
val keyHex = act.tinyGoset._add_key(Base64.decode(contactID, Base64.NO_WRAP), true)
191+
val alias = Base64.decode(args[2], Base64.NO_WRAP).decodeToString()
192+
val isTrusted = args.getOrNull(3) != null
193+
Log.d("add:contact", "contactID: $contactID, isTrusted: $isTrusted, alias: $alias")
194+
195+
val keyHex = act.tinyGoset._add_key(Base64.decode(contactID, Base64.NO_WRAP), true, alias)
194196
if (isTrusted) {
195-
Log.d("trustthismf", "trustthismf")
196197
trust_contact(keyHex, 2)
197198
}
198199
}

android/tinySSB/app/src/main/java/nz/scuttlebutt/tremolavossbol/tssb/GOset.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,11 +232,11 @@ class GOset(val context: MainActivity) {
232232
return true
233233
}
234234

235-
fun _add_key(key: ByteArray, trusted: Boolean = false): String {
235+
fun _add_key(key: ByteArray, trusted: Boolean = false, alias: String =""): String {
236236
if (!_include_key(key)) // adds key if necessary
237237
return ""
238238
//Set trusted
239-
context.tinyRepo.add_replica(key, trusted)
239+
context.tinyRepo.add_replica(key, trusted, alias)
240240

241241
keys.sortWith({a:ByteArray,b:ByteArray -> byteArrayCmp(a,b)})
242242
if (keys.size >= largest_claim_span) { // only rebroadcast if we are up to date

android/tinySSB/app/src/main/java/nz/scuttlebutt/tremolavossbol/tssb/Repo.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class Repo(val context: MainActivity) {
7676

7777
}
7878

79-
fun add_replica(fid: ByteArray, trusted: Boolean = false) {
79+
fun add_replica(fid: ByteArray, trusted: Boolean = false, alias: String = "") {
8080
if (replicas.any { it.fid.contentEquals(fid) })
8181
return
8282
val new_r = Replica(context, File(context.getDir(TINYSSB_DIR, MODE_PRIVATE), FEED_DIR), fid)
@@ -101,7 +101,7 @@ class Repo(val context: MainActivity) {
101101

102102
if(context.frontend_ready) // was: isWaiInitialized()
103103
if (trusted) {
104-
context.wai.eval("b2f_new_contact(\"@${fid.toBase64()}.ed25519\", \"trusted\")") // notify frontend
104+
context.wai.eval("b2f_new_contact(\"@${fid.toBase64()}.ed25519\", \"trusted\", \"$alias\")") // notify frontend
105105
} else {
106106
context.wai.eval("b2f_new_contact(\"@${fid.toBase64()}.ed25519\", \"untrusted\")") // notify frontend
107107
}

0 commit comments

Comments
 (0)