Add a button in the profile editor to ask the server to follow you. I'm hoping this helps replicating accounts that are otherwise difficult to discover.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4558 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
2023-10-20 14:37:24 +00:00
parent 6dae2f0749
commit 6db1a097aa
6 changed files with 188 additions and 15 deletions

View File

@ -1,4 +1,5 @@
{
"type": "tildefriends-app",
"emoji": "🐌"
"emoji": "🐌",
"previous": "&Vm+p2yc+lC+wd71VVNRmEGpaePRsnwyknk+qI9hphjQ=.sha256"
}

View File

@ -18,6 +18,12 @@ tfrpc.register(async function databaseSet(key, value) {
tfrpc.register(async function createIdentity() {
return ssb.createIdentity();
});
tfrpc.register(async function getServerIdentity() {
return ssb.getServerIdentity();
});
tfrpc.register(async function setServerFollowingMe(id, following) {
return ssb.setServerFollowingMe(id, following);
});
tfrpc.register(async function getIdentities() {
return ssb.getIdentities();
});

View File

@ -11,6 +11,7 @@ class TfProfileElement extends LitElement {
id: {type: String},
users: {type: Object},
size: {type: Number},
server_follows_me: {type: Boolean},
};
}
@ -24,6 +25,23 @@ class TfProfileElement extends LitElement {
this.id = null;
this.users = {};
this.size = 0;
this.server_follows_me = undefined;
}
async initial_load() {
this.server_follows_me = undefined;
let server_id = await tfrpc.rpc.getServerIdentity();
let followed = await tfrpc.rpc.query(`
SELECT json_extract(content, '$.following') AS following FROM messages
WHERE author = ? AND
json_extract(content, '$.type') = 'contact' AND
json_extract(content, '$.contact') = ? ORDER BY sequence DESC LIMIT 1
`, [server_id, this.whoami]);
let is_followed = false;
for (let row of followed) {
is_followed = row.following != 0;
}
this.server_follows_me = is_followed;
}
modify(change) {
@ -103,7 +121,23 @@ class TfProfileElement extends LitElement {
input.click();
}
async server_follow_me(follow) {
try {
await tfrpc.rpc.setServerFollowingMe(this.whoami, follow);
} catch (e) {
console.log(e);
}
try {
await this.initial_load();
} catch (e) {
console.log(e);
}
}
render() {
if (this.id == this.whoami && this.editing && this.server_follows_me === undefined) {
this.initial_load();
}
let self = this;
let profile = this.users[this.id] || {};
tfrpc.rpc.query(
@ -116,9 +150,16 @@ class TfProfileElement extends LitElement {
let block;
if (this.id === this.whoami) {
if (this.editing) {
let server_follow;
if (this.server_follows_me === true) {
server_follow = html`<input type="button" value="Server, Stop Following Me" @click=${() => this.server_follow_me(false)}></input>`;
} else if (this.server_follows_me === false) {
server_follow = html`<input type="button" value="Server, Follow Me" @click=${() => this.server_follow_me(true)}></input>`;
}
edit = html`
<input type="button" value="Save Profile" @click=${this.save_edits}></input>
<input type="button" value="Discard" @click=${this.discard_edits}></input>
${server_follow}
`;
} else {
edit = html`<input type="button" value="Edit Profile" @click=${this.edit}></input>`;