Skip to content

Latest commit

 

History

History
90 lines (52 loc) · 2.03 KB

File metadata and controls

90 lines (52 loc) · 2.03 KB

set_post_feed_related_objects_hook

This hook wraps the standard function that Misago uses to set related objects on dicts containing posts feed data.

Location

This hook can be imported from misago.threads.hooks:

from misago.threads.hooks import set_post_feed_related_objects_hook

Filter

def custom_set_post_feed_related_objects_filter(
    action: SetPostFeedRelatedObjectsHookAction,
    feed: list[dict],
    related_objects: dict,
):
    ...

A function implemented by a plugin that can be registered in this hook.

Arguments

action: SetPostFeedRelatedObjectsHookAction

Next function registered in this hook, either a custom function or Misago's standard one.

See the action section for details.

feed: list[dict]

A list of dict objects with post feed items. This function updates these dicts with objects from the related_objects dictionary.

related_objects: dict

A dict with objects related to the feed's items.

Action

def set_post_feed_related_objects_action(feed: list[dict], related_objects: dict):
    ...

Misago function used to set related objects on dicts containing posts feed data.

Arguments

feed: list[dict]

A list of dict objects with post feed items. This function updates these dicts with objects from the related_objects dictionary.

related_objects: dict

A dict with objects related to the feed's items.

Example

The code below implements a custom filter function that populates feed's items with plugin objects

from misago.threads.hooks import set_post_feed_related_objects_hook


@set_post_feed_related_objects_hook.append_filter
def replace_post_poster(
    action, feed: list[dict], related_objects: dict
):
    action(feed, related_objects)

    for item in feed:
        if item["type"] == "post":
            plugin_obj = related_objects["plugin_objects"].get(
                item["post"].plugin_data["plugin_relation_id"]
            )
            item["plugin_attr"] = plugin_obj