This hook allows plugins to replace or extend the logic used to create a watched thread object when user starts a new thread.
This hook can be imported from misago.notifications.hooks:
from misago.notifications.hooks import watch_started_thread_hookdef custom_watch_started_thread_filter(
action: WatchStartedThreadHookAction,
thread: Thread,
user: 'User',
commit: bool=True,
request: HttpRequest | None=None,
) -> WatchedThread | None:
...A function implemented by a plugin that can be registered in this hook.
Next function registered in this hook, either a custom function or Misago's standard one.
See the action section for details.
The thread to watch.
The user who started to the thread.
Whether the new WatchedThread instance should be saved to the database.
Defaults to True.
The request object, or None if not provided.
New WatchedThread instance, or None if the user has disabled the option to watch started threads.
def watch_started_thread_action(
thread: Thread,
user: 'User',
commit: bool=True,
request: HttpRequest | None=None,
) -> WatchedThread | None:
...Misago function for creating a new WatchedThread instance for a started thread.
The thread to watch.
The user who started to the thread.
Whether the new WatchedThread instance should be saved to the database.
Defaults to True.
The request object, or None if not provided.
New WatchedThread instance, or None if the user has disabled the option to watch started threads.
Record the IP address used to watch the thread:
from django.http import HttpRequest
from misago.notifications.hooks import watch_started_thread_hook
from misago.notifications.models import WatchedThread
from misago.threads.models import Thread
from misago.users.models import User
@watch_started_thread_hook.append_filter
def record_watched_thread_user_ip(
action,
thread: Thread,
user: User,
commit: bool = True,
request: HttpRequest | None = None,
) -> WatchedThread | None:
watched_thread = action(thread, user, send_emails, False, request)
if watched_thread:
watched_thread.plugin_data["user_id"] = request.user_ip
if commit:
watched_thread.save()
return watched_thread