-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Feat/timeline with HTML render (#8)
* feat: basic login * feat: successful login * feat: save credentials with keychain-swift * feat: adjust log * feat: switch instances * feat: lowercase server address * fix: non-neodb.social instance cannot login * feat: user api * feat: make llm knows keychain-swift is already added * feat: custom ContentUnavailableView * feat: profile view * feat: feat inject * feat: new profile view design * feat: injection * feat: new profile design * feat: injection next * feat: redesigned profile * refactor: replace @StateObject with @EnvironmentObject for AuthService in ContentView, LoginView, and NeoDBApp * feat: implement user caching and refresh functionality in UserService and ProfileViewModel - Added caching mechanism for user data in UserService to improve performance. - Updated getCurrentUser method to accept a forceRefresh parameter for optional cache bypass. - Implemented clearCache method to allow cache clearing on logout. - Modified loadUserProfile method in ProfileViewModel to support force refresh. - Enhanced ProfileView to show loading indicators and support pull-to-refresh for user profile loading. * refactor: enhance ProfileView layout and loading state handling - Introduced a new private variable for avatar size to standardize avatar dimensions. - Refactored profile content display logic to improve readability and maintainability. - Added a placeholder for the avatar while loading user data. - Updated loading indicators and error handling for a better user experience. - Ensured the logout button is disabled when no user is present. * chore: remove outdated Project Structure documentation and update logout button in ProfileView - Deleted the Project Structure.md file as it was no longer relevant. - Updated the logout button in ProfileView to use a text label instead of an icon, enhancing clarity for users. * refactor: update ContentView to use HomeView and remove unused code - Replaced the static "Home Feed" text with the HomeView component for better functionality. - Removed unnecessary commented-out code and debug-related properties to clean up the ContentView structure. * refactor: update Status model and TimelineService for improved data handling - Changed Status from a struct to a class, adding new properties for enhanced functionality, including uri, editedAt, and various flags (favourited, reblogged, etc.). - Updated the TimelineService to modify the timeline fetching method and improve error logging with detailed messages for better debugging. - Enhanced HomeViewModel to handle loading states and detailed error reporting, improving user experience during data fetch operations. - Added support for displaying status statistics (replies, reblogs, favourites) in the HomeView. * refactor: update TimelineService to local only - Changed logger subsystem from "app.neodb" to "social.neodb.app" for better categorization. - Updated getTimeline method to include a new 'local' parameter, defaulting to true, to filter statuses. - Enhanced query item handling to always include 'local=true' in requests. - Improved logging messages to specify when local statuses are successfully decoded. * feat: enhance local timeline with HTML content rendering - Updated TimelineService to display only local statuses and render HTML content properly. - Introduced HTMLContentView for rendering status content with support for links, mentions, and emoji ratings. - Added SwiftDown and MarkdownUI packages for HTML parsing and rendering. - Improved documentation to reflect new features and implementation details. - Enhanced StatusView with rich text support for better readability and interaction.
- Loading branch information
Showing
9 changed files
with
569 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,54 @@ | ||
# Timeline Local-Only Implementation | ||
|
||
## Overview | ||
Modified TimelineService to show only local statuses from the instance. | ||
Modified TimelineService to show only local statuses from the instance and properly render HTML content. | ||
|
||
## API Reference | ||
From Mastodon API documentation: | ||
- Endpoint: GET `/api/v1/timelines/public` | ||
- Parameter: `local=true` to show only local statuses | ||
- Default: Shows both local and remote statuses (local=false) | ||
|
||
## Content Rendering | ||
Status content comes in HTML format with the following features: | ||
- Links with href attributes | ||
- Mentions with rel attributes | ||
- Emoji ratings (🌕 for filled stars) | ||
- Paragraphs with spacing | ||
|
||
### HTML Example | ||
```html | ||
<p>看過 <a href="https://neodb.social/movie/xxx" rel="nofollow">电影名称</a> 🌕🌕🌕🌕🌕 </p> | ||
``` | ||
|
||
### Implementation Details | ||
1. Added SwiftDown package for HTML parsing | ||
2. Created custom AttributedString converter | ||
3. Added link handling support | ||
4. Implemented emoji rating display | ||
|
||
## Dependencies | ||
Required SPM packages: | ||
- SwiftDown: HTML and Markdown parsing | ||
- SwiftSoup (optional): Advanced HTML manipulation | ||
|
||
## Implementation Details | ||
1. Added local parameter to URL query | ||
2. Set local=true by default to show only local statuses | ||
3. Improved error logging for better debugging | ||
4. Added HTML content parsing and rendering | ||
5. Implemented link handling and styling | ||
|
||
## Design Rationale | ||
- Local-only timeline provides more relevant content for NeoDB users | ||
- Reduces noise from remote instances | ||
- Improves performance by reducing data load | ||
- Better content moderation as all content is from the same instance | ||
- Rich text rendering enhances readability and interaction | ||
|
||
## Code Changes | ||
- Modified getTimeline method in TimelineService | ||
- Added local parameter to URLComponents | ||
- Updated documentation | ||
- Added HTML content rendering support | ||
- Updated documentation | ||
- Enhanced StatusView with rich text support |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# HTML2Markdown | ||
|
||
## What is this? | ||
|
||
It's a Swift Package which attempts to convert HTML into Markdown. | ||
|
||
## How do I use it? | ||
|
||
```swift | ||
let html = "<p>This is a <em>terrible</em> idea.<br/>I must be daft.</p>" | ||
|
||
do { | ||
let dom = try HTMLParser().parse(html: html) | ||
let markdown = dom.markdownFormatted(options: .unorderedListBullets) | ||
print(markdown) | ||
} catch { | ||
// parsing error | ||
} | ||
``` | ||
|
||
This generates the following markdown string: | ||
|
||
``` | ||
This is a *terrible* idea.\nI must be daft. | ||
``` | ||
|
||
## What is supported? | ||
|
||
* `<strong>` and `<em>` for highlighting text | ||
* ordered and unordered lists (`<ol>` and `<ul>`) | ||
* paragraphs (`<p>`) and line breaks (`<br>`) | ||
* hyperlinks (`<a href="...">`) | ||
|
||
All other HTML tags are removed. | ||
|
||
> Note: | ||
> `SwiftUI.Text` currently cannot render Markdown lists therefore use the `MarkdownGenerator.Options.unorderedListBullets` option to generate nicer-looking bullets: `•` instead of `*`. | ||
## License | ||
|
||
See [LICENSE](LICSNE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Swift HTML -> Markdown | ||
This package allows you to quickly convert HTML code into Markdown. Normally you want to go from Markdown -> HTML and there are a thousand packages and parsers to do that. However, what if the service you are using (like Mastodon) provides everything in HTML but you want to parse it in Markdown? Well you need to convert it. This package allows you to do just that! | ||
|
||
## Supported Flavors of HTML | ||
| Flavor | Support | | ||
| -------------------- | --------------------------------------------------- | | ||
| Mastodon Status HTML (MastodonHTML) | ✅ | | ||
| Basic HTML (BasicHTML) | ⚠️ (Almost fully supported, tables are not) | | ||
|
||
## How to use | ||
Using the library is pretty simple. The first step is to pick which HTML flavor you are going to be converting. If you are converting a Basic HTML document you can use the `BasicHTML` class. For Mastodon statuses you can use the `MastodonHTML` class. | ||
|
||
Once you have picked out the class you will be using, the following code is all you need! | ||
```swift | ||
var document = BasicHTML(rawHTML: raw) | ||
try document.parse() | ||
|
||
let markdown = try document.asMarkdown() | ||
print(markdwon) | ||
``` |
Oops, something went wrong.