Add the ability to search for specific comments within posts.
Known issues:
- Just like on reddit, this does not work with comment sorting. The
sorting order is ignored during the search and changing the sorting
order after the search does not change anything. I do not think we
can fix this before reddit does, since in my understanding we rely
on them for the sorting. However we could implement a default
sorting method ourselves by taking the vector of comments returned
from the search and sorting it manually.
- The UI could be improved on mobile. On screens with a max width
inferior to 480 pixels, the comment search bar is displayed below
the comment sorting form. It would be great if we could make the
search bar have the same width as the whole comment sorting form
but I do not have the willpower to write any more css.
To know if the gate should be bypassed, we check if the link contains
the pasameter instead of checking if the link ends with it. This is
impostant, for example if we were to implement searching for comments
within a post. If we wanted to search for comments within a post that we
have bypassed the gate to view: the link will look like
https://libreddit-instance/r/somesub/comments/post-id/post-title&bypass_nsfw_landing/?q=some-query&type=comment
If we can't retrieve subreddit name, just use the user-supplied name.
This fixes banned subreddits being impossible to to unfilter or
unsubscribe from.
A drawback of such approach is that it might be possible to subscribe to
a subreddit twice with different casing, however the chance of this is
extremely low.
* Fix gated communities being unviewable by treating them as quarantined
* Show restriction reason in quarantine template
* Add `gated` checks for other requests
Making a new connection on every request is very slow and wasteful, espectially on slower network.
Fix this by reuse a hyper client which shares a connection pool.
I'm able to lower /r/popular loading time from 5s to 1.5s on my machine.
This simplifies the logic to build the listener by using more clap
features instead of manually accessing the PORT environment variable.
This also removes unnecessary `unwrap_or` calls that set defaults that
are already set by clap.
* Search - add support for raw reddit links
If a search query starts with 'https://www.reddit.com/' or 'https://old.reddit.com/',
this prefix will be truncated and the query will be processed normally.
For example, a search query 'https://www.reddit.com/r/rust' will redirect to
r/rust.
* Search - support a wider variety of reddit links.
Add once cell dependency for static regex support (avoid compiling the
same regex multiple times).
All search queries are now matched against a regex (provided by @Daniel-Valentine)
that determines if it is a reddit link. If it is, the prefix specifying
the reddit instance will be truncated from the query that will then be
processed normally.
For example, the query 'https://www.reddit.com/r/rust' will be treated
the same way as the query 'r/rust'.
* Fix 'all_posts_hidden_nsfw' when there are no posts.
If a search query yielded no results and the user set nsfw posts to be
hidden, libreddit would show 'All posts are hidden because they are NSFW.
Enable "Show NSFW posts" in settings to view'. This is fixed by
verifying tnat posts.len > 0 before setting 'all_posts_hidden_nsfw' to
true.
* Add a message when no posts were found.
* Delete 2
* Redirect /:id to canonical URL for post.
This implements redirection of `/:id` (a short-form URL to a post) to
the post's canonical URL. Libreddit issues a `HEAD /:id` to Reddit to get
the canonical URL, and on success will send an HTTP 302 to a client with
the canonical URL set in as the value of the `Location:` header.
This also implements support for short IDs for non-ASCII posts, c/o
spikecodes.
Co-authored-by: spikecodes <19519553+spikecodes@users.noreply.github.com>
Implements HTTP compression, between both Reddit and Libreddit and Libreddit
and a web browser. Compression between Reddit and Libreddit is mandatory,
whereas compression between Libreddit and a client is opt-in (client must
specify a compressor in the Accept-Encoding header).
Supported compressors are gzip and brotli. gzip support is ubiquitous,
whereas brotli is supported by almost all modern browsers except Safari
(iOS, iPhone, macOS), although Safari may support brotli in the future.
Co-authored-by: Matthew E <matt@matthew.science>
Adds another on/off preference (default: on, keeps same
behaviour) for the fixed navbar.
When off the navbar will not remain at the top of the
page when scrolling.
This is useful for small displays such as phones where
otherwise the navbar takes up a sizeable portion of
the viewport.
* Fix sorting buttons on r/all and r/popular
* Bump version to v0.22.2
* Fix empty sidebar in r/all and r/popular
Co-authored-by: spikecodes <19519553+spikecodes@users.noreply.github.com>
* Parse video data from cross_post_parent_list as vanilla Reddit does.
introduce testdata directory for testing JSON parsing functions.
refactor Media::parse for slightly more readability.
Add various test cases.
* Trim down to just refactoring
Co-authored-by: Spike <19519553+spikecodes@users.noreply.github.com>
* Initial work on filtering subreddits and users
* Fix doubly-prefixed subreddit name in search alt text (e.g. r/r/pics)
* Don't set post title to "Comment" if empty - this could throw off actual posts with the title "Comment"
* Filter search results
* Fix filtering to differentiate between "this subject itself is filtered" vs "all posts on this current page have been filtered"
* Remove unnecessary check
* Clean up
* Cargo format
* Collapse comments from filtered users
Co-authored-by: spikecodes <19519553+spikecodes@users.noreply.github.com>
* Initial implementation of award parsing
* Posts: Implement awards as part of post
* Posts: remove parse_awards dead code
* Posts: initial implementation of displaying Awards at the post title
* Posts: Proxy static award images
* Client: i.redd.it should take path as argument not ID
* Posts: Just like Reddit make award size 16px
* Templates: limit the awards to 4 awards to increase performance
* Comments: Make awards a property of comments and display them
* Format and correct /img/:id
* Update comment.html
* [Optimization] Awards is not longer async
* [Revert] Posts can now display more than 4 awards again
* [Implementation] Awards not display on the frontpage
* [Implementation] Display count on awards
* Post: Start working on awards css
* Awards: Move the image size to css
* Awards: Start implementing tooltips
* Refactor awards code and tweak CSS indentation
* Unify Awards::new and Awards::parse
* Use native tooltips and brighten awards background
Co-authored-by: Spike <19519553+spikecodes@users.noreply.github.com>
* Render markdown correctly in text post previews by using selftext_html.
I was mistakenly under the impression that we somehow render markdown ourselves, but turns out we just take whatever HTML reddit gives us, and we also need to do this for text previews.
Use CSS to limit the size of the previews instead of truncating in the template.
Fix table CSS.
* Fix post_body padding and trim post_previews
Co-authored-by: spikecodes <19519553+spikecodes@users.noreply.github.com>
* Format post and comment votes with a decimal place, like vanilla reddit does.
Before this change, a vote count of 1999 was displayed as 1k, which is a pretty big gap. The displayed count also differed from what Reddit does. Now, the behaviour is consistent.
Added some tests for format_num.
* Provide more space for post scores
Co-authored-by: spikecodes <19519553+spikecodes@users.noreply.github.com>
* Add text post previews.
* Add mask gradient over post preview text
* Increase post title font weight for contrast
Co-authored-by: spikecodes <19519553+spikecodes@users.noreply.github.com>
* Collapse bot comments by default.
Comments are considered bot comments if they are posted by a moderator and are stickied. Some false positives are expected.
* Remove unneeded String conversion
Co-authored-by: spikecodes <19519553+spikecodes@users.noreply.github.com>
* Pass the url parameter to all templates. Add a reddit_link to the navbar, which opens the current url on reddit.
* Add icon for reddit link
Co-authored-by: spikecodes <19519553+spikecodes@users.noreply.github.com>
* Encode HTML characters in flairs
* Encode HTML characters in flairs
* Use esc! macro for HTML escaping
Co-authored-by: spikecodes <19519553+spikecodes@users.noreply.github.com>
* Added support for quarantined subreddits
* Added confirmation wall for quarantined subreddits
* Added quarantine walls to other routes and fixed case issue
* Correct obsolete use of cookie()
* Refactor param() and quarantine()
Co-authored-by: Spike <19519553+spikecodes@users.noreply.github.com>
* HLS video playback
Signed-off-by: Adrian Lebioda <adrianlebioda@gmail.com>
* Add LibreJS compliance
* Locally host hls.js
* Notification about HLS under videos that support it
Signed-off-by: Adrian Lebioda <adrianlebioda@gmail.com>
* Use .contains() instead of .find() == None
* Make list of preferences constant
* Change headers_keys from Vector into Array
* Fix incorrect detecting of # in paths
* Remove trailing-slash-appending if statement
* Change HLS notification styling
Co-authored-by: spikecodes <19519553+spikecodes@users.noreply.github.com>