示例#1
0
def send_feedback_possible_count(user):
    groups = defaultdict(dict)

    for group_id, count in get_feedback_possible(user):
        groups[group_id]['feedback_possible_count'] = count

    payload = {'groups': groups}

    for subscription in ChannelSubscription.objects.recent().filter(user=user):
        send_in_channel(subscription.reply_channel, topic='status', payload=payload)
示例#2
0
def feedback_saved(sender, instance, created, **kwargs):
    feedback = instance

    if not created:
        return

    user = feedback.given_by

    groups = defaultdict(dict)
    for group_id, count in get_feedback_possible(user):
        groups[group_id]['feedback_possible_count'] = count

    payload = {'groups': groups}

    for subscription in ChannelSubscription.objects.recent().filter(user=user):
        send_in_channel(subscription.reply_channel, topic='status', payload=payload)
示例#3
0
def activity_date_saved(sender, instance, **kwargs):
    activity = instance

    if activity.is_done is False:
        # Activity is not done
        return
    # TODO don't send if 'is_done' did not change

    for user, subscriptions in groupby(sorted(list(
            ChannelSubscription.objects.recent().filter(user__in=activity.participants.all())),
                                              key=lambda x: x.user.id), key=lambda x: x.user):

        groups = defaultdict(dict)
        for group_id, count in get_feedback_possible(user):
            groups[group_id]['feedback_possible_count'] = count

        for subscription in subscriptions:
            send_in_channel(subscription.reply_channel, topic='status', payload={'groups': groups})
示例#4
0
    def get(request, **kwargs):
        conversations = unread_conversations(request.user)
        applications = pending_applications(request.user)
        feedback_possible = get_feedback_possible(request.user)

        groups = defaultdict(dict)
        for group_id, conversation_data in conversations['groups'].items():
            groups[group_id] = {
                **conversation_data,
            }

        for group_id, application_count in applications:
            groups[group_id]['pending_application_count'] = application_count

        for group_id, feedback_possible_count in feedback_possible:
            groups[group_id][
                'feedback_possible_count'] = feedback_possible_count

        places = {}
        for place_id, conversation_data in conversations['places'].items():
            places[place_id] = {
                **conversation_data,
            }

        data = {
            'unseen_conversation_count':
            conversations['unseen_conversation_count'],
            'unseen_thread_count':
            conversations['unseen_thread_count'],
            'has_unread_conversations_or_threads':
            conversations['has_unread_conversations_or_threads'],
            'unseen_notification_count':
            unseen_notification_count(request.user),
            'groups':
            groups,
            'places':
            places,
        }

        return Response(data=data, status=status.HTTP_200_OK)