Reworked some following math.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4601 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
		| @@ -212,9 +212,18 @@ class TfElement extends LitElement { | ||||
| 		let whoami = this.whoami; | ||||
| 		let tags = this.load_recent_tags(); | ||||
| 		let following = await tfrpc.rpc.following([whoami], 2); | ||||
| 		console.log(following); | ||||
| 		let users = {}; | ||||
| 		users = await this.fetch_about(following.sort(), users); | ||||
| 		this.following = following; | ||||
| 		for (let [id, v] of Object.entries(following)) { | ||||
| 			users[id] = { | ||||
| 				following: v.of, | ||||
| 				blocking: v.ob, | ||||
| 				followed: v.if, | ||||
| 				blocked: v.ib, | ||||
| 			}; | ||||
| 		} | ||||
| 		users = await this.fetch_about(Object.keys(following).sort(), users); | ||||
| 		this.following = Object.keys(following); | ||||
| 		this.users = users; | ||||
| 		await tags; | ||||
| 		console.log(`load finished ${whoami} => ${this.whoami}`); | ||||
|   | ||||
| @@ -12,6 +12,8 @@ class TfProfileElement extends LitElement { | ||||
| 			users: {type: Object}, | ||||
| 			size: {type: Number}, | ||||
| 			server_follows_me: {type: Boolean}, | ||||
| 			following: {type: Boolean}, | ||||
| 			blocking: {type: Boolean}, | ||||
| 		}; | ||||
| 	} | ||||
|  | ||||
| @@ -28,11 +30,31 @@ class TfProfileElement extends LitElement { | ||||
| 		this.server_follows_me = undefined; | ||||
| 	} | ||||
|  | ||||
| 	async load() { | ||||
| 		if (this.whoami !== this._follow_whoami) { | ||||
| 			this._follow_whoami = this.whoami; | ||||
| 			this.following = undefined; | ||||
| 			this.blocking = undefined; | ||||
|  | ||||
| 			let result = 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 | ||||
| 			`, [this.whoami, this.id]); | ||||
| 			console.log(result); | ||||
| 			this.following = result?.[0]?.following ?? false; | ||||
| 			console.log('FOLLOWING', this.whoami, this.id, this.following); | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	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 | ||||
| 			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 | ||||
| @@ -138,6 +160,7 @@ class TfProfileElement extends LitElement { | ||||
| 		if (this.id == this.whoami && this.editing && this.server_follows_me === undefined) { | ||||
| 			this.initial_load(); | ||||
| 		} | ||||
| 		this.load(); | ||||
| 		let self = this; | ||||
| 		let profile = this.users[this.id] || {}; | ||||
| 		tfrpc.rpc.query( | ||||
| @@ -166,16 +189,16 @@ class TfProfileElement extends LitElement { | ||||
| 			} | ||||
| 		} | ||||
| 		if (this.id !== this.whoami && | ||||
| 			this.users[this.whoami]?.following) { | ||||
| 			this.following !== undefined) { | ||||
| 			follow = | ||||
| 				this.users[this.whoami].following[this.id] ? | ||||
| 				this.following ? | ||||
| 				html`<input type="button" value="Unfollow" @click=${this.unfollow}></input>` : | ||||
| 				html`<input type="button" value="Follow" @click=${this.follow}></input>`; | ||||
| 		} | ||||
| 		if (this.id !== this.whoami && | ||||
| 			this.users[this.whoami]?.blocking) { | ||||
| 			this.blocking !== undefined) { | ||||
| 			block = | ||||
| 				this.users[this.whoami].blocking[this.id] ? | ||||
| 				this.blocking ? | ||||
| 				html`<input type="button" value="Unblock" @click=${this.unblock}></input>` : | ||||
| 				html`<input type="button" value="Block" @click=${this.block}></input>`; | ||||
| 		} | ||||
| @@ -208,10 +231,10 @@ class TfProfileElement extends LitElement { | ||||
| 				</div> | ||||
| 			</div> | ||||
| 			<div> | ||||
| 				Following ${Object.keys(profile.following || {}).length} identities. | ||||
| 				Followed by ${Object.values(self.users).filter(x => (x.following || {})[self.id]).length} identities. | ||||
| 				Blocking ${Object.keys(profile.blocking || {}).length} identities. | ||||
| 				Blocked by ${Object.values(self.users).filter(x => (x.blocking || {})[self.id]).length} identities. | ||||
| 				Following ${profile.following} identities. | ||||
| 				Followed by ${profile.followed} identities. | ||||
| 				Blocking ${profile.blocking} identities. | ||||
| 				Blocked by ${profile.blocked} identities. | ||||
| 			</div> | ||||
| 			<div> | ||||
| 				${edit} | ||||
|   | ||||
		Reference in New Issue
	
	Block a user