-
-
Notifications
You must be signed in to change notification settings - Fork 528
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace per-post read tracker with per-thread one (#1800)
- Loading branch information
Showing
123 changed files
with
4,567 additions
and
1,105 deletions.
There are no files selected for viewing
108 changes: 108 additions & 0 deletions
108
dev-docs/plugins/hooks/get-category-threads-query-hook.md
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,108 @@ | ||
# `get_category_threads_query_hook` | ||
|
||
This hook wraps the standard function that Misago uses to get the name of the predefined database `WHERE` clause (represented as a `Q` object instance) to use to retrieve threads from the given category. | ||
|
||
|
||
## Location | ||
|
||
This hook can be imported from `misago.permissions.hooks`: | ||
|
||
```python | ||
from misago.permissions.hooks import get_category_threads_query_hook | ||
``` | ||
|
||
|
||
## Filter | ||
|
||
```python | ||
def custom_get_category_threads_query_filter( | ||
action: GetCategoryThreadsQueryHookAction, | ||
permissions: 'UserPermissionsProxy', | ||
category: dict, | ||
) -> str | list[str] | None: | ||
... | ||
``` | ||
|
||
A function implemented by a plugin that can be registered in this hook. | ||
|
||
|
||
### Arguments | ||
|
||
#### `action: GetCategoryThreadsQueryHookAction` | ||
|
||
A standard Misago function used to get the name of the predefined database `WHERE` clause (represented as a `Q` object instance) to use to retrieve threads from the given category. | ||
|
||
See the [action](#action) section for details. | ||
|
||
|
||
#### `user_permissions: UserPermissionsProxy` | ||
|
||
A proxy object with the current user's permissions. | ||
|
||
|
||
#### `category: dict` | ||
|
||
A `dict` with category data. | ||
|
||
|
||
### Return value | ||
|
||
A `CategoryThreadsQuery` member or a `str` with a custom clause name. If `None`, the query retrieving threads will skip this category. If multiple clauses should be `OR`ed together, a list of strings or `CategoryThreadsQuery` members can be returned. | ||
|
||
|
||
## Action | ||
|
||
```python | ||
def get_category_threads_query_action( | ||
permissions: 'UserPermissionsProxy', category: dict | ||
) -> str | list[str] | None: | ||
... | ||
``` | ||
|
||
A standard Misago function used to get the name of the predefined database `WHERE` clause (represented as a `Q` object instance) to use to retrieve threads from the given category. | ||
|
||
Standard `WHERE` clauses implemented by Misago can be retrieved from the `CategoryThreadsQuery` `StrEnum`: | ||
|
||
```python | ||
from misago.permissions.enums import CategoryThreadsQuery | ||
``` | ||
|
||
|
||
### Arguments | ||
|
||
#### `user_permissions: UserPermissionsProxy` | ||
|
||
A proxy object with the current user's permissions. | ||
|
||
|
||
#### `category: dict` | ||
|
||
A `dict` with category data. | ||
|
||
|
||
### Return value | ||
|
||
A `CategoryThreadsQuery` member or a `str` with a custom clause name. If `None`, the query retrieving threads will skip this category. If multiple clauses should be `OR`ed together, a list of strings or `CategoryThreadsQuery` members can be returned. | ||
|
||
|
||
## Example | ||
|
||
The code below implements a custom filter function that specifies a custom `WHERE` clause supported by the `get_threads_query_orm_filter_hook`. | ||
|
||
```python | ||
from misago.permissions.hooks import get_category_threads_query_hook | ||
from misago.permissions.proxy import UserPermissionsProxy | ||
|
||
@get_category_threads_query_hook.append_filter | ||
def get_category_threads_query( | ||
action, | ||
permissions: UserPermissionsProxy, | ||
category: dict, | ||
) -> str | list[str] | None: | ||
if ( | ||
category.get("plugin_flag") and context == CategoryQueryContext.CURRENT | ||
): | ||
return "plugin-where" | ||
|
||
return action(permissions, category) | ||
``` |
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
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 |
---|---|---|
|
@@ -57,3 +57,8 @@ | |
position: sticky; | ||
bottom: 0; | ||
} | ||
|
||
.panel-prompt { | ||
max-width: 500px; | ||
margin: @line-height-computed auto; | ||
} |
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
Oops, something went wrong.