コード例 #1
0
ファイル: outgoing.py プロジェクト: SHSauler/bookwyrm
def handle_shelve(user, book, shelf):
    ''' a local user is getting a book put on their shelf '''
    # update the database
    shelve = models.ShelfBook(book=book, shelf=shelf, added_by=user)
    shelve.save()

    broadcast(user, shelve.to_add_activity(user))
コード例 #2
0
ファイル: outgoing.py プロジェクト: SHSauler/bookwyrm
def handle_reject(follow_request):
    ''' a local user who managed follows rejects a follow request '''
    user = follow_request.user_subject
    to_follow = follow_request.user_object
    activity = follow_request.to_reject_activity()
    follow_request.delete()
    broadcast(to_follow, activity, privacy='direct', direct_recipients=[user])
コード例 #3
0
ファイル: outgoing.py プロジェクト: SHSauler/bookwyrm
def handle_untag(user, book, name):
    ''' tag a book '''
    book = models.Book.objects.get(id=book)
    tag = models.Tag.objects.get(name=name, book=book, user=user)
    tag_activity = tag.to_remove_activity(user)
    tag.delete()

    broadcast(user, tag_activity)
コード例 #4
0
ファイル: outgoing.py プロジェクト: SHSauler/bookwyrm
def handle_unshelve(user, book, shelf):
    ''' a local user is getting a book put on their shelf '''
    # update the database
    row = models.ShelfBook.objects.get(book=book, shelf=shelf)
    activity = row.to_remove_activity(user)
    row.delete()

    broadcast(user, activity)
コード例 #5
0
ファイル: outgoing.py プロジェクト: hartsick/bookwyrm
def handle_unboost(user, status):
    ''' a user regrets boosting a status '''
    boost = models.Boost.objects.filter(boosted_status=status,
                                        user=user).first()
    activity = boost.to_undo_activity(user)

    boost.delete()
    broadcast(user, activity)
コード例 #6
0
ファイル: outgoing.py プロジェクト: SHSauler/bookwyrm
def handle_reading_status(user, shelf, book, privacy):
    ''' post about a user reading a book '''
    # tell the world about this cool thing that happened
    try:
        message = {
            'to-read': 'wants to read',
            'reading': 'started reading',
            'read': 'finished reading'
        }[shelf.identifier]
    except KeyError:
        # it's a non-standard shelf, don't worry about it
        return

    status = create_generated_note(user,
                                   message,
                                   mention_books=[book],
                                   privacy=privacy)
    status.save()

    broadcast(user, status.to_create_activity(user))
コード例 #7
0
ファイル: outgoing.py プロジェクト: SHSauler/bookwyrm
def handle_status(user, form):
    ''' generic handler for statuses '''
    status = form.save()

    # inspect the text for user tags
    text = status.content
    matches = re.finditer(regex.username, text)
    for match in matches:
        username = match.group().strip().split('@')[1:]
        if len(username) == 1:
            # this looks like a local user (@user), fill in the domain
            username.append(DOMAIN)
        username = '******'.join(username)

        mention_user = handle_remote_webfinger(username)
        if not mention_user:
            # we can ignore users we don't know about
            continue
        # add them to status mentions fk
        status.mention_users.add(mention_user)
        # create notification if the mentioned user is local
        if mention_user.local:
            create_notification(mention_user,
                                'MENTION',
                                related_user=user,
                                related_status=status)
    status.save()

    # notify reply parent or tagged users
    if status.reply_parent and status.reply_parent.user.local:
        create_notification(status.reply_parent.user,
                            'REPLY',
                            related_user=user,
                            related_status=status)

    broadcast(user, status.to_create_activity(user), software='bookwyrm')

    # re-format the activity for non-bookwyrm servers
    if hasattr(status, 'pure_activity_serializer'):
        remote_activity = status.to_create_activity(user, pure=True)
        broadcast(user, remote_activity, software='other')
コード例 #8
0
ファイル: outgoing.py プロジェクト: SHSauler/bookwyrm
def handle_imported_book(user, item, include_reviews, privacy):
    ''' process a goodreads csv and then post about it '''
    if isinstance(item.book, models.Work):
        item.book = item.book.default_edition
    if not item.book:
        return

    if item.shelf:
        desired_shelf = models.Shelf.objects.get(identifier=item.shelf,
                                                 user=user)
        # shelve the book if it hasn't been shelved already
        shelf_book, created = models.ShelfBook.objects.get_or_create(
            book=item.book, shelf=desired_shelf, added_by=user)
        if created:
            broadcast(user, shelf_book.to_add_activity(user), privacy=privacy)

            # only add new read-throughs if the item isn't already shelved
            for read in item.reads:
                read.book = item.book
                read.user = user
                read.save()

    if include_reviews and (item.rating or item.review):
        review_title = 'Review of {!r} on Goodreads'.format(
            item.book.title, ) if item.review else ''

        # we don't know the publication date of the review,
        # but "now" is a bad guess
        published_date_guess = item.date_read or item.date_added
        review = models.Review.objects.create(
            user=user,
            book=item.book,
            name=review_title,
            content=item.review,
            rating=item.rating,
            published_date=published_date_guess,
            privacy=privacy,
        )
        # we don't need to send out pure activities because non-bookwyrm
        # instances don't need this data
        broadcast(user, review.to_create_activity(user), privacy=privacy)
コード例 #9
0
ファイル: outgoing.py プロジェクト: SHSauler/bookwyrm
def handle_tag(user, tag):
    ''' tag a book '''
    broadcast(user, tag.to_add_activity(user))
コード例 #10
0
ファイル: outgoing.py プロジェクト: SHSauler/bookwyrm
def handle_delete_status(user, status):
    ''' delete a status and broadcast deletion to other servers '''
    delete_status(status)
    broadcast(user, status.to_delete_activity(user))