redlib-org / redlib

Private front-end for Reddit
GNU Affero General Public License v3.0
1.34k stars 90 forks source link

💡 Feature request: Stream comments #6

Closed sigaloid closed 8 months ago

sigaloid commented 10 months ago

Is your feature request related to a problem? Please describe.

We now use the OAuth endpoints which gives us a plethora of data to play with, including a wss url that pushes new comments

Describe the feature you would like to be implemented

A checkbox to enable "live mode" that will connect to this wss endpoint and proxy through the backend, updating the frontend with new comments.

Describe alternatives you've considered

N/A (polling won't work due to cache)

Additional context / screenshot

Sample of what it looks like:

───────────────────────────────────── TEXT message on 2023-12-28 18:50:48 ──────────────────────────────────────
{"type": "new_comment", "payload": {"author_icon_img": 
"https://styles.redditmedia.com/t5_wa4w7/styles/profileIcon_snoo502f8b1a-182f-443b-8724-c91fde40339b-headshot.pn
g?width=256&height=256&crop=256:256,smart&s=e76dae5dcaf32f54eea7c2a23b43f89c926f7ed1", "attribs": [], 
"subreddit_id": "t5_2qh1i", "comment_type": null, "link_id": "t3_18srrdp", "author_snoovatar_img": 
"https://i.redd.it/snoovatar/avatars/502f8b1a-182f-443b-8724-c91fde40339b.png", "rtjson": {"document": [{"c": 
[{"e": "text", "t": "I literally dated (and lived) with someone like this for years. He was a fucking 
self-centered nut job. Took me years to rebuild my self-esteem because he was \u201csuch an empath.\u201d"}], 
"e": "par"}]}, "author_fullname": "t2_36vu7538", "subreddit_name_prefixed": "r/AskReddit", "full_date": 
"2023-12-28T23:50:46+00:00", "parent_id36": "kfc4rg4", "collapsed_in_crowd_control": false, "score": 1, 
"parent_id": "t1_kfc4rg4", "author_is_default_icon": false, "body": "I literally dated (and lived) with someone 
like this for years. He was a fucking self-centered nut job. Took me years to rebuild my self-esteem because he 
was \u201csuch an empath.\u201d", "collapsed": false, "body_html": "<!-- SC_OFF --><div class=\"md\"><p>I 
literally dated (and lived) with someone like this for years. He was a fucking self-centered nut job. Took me 
years to rebuild my self-esteem because he was \u201csuch an empath.\u201d</p>\n</div><!-- SC_ON -->", 
"author_is_nsfw_icon": false, "total_comment_count": 15167, "associated_award": null, "subreddit": "AskReddit", 
"flair_position": "right", "_id36": "kfc98nr", "name": "t1_kfc98nr", "author": "defnotevilmorty", "created_utc":
1703807446, "context": "/r/AskReddit/comments/18srrdp/what_phrase_needs_to_die_immediately/kfc98nr/", 
"author_id": 250078359428, "distinguished": null}}
───────────────────────────────────── TEXT message on 2023-12-28 18:50:52 ──────────────────────────────────────
{"type": "remove_comment", "payload": {"subreddit_id": "t5_2qh1i", "name": "t1_kf9k19z", "link_id": 
"t3_18srrdp"}}
───────────────────────────────────── TEXT message on 2023-12-28 18:50:54 ──────────────────────────────────────
{"type": "new_comment", "payload": {"author_icon_img": 
"https://styles.redditmedia.com/t5_8z0sxa/styles/profileIcon_snoo-nftv2_bmZ0X2VpcDE1NToxMzdfZWI5NTlhNzE1ZGZmZmU2
ZjgyZjQ2MDU1MzM5ODJjNDg1OWNiMTRmZV8xMDg1MzczNQ_rare_bbbfefb5-3f01-45e3-93d3-663544934c85-headshot.png?width=256&
height=256&crop=256:256,smart&s=6a539539946567b0a681de61e916c50b82b3f54c", "attribs": [], "subreddit_id": 
"t5_2qh1i", "comment_type": null, "link_id": "t3_18srrdp", "author_snoovatar_img": 
"https://i.redd.it/snoovatar/avatars/nftv2_bmZ0X2VpcDE1NToxMzdfZWI5NTlhNzE1ZGZmZmU2ZjgyZjQ2MDU1MzM5ODJjNDg1OWNiM
TRmZV8xMDg1MzczNQ_rare_bbbfefb5-3f01-45e3-93d3-663544934c85.png", "rtjson": {"document": [{"c": [{"e": "text", 
"t": "Gas lighting, Nepo baby, juxtaposition, do better, sucks to suck,  unalived, houseless."}], "e": "par"}, 
{"c": [{"e": "text", "t": "Stfu"}], "e": "par"}]}, "author_fullname": "t2_gboziqla9", "subreddit_name_prefixed":
"r/AskReddit", "full_date": "2023-12-28T23:50:51+00:00", "collapsed_in_crowd_control": false, "score": 1, 
"author_is_default_icon": false, "body": "Gas lighting, Nepo baby, juxtaposition, do better, sucks to suck,  
unalived, houseless. \n\nStfu", "collapsed": false, "body_html": "<!-- SC_OFF --><div class=\"md\"><p>Gas 
lighting, Nepo baby, juxtaposition, do better, sucks to suck,  unalived, houseless. 
</p>\n\n<p>Stfu</p>\n</div><!-- SC_ON -->", "author_is_nsfw_icon": false, "total_comment_count": 15169, 
"associated_award": null, "subreddit": "AskReddit", "flair_position": "right", "_id36": "kfc996n", "name": 
"t1_kfc996n", "author": "Kevinfrombase", "created_utc": 1703807451, "context": 
"/r/AskReddit/comments/18srrdp/what_phrase_needs_to_die_immediately/kfc996n/", "author_id": 46054154890305, 
"distinguished": null}}
───────────────────────────────────── TEXT message on 2023-12-28 18:50:57 ──────────────────────────────────────
{"type": "new_comment", "payload": {"author_icon_img": 
"https://styles.redditmedia.com/t5_7svlns/styles/profileIcon_snoobb2ef345-b853-40f6-9da9-7d7535f6acce-headshot.p
ng?width=256&height=256&crop=256:256,smart&s=34387bf97c9865d50179324344229bb13ac42eed", "attribs": [], 
"subreddit_id": "t5_2qh1i", "comment_type": null, "link_id": "t3_18srrdp", "author_snoovatar_img": 
"https://i.redd.it/snoovatar/avatars/bb2ef345-b853-40f6-9da9-7d7535f6acce.png", "rtjson": {"document": [{"c": 
[{"e": "text", "t": "\u201cI\u2019m so skibidi\u201d \u201cw Rizz\u201d \u201conly in Ohio\u201d 
\u201cthat\u2019s so sigma\u201d bruh anything that has skibidi, rizz, Ohio, sigma"}], "e": "par"}]}, 
"author_fullname": "t2_vn3lm0rq", "subreddit_name_prefixed": "r/AskReddit", "full_date": 
"2023-12-28T23:50:55+00:00", "collapsed_in_crowd_control": false, "score": 1, "author_is_default_icon": false, 
"body": "\u201cI\u2019m so skibidi\u201d \u201cw Rizz\u201d \u201conly in Ohio\u201d \u201cthat\u2019s so 
sigma\u201d bruh anything that has skibidi, rizz, Ohio, sigma", "collapsed": false, "body_html": "<!-- SC_OFF 
--><div class=\"md\"><p>\u201cI\u2019m so skibidi\u201d \u201cw Rizz\u201d \u201conly in Ohio\u201d 
\u201cthat\u2019s so sigma\u201d bruh anything that has skibidi, rizz, Ohio, sigma</p>\n</div><!-- SC_ON -->", 
"author_is_nsfw_icon": false, "total_comment_count": 15170, "associated_award": null, "subreddit": "AskReddit", 
"flair_position": "right", "_id36": "kfc99he", "name": "t1_kfc99he", "author": "AAAUUUGGGGHHH", "created_utc": 
1703807455, "context": "/r/AskReddit/comments/18srrdp/what_phrase_needs_to_die_immediately/kfc99he/", 
"author_id": 2479572778598, "distinguished": null}}

Interestingly enough, I caught a live comment removal above.

sigaloid commented 10 months ago

This would require a lot of overhaul - notably, switching the entire web framework to something like Axum. :thinking:


image Sassy HTTP endpoint... :angry:

sigaloid commented 10 months ago

image :grin:

This is not nearly as impressive now that I realize the regular JSON API returns it... the code I wrote was the GQL client :thinking:

FireMasterK commented 10 months ago

This would require a lot of overhaul - notably, switching the entire web framework to something like Axum. 🤔

Why not just use something like https://crates.io/crates/hyper_tungstenite?

sigaloid commented 10 months ago

The current architecture converts everything to a Request<Body> from the hyper crate when building the router. We'd need to handle it a lot sooner in the router path, meaning a lot of changes. If we're going to do that, I would prefer we also move to a better stack - Axum is probably better-equipped to handle a full-stack app, rather than building and manually managing everything from routing, compression, caching, etc.

sigaloid commented 10 months ago

Did some tests and with tokio-tungstenite, I get incredibly small memory usage (1.2MB!) even with thousands of simultaneous WS connections to a variety of WS streams, getting new comments. :thinking:

sigaloid commented 8 months ago

Considering this out of scope (for now). I definitely don't think live-streaming and proxying these updates is within the scope of Redlib.