예제 #1
0
 def run(self, user_id):
     UserSubscription.trim_user_read_stories(user_id)
     UserSubscription.verify_feeds_scheduled(user_id)
     Profile.count_all_feed_subscribers_for_user(user_id)
     MInteraction.trim(user_id)
     MActivity.trim(user_id)
     # UserSubscription.refresh_stale_feeds(user_id)
     
     try:
         ss = MSocialServices.objects.get(user_id=user_id)
     except MSocialServices.DoesNotExist:
         logging.debug(" ---> ~FRCleaning up user, can't find social_services for user_id: ~SB%s" % user_id)
         return
     ss.sync_twitter_photo()
예제 #2
0
def like_comment(request):
    code     = 1
    feed_id  = int(request.POST['story_feed_id'])
    story_id = request.POST['story_id']
    comment_user_id = request.POST['comment_user_id']
    format = request.REQUEST.get('format', 'json')
    
    if comment_user_id == request.user.pk:
        return json.json_response(request, {'code': -1, 'message': 'You cannot favorite your own shared story comment.'})
        
    shared_story = MSharedStory.objects.get(user_id=comment_user_id, 
                                            story_feed_id=feed_id, 
                                            story_guid=story_id)
    shared_story.add_liking_user(request.user.pk)
    comment, profiles = shared_story.comment_with_author_and_profiles()

    comment_user = User.objects.get(pk=shared_story.user_id)
    logging.user(request, "~BB~FMLiking comment by ~SB%s~SN: %s" % (
        comment_user.username, 
        shared_story.comments[:30],
    ))

    MActivity.new_comment_like(liking_user_id=request.user.pk,
                               comment_user_id=comment['user_id'],
                               story_id=story_id,
                               story_title=shared_story.story_title,
                               comments=shared_story.comments)
    MInteraction.new_comment_like(liking_user_id=request.user.pk, 
                                  comment_user_id=comment['user_id'],
                                  story_id=story_id,
                                  story_title=shared_story.story_title,
                                  comments=shared_story.comments)
                                       
    if format == 'html':
        comment = MSharedStory.attach_users_to_comment(comment, profiles)
        return render_to_response('social/story_comment.xhtml', {
            'comment': comment,
        }, context_instance=RequestContext(request))
    else:
        return json.json_response(request, {
            'code': code, 
            'comment': comment, 
            'user_profiles': profiles,
        })
예제 #3
0
def render_interactions_module(context, page=1):
    user = get_user(context['user'])
    interactions, has_next_page = MInteraction.user(user.pk, page)
    
    return {
        'user': user,
        'interactions': interactions,
        'page': page,
        'has_next_page': has_next_page,
        'MEDIA_URL': context['MEDIA_URL'],
    }
예제 #4
0
def render_interactions_module(context, page=1):
    user = get_user(context['user'])
    interactions, has_next_page = MInteraction.user(user.pk, page)

    return {
        'user': user,
        'interactions': interactions,
        'page': page,
        'has_next_page': has_next_page,
        'MEDIA_URL': context['MEDIA_URL'],
    }
예제 #5
0
파일: views.py 프로젝트: yoyo2k/NewsBlur
def like_comment(request):
    code = 1
    feed_id = int(request.POST["story_feed_id"])
    story_id = request.POST["story_id"]
    comment_user_id = request.POST["comment_user_id"]
    format = request.REQUEST.get("format", "json")

    if comment_user_id == request.user.pk:
        return json.json_response(
            request, {"code": -1, "message": "You cannot favorite your own shared story comment."}
        )

    shared_story = MSharedStory.objects.get(user_id=comment_user_id, story_feed_id=feed_id, story_guid=story_id)
    shared_story.add_liking_user(request.user.pk)
    comment, profiles = shared_story.comment_with_author_and_profiles()

    comment_user = User.objects.get(pk=shared_story.user_id)
    logging.user(request, "~BB~FMLiking comment by ~SB%s~SN: %s" % (comment_user.username, shared_story.comments[:30]))

    MActivity.new_comment_like(
        liking_user_id=request.user.pk,
        comment_user_id=comment["user_id"],
        story_id=story_id,
        story_title=shared_story.story_title,
        comments=shared_story.comments,
    )
    MInteraction.new_comment_like(
        liking_user_id=request.user.pk,
        comment_user_id=comment["user_id"],
        story_id=story_id,
        story_title=shared_story.story_title,
        comments=shared_story.comments,
    )

    if format == "html":
        comment = MSharedStory.attach_users_to_comment(comment, profiles)
        return render_to_response(
            "social/story_comment.xhtml", {"comment": comment}, context_instance=RequestContext(request)
        )
    else:
        return json.json_response(request, {"code": code, "comment": comment, "user_profiles": profiles})
예제 #6
0
파일: views.py 프로젝트: yoyo2k/NewsBlur
def load_interactions(request):
    user_id = request.REQUEST.get("user_id", None)
    if not user_id:
        user_id = get_user(request).pk
    page = max(1, int(request.REQUEST.get("page", 1)))
    limit = request.REQUEST.get("limit")
    interactions, has_next_page = MInteraction.user(user_id, page=page, limit=limit)
    format = request.REQUEST.get("format", None)

    data = {"interactions": interactions, "page": page, "has_next_page": has_next_page}

    if format == "html":
        return render_to_response("reader/interactions_module.xhtml", data, context_instance=RequestContext(request))
    else:
        return json.json_response(request, data)
예제 #7
0
def load_interactions(request):
    user_id = request.REQUEST.get('user_id', None)
    if not user_id:
        user_id = get_user(request).pk
    page = max(1, int(request.REQUEST.get('page', 1)))
    limit = request.REQUEST.get('limit')
    interactions, has_next_page = MInteraction.user(user_id, page=page, limit=limit)
    format = request.REQUEST.get('format', None)
    
    data = {
        'interactions': interactions,
        'page': page,
        'has_next_page': has_next_page
    }
    
    if format == 'html':
        return render_to_response('reader/interactions_module.xhtml', data,
                                  context_instance=RequestContext(request))
    else:
        return json.json_response(request, data)
예제 #8
0
def remove_comment_reply(request):
    code     = 1
    feed_id  = int(request.POST['story_feed_id'])
    story_id = request.POST['story_id']
    comment_user_id = request.POST['comment_user_id']
    reply_id = request.POST.get('reply_id')
    format = request.REQUEST.get('format', 'json')
    original_message = None
    
    shared_story = MSharedStory.objects.get(user_id=comment_user_id, 
                                            story_feed_id=feed_id, 
                                            story_guid=story_id)
    replies = []
    for story_reply in shared_story.replies:
        if ((story_reply.user_id == request.user.pk or request.user.is_staff) and 
            story_reply.reply_id == ObjectId(reply_id)):
            original_message = story_reply.comments
            # Skip reply
        else:
            replies.append(story_reply)
    shared_story.replies = replies
    shared_story.save()

    logging.user(request, "~FCRemoving comment reply in ~FM%s: ~SB~FB%s~FM" % (
             shared_story.story_title[:20], original_message and original_message[:30]))
    
    comment, profiles = shared_story.comment_with_author_and_profiles()

    # Interaction for every other replier and original commenter
    MActivity.remove_comment_reply(user_id=request.user.pk,
                                   comment_user_id=comment['user_id'],
                                   reply_content=original_message,
                                   story_id=story_id,
                                   story_feed_id=feed_id)
    MInteraction.remove_comment_reply(user_id=comment['user_id'], 
                                      reply_user_id=request.user.pk, 
                                      reply_content=original_message,
                                      story_id=story_id,
                                      story_feed_id=feed_id)
    
    reply_user_ids = [reply['user_id'] for reply in comment['replies']]
    for user_id in set(reply_user_ids).difference([comment['user_id']]):
        if request.user.pk != user_id:
            MInteraction.remove_reply_reply(user_id=user_id, 
                                            comment_user_id=comment['user_id'],
                                            reply_user_id=request.user.pk, 
                                            reply_content=original_message,
                                            story_id=story_id,
                                            story_feed_id=feed_id)
    
    if format == 'html':
        comment = MSharedStory.attach_users_to_comment(comment, profiles)
        return render_to_response('social/story_comment.xhtml', {
            'comment': comment,
        }, context_instance=RequestContext(request))
    else:
        return json.json_response(request, {
            'code': code, 
            'comment': comment, 
            'user_profiles': profiles
        })
예제 #9
0
def save_comment_reply(request):
    code     = 1
    feed_id  = int(request.POST['story_feed_id'])
    story_id = request.POST['story_id']
    comment_user_id = request.POST['comment_user_id']
    reply_comments = request.POST.get('reply_comments')
    reply_id = request.POST.get('reply_id')
    format = request.REQUEST.get('format', 'json')
    original_message = None
    
    if not reply_comments:
        return json.json_response(request, {'code': -1, 'message': 'Reply comments cannot be empty.'})
        
    shared_story = MSharedStory.objects.get(user_id=comment_user_id, 
                                            story_feed_id=feed_id, 
                                            story_guid=story_id)
    reply = MCommentReply()
    reply.user_id = request.user.pk
    reply.publish_date = datetime.datetime.now()
    reply.comments = reply_comments
    
    if reply_id:
        replies = []
        for story_reply in shared_story.replies:
            if (story_reply.user_id == reply.user_id and 
                story_reply.reply_id == ObjectId(reply_id)):
                reply.publish_date = story_reply.publish_date
                reply.reply_id = story_reply.reply_id
                original_message = story_reply.comments
                replies.append(reply)
            else:
                replies.append(story_reply)
        shared_story.replies = replies
        logging.user(request, "~FCUpdating comment reply in ~FM%s: ~SB~FB%s~FM" % (
                 shared_story.story_title[:20], reply_comments[:30]))
    else:
        reply.reply_id = ObjectId()
        logging.user(request, "~FCReplying to comment in: ~FM%s: ~SB~FB%s~FM" % (
                     shared_story.story_title[:20], reply_comments[:30]))
        shared_story.replies.append(reply)
    shared_story.save()
    
    comment, profiles = shared_story.comment_with_author_and_profiles()
    
    # Interaction for every other replier and original commenter
    MActivity.new_comment_reply(user_id=request.user.pk,
                                comment_user_id=comment['user_id'],
                                reply_content=reply_comments,
                                original_message=original_message,
                                story_id=story_id,
                                story_feed_id=feed_id,
                                story_title=shared_story.story_title)
    if comment['user_id'] != request.user.pk:
        MInteraction.new_comment_reply(user_id=comment['user_id'], 
                                       reply_user_id=request.user.pk, 
                                       reply_content=reply_comments,
                                       original_message=original_message,
                                       story_id=story_id,
                                       story_feed_id=feed_id,
                                       story_title=shared_story.story_title)

    reply_user_ids = list(r['user_id'] for r in comment['replies'])
    for user_id in set(reply_user_ids).difference([comment['user_id']]):
        if request.user.pk != user_id:
            MInteraction.new_reply_reply(user_id=user_id, 
                                         comment_user_id=comment['user_id'],
                                         reply_user_id=request.user.pk, 
                                         reply_content=reply_comments,
                                         original_message=original_message,
                                         story_id=story_id,
                                         story_feed_id=feed_id,
                                         story_title=shared_story.story_title)

    EmailCommentReplies.apply_async(kwargs=dict(shared_story_id=shared_story.id,
                                                reply_id=reply.reply_id), countdown=60)
    
    if format == 'html':
        comment = MSharedStory.attach_users_to_comment(comment, profiles)
        return render_to_response('social/story_comment.xhtml', {
            'comment': comment,
        }, context_instance=RequestContext(request))
    else:
        return json.json_response(request, {
            'code': code, 
            'comment': comment, 
            'reply_id': reply.reply_id,
            'user_profiles': profiles
        })
예제 #10
0
파일: views.py 프로젝트: yoyo2k/NewsBlur
def remove_comment_reply(request):
    code = 1
    feed_id = int(request.POST["story_feed_id"])
    story_id = request.POST["story_id"]
    comment_user_id = request.POST["comment_user_id"]
    reply_id = request.POST.get("reply_id")
    format = request.REQUEST.get("format", "json")
    original_message = None

    shared_story = MSharedStory.objects.get(user_id=comment_user_id, story_feed_id=feed_id, story_guid=story_id)
    replies = []
    for story_reply in shared_story.replies:
        if (story_reply.user_id == request.user.pk or request.user.is_staff) and story_reply.reply_id == ObjectId(
            reply_id
        ):
            original_message = story_reply.comments
            # Skip reply
        else:
            replies.append(story_reply)
    shared_story.replies = replies
    shared_story.save()

    logging.user(
        request,
        "~FCRemoving comment reply in ~FM%s: ~SB~FB%s~FM"
        % (shared_story.story_title[:20], original_message and original_message[:30]),
    )

    comment, profiles = shared_story.comment_with_author_and_profiles()

    # Interaction for every other replier and original commenter
    MActivity.remove_comment_reply(
        user_id=request.user.pk,
        comment_user_id=comment["user_id"],
        reply_content=original_message,
        story_id=story_id,
        story_feed_id=feed_id,
    )
    MInteraction.remove_comment_reply(
        user_id=comment["user_id"],
        reply_user_id=request.user.pk,
        reply_content=original_message,
        story_id=story_id,
        story_feed_id=feed_id,
    )

    reply_user_ids = [reply["user_id"] for reply in comment["replies"]]
    for user_id in set(reply_user_ids).difference([comment["user_id"]]):
        if request.user.pk != user_id:
            MInteraction.remove_reply_reply(
                user_id=user_id,
                comment_user_id=comment["user_id"],
                reply_user_id=request.user.pk,
                reply_content=original_message,
                story_id=story_id,
                story_feed_id=feed_id,
            )

    if format == "html":
        comment = MSharedStory.attach_users_to_comment(comment, profiles)
        return render_to_response(
            "social/story_comment.xhtml", {"comment": comment}, context_instance=RequestContext(request)
        )
    else:
        return json.json_response(request, {"code": code, "comment": comment, "user_profiles": profiles})
예제 #11
0
파일: views.py 프로젝트: yoyo2k/NewsBlur
def save_comment_reply(request):
    code = 1
    feed_id = int(request.POST["story_feed_id"])
    story_id = request.POST["story_id"]
    comment_user_id = request.POST["comment_user_id"]
    reply_comments = request.POST.get("reply_comments")
    reply_id = request.POST.get("reply_id")
    format = request.REQUEST.get("format", "json")
    original_message = None

    if not reply_comments:
        return json.json_response(request, {"code": -1, "message": "Reply comments cannot be empty."})

    shared_story = MSharedStory.objects.get(user_id=comment_user_id, story_feed_id=feed_id, story_guid=story_id)
    reply = MCommentReply()
    reply.user_id = request.user.pk
    reply.publish_date = datetime.datetime.now()
    reply.comments = reply_comments

    if reply_id:
        replies = []
        for story_reply in shared_story.replies:
            if story_reply.user_id == reply.user_id and story_reply.reply_id == ObjectId(reply_id):
                reply.publish_date = story_reply.publish_date
                reply.reply_id = story_reply.reply_id
                original_message = story_reply.comments
                replies.append(reply)
            else:
                replies.append(story_reply)
        shared_story.replies = replies
        logging.user(
            request,
            "~FCUpdating comment reply in ~FM%s: ~SB~FB%s~FM" % (shared_story.story_title[:20], reply_comments[:30]),
        )
    else:
        reply.reply_id = ObjectId()
        logging.user(
            request,
            "~FCReplying to comment in: ~FM%s: ~SB~FB%s~FM" % (shared_story.story_title[:20], reply_comments[:30]),
        )
        shared_story.replies.append(reply)
    shared_story.save()

    comment, profiles = shared_story.comment_with_author_and_profiles()

    # Interaction for every other replier and original commenter
    MActivity.new_comment_reply(
        user_id=request.user.pk,
        comment_user_id=comment["user_id"],
        reply_content=reply_comments,
        original_message=original_message,
        story_id=story_id,
        story_feed_id=feed_id,
        story_title=shared_story.story_title,
    )
    if comment["user_id"] != request.user.pk:
        MInteraction.new_comment_reply(
            user_id=comment["user_id"],
            reply_user_id=request.user.pk,
            reply_content=reply_comments,
            original_message=original_message,
            story_id=story_id,
            story_feed_id=feed_id,
            story_title=shared_story.story_title,
        )

    reply_user_ids = list(r["user_id"] for r in comment["replies"])
    for user_id in set(reply_user_ids).difference([comment["user_id"]]):
        if request.user.pk != user_id:
            MInteraction.new_reply_reply(
                user_id=user_id,
                comment_user_id=comment["user_id"],
                reply_user_id=request.user.pk,
                reply_content=reply_comments,
                original_message=original_message,
                story_id=story_id,
                story_feed_id=feed_id,
                story_title=shared_story.story_title,
            )

    EmailCommentReplies.apply_async(kwargs=dict(shared_story_id=shared_story.id, reply_id=reply.reply_id), countdown=60)

    if format == "html":
        comment = MSharedStory.attach_users_to_comment(comment, profiles)
        return render_to_response(
            "social/story_comment.xhtml", {"comment": comment}, context_instance=RequestContext(request)
        )
    else:
        return json.json_response(
            request, {"code": code, "comment": comment, "reply_id": reply.reply_id, "user_profiles": profiles}
        )