예제 #1
0
    def get_comment_times_can_seen(status_id, user_id):
        '''得到某一个人能够看到的评论次数'''

        status = yield StatusDocument.get_status(status_id)
        if not status:
            raise gen.Return(0)

        if ObjectId(status['author']['_id']) == ObjectId(user_id):
            cnt = yield StatusCommentDocument.get_comment_times(status_id)
            raise gen.Return(cnt)

        can_see = yield StatusDocument.can_see(status, user_id)
        if not can_see:
            raise gen.Return(0)

        friend_ids = yield FriendDocument.get_same_friend_ids(
            status['author']['_id'], user_id)

        friend_ids += [
            DBRef(UserDocument.meta['collection'], ObjectId(user_id)),
            DBRef(UserDocument.meta['collection'],
                  ObjectId(status['author']['_id']))
        ]

        cnt = yield StatusCommentDocument.find({
            'status':
            DBRef(StatusDocument.meta['collection'], ObjectId(status['_id'])),
            'author': {
                '$in': friend_ids
            },
            '$or': [{
                'replyeder': {
                    '$exists': False
                }
            }, {
                'replyeder': {
                    '$exists': True,
                    '$in': friend_ids
                }
            }]
        }).count()

        raise gen.Return(cnt)
예제 #2
0
    def get_comment_times_can_seen(status_id, user_id):
        '''得到某一个人能够看到的评论次数'''

        status = yield StatusDocument.get_status(status_id)
        if not status:
            raise gen.Return(0)

        if ObjectId(status['author']['_id']) == ObjectId(user_id):
            cnt = yield StatusCommentDocument.get_comment_times(status_id)
            raise gen.Return(cnt)

        can_see = yield StatusDocument.can_see(status, user_id)
        if not can_see:
            raise gen.Return(0)

        friend_ids = yield FriendDocument.get_same_friend_ids(
            status['author']['_id'], user_id
        )

        friend_ids += [
            DBRef(
                UserDocument.meta['collection'],
                ObjectId(user_id)
            ),
            DBRef(
                UserDocument.meta['collection'],
                ObjectId(status['author']['_id'])
            )
        ]

        cnt = yield StatusCommentDocument.find({
            'status': DBRef(
                StatusDocument.meta['collection'],
                ObjectId(status['_id'])
            ),
            'author': {'$in': friend_ids},
            '$or': [
                {'replyeder': {'$exists': False}},
                {'replyeder': {'$exists': True, '$in': friend_ids}}
            ]
        }).count()

        raise gen.Return(cnt)
예제 #3
0
    def get_comment_list(status_id, user_id, skip=0, limit=None):
        '''得到某一状态的评论, 只能看到共同好友和自己的评论.

        :Parameters:
          - `status_id`: 相关的状态
          - `user_id`: 查看评论者
          - `skip`: 默认0
          - `limit`: 默认None
        '''

        comment_list = []

        status = yield StatusDocument.find_one({'_id': ObjectId(status_id)})
        if status:
            status = yield StatusDocument.translate_dbref_in_document(status)
            if status['author']['_id'] == ObjectId(user_id):
                cursor = StatusCommentDocument.find({
                    'status':
                    DBRef(StatusDocument.meta['collection'],
                          ObjectId(status['_id']))
                })
            else:
                can_see = yield StatusDocument.can_see(status, user_id)
                if not can_see:
                    raise gen.Return(comment_list)

                friend_ids = yield FriendDocument.get_same_friend_ids(
                    status['author']['_id'], user_id)

                friend_ids += [
                    DBRef(UserDocument.meta['collection'], ObjectId(user_id)),
                    DBRef(UserDocument.meta['collection'],
                          ObjectId(status['author']['_id']))
                ]

                cursor = StatusCommentDocument.find({
                    'status':
                    DBRef(StatusDocument.meta['collection'],
                          ObjectId(status['_id'])),
                    'author': {
                        '$in': friend_ids
                    },
                    '$or': [{
                        'replyeder': {
                            '$exists': False
                        }
                    }, {
                        'replyeder': {
                            '$exists': True,
                            '$in': friend_ids
                        }
                    }]
                })

            cursor = cursor.sort([('comment_time', pymongo.ASCENDING)
                                  ]).skip(skip)

            if limit is not None:
                cursor = cursor.limit(limit)

            translate = StatusCommentDocument.translate_dbref_in_document_list
            comment_list = yield StatusCommentDocument.to_list(cursor)
            comment_list = yield translate(comment_list)

        raise gen.Return(comment_list)
예제 #4
0
    def get_comment_list(status_id, user_id, skip=0, limit=None):
        '''得到某一状态的评论, 只能看到共同好友和自己的评论.

        :Parameters:
          - `status_id`: 相关的状态
          - `user_id`: 查看评论者
          - `skip`: 默认0
          - `limit`: 默认None
        '''

        comment_list = []

        status = yield StatusDocument.find_one({'_id': ObjectId(status_id)})
        if status:
            status = yield StatusDocument.translate_dbref_in_document(status)
            if status['author']['_id'] == ObjectId(user_id):
                cursor = StatusCommentDocument.find({
                    'status': DBRef(
                        StatusDocument.meta['collection'],
                        ObjectId(status['_id'])
                    )
                })
            else:
                can_see = yield StatusDocument.can_see(status, user_id)
                if not can_see:
                    raise gen.Return(comment_list)

                friend_ids = yield FriendDocument.get_same_friend_ids(
                    status['author']['_id'], user_id
                )

                friend_ids += [
                    DBRef(
                        UserDocument.meta['collection'],
                        ObjectId(user_id)
                    ),
                    DBRef(
                        UserDocument.meta['collection'],
                        ObjectId(status['author']['_id'])
                    )
                ]

                cursor = StatusCommentDocument.find({
                    'status': DBRef(
                        StatusDocument.meta['collection'],
                        ObjectId(status['_id'])
                    ),
                    'author': {'$in': friend_ids},
                    '$or': [
                        {'replyeder': {'$exists': False}},
                        {'replyeder': {'$exists': True, '$in': friend_ids}}
                    ]
                })

            cursor = cursor.sort(
                [('comment_time', pymongo.ASCENDING)]
            ).skip(skip)

            if limit is not None:
                cursor = cursor.limit(limit)

            translate = StatusCommentDocument.translate_dbref_in_document_list
            comment_list = yield StatusCommentDocument.to_list(cursor)
            comment_list = yield translate(comment_list)

        raise gen.Return(comment_list)