Skip to content

Commit 39896b7

Browse files
committed
improve "delete all but own feed" (but it's WIP)
1 parent a32af3a commit 39896b7

6 files changed

Lines changed: 47 additions & 15 deletions

File tree

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ function load_post_item(p) { // { 'key', 'from', 'when', 'body', 'to' (if group
300300
}
301301

302302
function load_chat(nm) {
303+
console.log("load_chat() for ", nm);
303304
var ch, pl, e;
304305
ch = tremola.chats[nm]
305306
if (ch.timeline == null)
@@ -492,6 +493,7 @@ function new_conversation() {
492493
}
493494

494495
function getUnreadCnt(nm) {
496+
console.log("XX", nm);
495497
var ch = tremola.chats[nm];
496498
return Object.keys(ch.posts).length - ch.lastRead;
497499
}

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,11 @@ function load_contact_list() {
3535
document.getElementById("lst:contacts-trustLevelZero").innerHTML = '';
3636
document.getElementById("lst:contacts-trustLevelOne").innerHTML = '';
3737
document.getElementById("lst:contacts-trustLevelTwo").innerHTML = '';
38-
for (var id in tremola.contacts)
38+
for (var id in tremola.contacts) {
39+
console.log("contacts", id);
3940
if (!tremola.contacts[id].forgotten)
4041
load_contact_item([id, tremola.contacts[id]]);
42+
}
4143
if (!tremola.settings.hide_forgotten_contacts)
4244
for (var id in tremola.contacts) {
4345
var c = tremola.contacts[id]
@@ -57,7 +59,7 @@ function load_contact_item(c) { // [ id, { "alias": "thealias", "initial": "T",
5759
c[1]["color"] = colors[Math.floor(colors.length * Math.random())];
5860
persist();
5961
}
60-
console.log("load_c_i", JSON.stringify(c[1]))
62+
// console.log("load_c_i", JSON.stringify(c[1]))
6163
bg = c[1].forgotten ? ' gray' : ' light';
6264
row = "<button class=contact_picture style='margin-right: 0.75em; background: " + c[1].color + ";'>" + c[1].initial + "</button>";
6365
row += "<button class='chat_item_button" + bg + "' style='overflow: hidden; width: calc(100% - 4em);' onclick='show_contact_details(\"" + c[0] + "\");'>";
@@ -370,8 +372,15 @@ function deleteContact(contactID) {
370372
//convert the contactID to scuttlebutt format
371373
contactID = encodeScuttlebuttId(contactID);
372374
//remove the contact from the contacts list
373-
delete tremola.contacts[contactID];
374-
persist();
375+
if (tremola == undefined)
376+
tremola = {};
377+
if (!Object.hasOwn(tremola, 'contacts'))
378+
tremola.contacts = {};
379+
if (contactID in tremola.contacts) {
380+
console.log("going to delete", contactID, "in", tremola.contacts);
381+
delete tremola.contacts[contactID];
382+
persist();
383+
}
375384
closeOverlay();
376385
load_contact_list();
377386
launch_snackbar("Contact deleted successfully");

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,13 @@ function settings_reset_ui() {
159159
}
160160

161161
function settings_clear_other_feeds() {
162-
backend("wipe:others")
163-
closeOverlay()
164-
settings_reset_ui()
165-
162+
closeOverlay();
163+
resetTremola();
164+
setScenario('chats');
165+
menu_redraw();
166+
launch_snackbar("reloading all feeds");
167+
backend("wipe:others");
168+
backend("reset");
166169
}
167170

168171
// eof

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

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -631,12 +631,20 @@ function b2f_new_event(e) { // incoming SSB log event: we get map with three ent
631631
if (!(ch.timeline instanceof Timeline))
632632
ch.timeline = Timeline.fromJSON(ch.timeline)
633633

634+
var ESID = encodeScuttlebuttId(a[2]);
635+
if (!(ESID in tremola.contacts)) {
636+
var shortID = id2b32(ESID);
637+
console.log("XX", a[2], ESID, shortID)
638+
tremola.contacts[ESID] = {
639+
"alias": shortID, "initial": shortID.substring(0, 1).toUpperCase(),
640+
"color": colors[Math.floor(colors.length * Math.random())],
641+
"iam": "", "forgotten": false
642+
}
643+
}
634644
// console.log("new post 1 ", ch)
635645
if (!(e.header.ref in ch.posts)) { // new post
636-
var a = e.confid;
637-
638646
//get alias from fid
639-
var alias = tremola.contacts[encodeScuttlebuttId(a[2])].alias;
647+
var alias = tremola.contacts[ESID].alias;
640648
var p = {
641649
"key": e.header.ref, "from": e.header.fid, "body": "Set contact: " + alias + "'s trust level to " + a[3],
642650
"when": a[4] * 1000, "prev": a[1]
@@ -655,6 +663,8 @@ function b2f_new_event(e) { // incoming SSB log event: we get map with three ent
655663
}
656664
// if (curr_scenario == "chats") // the updated conversation could bubble up
657665
load_chat_list();
666+
load_contact_list();
667+
reloadChatTrustLevels();
658668
}
659669
if (a[0] == 'TAV')
660670
rcpts = a[5];
@@ -744,10 +754,12 @@ function b2f_new_contact(fid, trustLevel="untrusted", alias="") {
744754
if (alias == "") {
745755
alias = id2b32(fid);
746756
}
747-
tremola.contacts[fid] = {
748-
"alias": alias, "initial": alias.substring(0, 1).toUpperCase(),
749-
"color": colors[Math.floor(colors.length * Math.random())],
750-
"iam": "", "forgotten": false, "trusted": trusted
757+
if (!(fid in tremola.contacts)) {
758+
tremola.contacts[fid] = {
759+
"alias": alias, "initial": alias.substring(0, 1).toUpperCase(),
760+
"color": colors[Math.floor(colors.length * Math.random())],
761+
"iam": "", "forgotten": false, "trusted": trusted
762+
};
751763
};
752764
backend("contacts:checkDeleted " + decodeScuttlebuttId(fid));
753765
console.log(tremola.contacts[fid]);

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@ class WebAppInterface(val act: MainActivity, val webView: WebView) {
117117
}
118118
"restream" -> {
119119
eval("restream = true")
120+
for (fid in act.tinyRepo.listFeeds()) {
121+
Log.d("wai", "recreating contact ${fid.toHex()}")
122+
if (!fid.contentEquals(act.idStore.identity.verifyKey))
123+
eval("b2f_new_contact(\"@${fid.toBase64()}.ed25519\", \"untrusted\")")
124+
}
120125
for (fid in act.tinyRepo.listFeeds()) {
121126
Log.d("wai", "restreaming ${fid.toHex()}")
122127
var i = 1

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ class Repo(val context: MainActivity) {
122122
// Check if the replica was found
123123
if (replicaIndex != -1) {
124124
replicas.removeAt(replicaIndex)
125+
delete_feed(fid)
125126
Log.d("repo", "Replica with fid ${fid.toHex()} deleted.")
126127
return true
127128
} else {

0 commit comments

Comments
 (0)