This hook allows plugins to replace or extend the logic used to unwatch a thread for a user.”
This hook can be imported from misago.notifications.hooks:
from misago.notifications.hooks import unwatch_thread_hookdef custom_unwatch_thread_filter(
action: UnwatchThreadHookAction,
thread: Thread,
user: 'User',
request: HttpRequest | None=None,
) -> bool:
...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 unwatch.
The user who is unwatching the thread.
The request object, or None if not provided.
True if any WatchedThread instances were deleted, and False if not.
def unwatch_thread_action(
thread: Thread, user: 'User', request: HttpRequest | None=None
) -> bool:
...Misago function for deleting WatchedThread instances associated with a user and a thread.
The thread to unwatch.
The user who is unwatching the thread.
The request object, or None if not provided.
True if any WatchedThread instances were deleted, and False if not.
Record in the database when a user unwatches a thread:
from django.http import HttpRequest
from misago.notifications.hooks import unwatch_thread_hook
from misago.threads.models import Thread
from misago.users.models import User
from myplugin.models import UnwatchedThread
@unwatch_thread_hook.append_filter
def record_unwatched_thread(
action,
thread: Thread,
user: User,
request: HttpRequest | None = None,
) -> bool:
deleted = action(thread, user, request)
if deleted:
UnwatchedThread.objects.create(thread=thread, user=user)
return deleted