forked from cory/tildefriends
		
	Trying to do mentions and refs betters. Questionable success.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4016 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
		| @@ -126,7 +126,7 @@ class TfMessageElement extends LitElement { | ||||
|  | ||||
| 	render_mention(mention) { | ||||
| 		if (!mention?.link || typeof(mention.link) != 'string') { | ||||
| 			return html`<pre>${JSON.stringify(mention)}</pre>`; | ||||
| 			return html` <pre>${JSON.stringify(mention)}</pre>`; | ||||
| 		} else if (mention?.link?.startsWith('&') && | ||||
| 			mention?.type?.startsWith('image/')) { | ||||
| 			return html` | ||||
| @@ -141,13 +141,15 @@ class TfMessageElement extends LitElement { | ||||
| 			`; | ||||
| 		} else if (mention.link?.startsWith('&') && | ||||
| 			mention?.type === 'application/tildefriends') { | ||||
| 			return html`<a href=${`/${mention.link}/`}>😎 ${mention.name}</a>`; | ||||
| 			return html` <a href=${`/${mention.link}/`}>😎 ${mention.name}</a>`; | ||||
| 		} else if (mention.link?.startsWith('%') || mention.link?.startsWith('@')) { | ||||
| 			return html` <a href=${'#' + encodeURIComponent(mention.link)}>${mention.name}</a>`; | ||||
| 		} else if (mention.link?.startsWith('#')) { | ||||
| 			return html` <a href=${'#q=' + encodeURIComponent(mention.link)}>${mention.link}</a>`; | ||||
| 		} else if (Object.keys(mention).length == 2 && mention.link && mention.name) { | ||||
| 			return html` <a href=${`/${mention.link}/view`}>${mention.name}</a>`; | ||||
| 		} else { | ||||
| 			return html`<pre style="white-space: pre-wrap">${JSON.stringify(mention, null, 2)}</pre>`; | ||||
| 			return html` <pre style="white-space: pre-wrap">${JSON.stringify(mention, null, 2)}</pre>`; | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
|   | ||||
| @@ -26,17 +26,24 @@ class TfTabNewsFeedElement extends LitElement { | ||||
|  | ||||
| 	async fetch_messages() { | ||||
| 		if (this.hash.startsWith('#@')) { | ||||
| 			return await tfrpc.rpc.query( | ||||
| 			let r = await tfrpc.rpc.query( | ||||
| 				` | ||||
| 					WITH mine AS (SELECT messages.* | ||||
| 						FROM messages | ||||
| 						WHERE messages.author = ? | ||||
| 						ORDER BY sequence DESC | ||||
| 						LIMIT 20) | ||||
| 					SELECT messages.* | ||||
| 					FROM messages | ||||
| 					WHERE messages.author = ? | ||||
| 					ORDER BY sequence DESC | ||||
| 					LIMIT 20 | ||||
| 						FROM mine | ||||
| 						JOIN messages_refs ON mine.id = messages_refs.ref | ||||
| 						JOIN messages ON messages_refs.message = messages.id | ||||
| 					UNION | ||||
| 					SELECT * FROM mine | ||||
| 				`, | ||||
| 				[ | ||||
| 					this.hash.substring(1), | ||||
| 				]); | ||||
| 			return r; | ||||
| 		} else if (this.hash.startsWith('#%')) { | ||||
| 			return await tfrpc.rpc.query( | ||||
| 				` | ||||
| @@ -55,11 +62,17 @@ class TfTabNewsFeedElement extends LitElement { | ||||
| 		} else { | ||||
| 			return await tfrpc.rpc.query( | ||||
| 				` | ||||
| 					SELECT messages.* | ||||
| 					WITH news AS (SELECT messages.* | ||||
| 					FROM messages | ||||
| 					JOIN json_each(?) AS following ON messages.author = following.value | ||||
| 					WHERE messages.timestamp > ? | ||||
| 					ORDER BY messages.timestamp DESC | ||||
| 					ORDER BY messages.timestamp DESC) | ||||
| 					SELECT messages.* | ||||
| 						FROM news | ||||
| 						JOIN messages_refs ON news.id = messages_refs.ref | ||||
| 						JOIN messages ON messages_refs.message = messages.id | ||||
| 					UNION | ||||
| 					SELECT * FROM news | ||||
| 				`, | ||||
| 				[ | ||||
| 					JSON.stringify(this.following), | ||||
| @@ -79,6 +92,8 @@ class TfTabNewsFeedElement extends LitElement { | ||||
| 			this._messages_following = this.following; | ||||
| 			this.fetch_messages().then(function(messages) { | ||||
| 				self.messages = messages; | ||||
| 			}).catch(function(error) { | ||||
| 				alert(JSON.stringify(error, null, 2)); | ||||
| 			}); | ||||
| 		} | ||||
| 		return html`<tf-news id="news" whoami=${this.whoami} .users=${this.users} .messages=${this.messages} .following=${this.following}></tf-news>`; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user