Skip to content

Messaging

hypha.apply.activity.messaging

logger module-attribute

logger = getLogger(__name__)

User module-attribute

User = get_user_model()

adapters module-attribute

messenger module-attribute

messenger = MessengerBackend(*adapters)

MessengerBackend

MessengerBackend(*adapters)
Source code in hypha/apply/activity/messaging.py
def __init__(self, *adapters):
    self.adapters = adapters

adapters instance-attribute

adapters = adapters

send

send(message_type, request, user, related, source=None, sources=None, **kwargs)
Source code in hypha/apply/activity/messaging.py
def send(
    self, message_type, request, user, related, source=None, sources=None, **kwargs
):
    from .models import Event

    if sources is None:
        sources = []

    if source:
        event = Event.objects.create(type=message_type.name, by=user, source=source)
        for adapter in self.adapters:
            adapter.process(
                message_type,
                event,
                request=request,
                user=user,
                source=source,
                related=related,
                **kwargs,
            )

    elif sources:
        events = Event.objects.bulk_create(
            Event(type=message_type.name, by=user, source=source)
            for source in sources
        )
        for adapter in self.adapters:
            adapter.process_batch(
                message_type,
                events,
                request=request,
                user=user,
                sources=sources,
                related=related,
                **kwargs,
            )