Esempio n. 1
0
 def getNotifyContent(self, action, toid, otherid, extra):
     nickname = ''
     avatar = None
     if otherid:
         other_user1 = MeQuery('UserInfo').find_one({'user': otherid})
         if other_user1:
             nickname = other_user1['nickName']
             avatar = other_user1['avatar']
             logger.debug('nickname:%s, avatar:%s', nickname, avatar)
         else:
             logger.debug('other_user1 is null')
     if action == 'followed':
         title = '新粉丝'
         content = nickname + '关注了你'
     elif action == 'assigned':
         title = nickname
         content = '给你贡献了1张照片,快来看~'
     elif action == 'claimed':
         title = nickname
         content = '认领了你贡献的照片'
     elif action == 'assignedBought':
         title = '获得' + extra + '个蜂蜜新收益'
         content = nickname + '购买了你贡献的照片'
     elif action == 'ownedBought':
         title = '获得' + extra + '个蜂蜜新收益'
         content = nickname + '购买了你的照片'
     elif action == 'newFeed':
         title = nickname
         content = '认领了新照片,快来看~'
     elif action == 'similarFace':
         title = '来自智能探索的新发现'
         if toid:
             toid1 = MeQuery('UserInfo').find_one({'user': toid})
             if toid1:
                 nickname = toid1['nickName']
                 if nickname:
                     content = '发现了' + extra + '张可能和你(' + nickname + ')有关的照片'
                 else:
                     content = '发现了' + extra + '张可能和你有关的照片'
     elif action == 'intrestedFace':
         title = '来自智能探索的新发现'
         if toid:
             toid1 = MeQuery('UserInfo').find_one({'user': toid})
             if toid1:
                 nickname = toid1['nickName']
                 if nickname:
                     content = '发现了' + extra + '张你(' + nickname + ')可能感兴趣照片'
                 else:
                     content = '发现了' + extra + '张你可能感兴趣照片'
     else:
         logger.warn('push action error:%s', action)
         return None
     return {'title': title, 'content': content, 'avatar': avatar}
 def getNotifyContent(self, action, otherid):
     nickname = ''
     if otherid:
         other_user1 = MeQuery('UserInfo').find_one({'user': otherid})
         if other_user1:
             nickname = other_user1['nickName']
     if action == 'followed':
         title = '新粉丝'
         content = nickname + '关注了你'
         # content = '新粉丝'
     elif action == 'assigned':
         title = nickname
         content = '给你贡献了1张照片,快来看~'
         # content = '有人给我贡献照片'
     elif action == 'claimed':
         title = nickname
         content = '认领了你贡献的照片'
         # content = '有人认领了我贡献的照片'
     elif action == 'assignedBought':
         title = '新的收益'
         content = nickname + '付费查看了你贡献的照片'
         # content = '有人购买了我贡献的照片'
     elif action == 'ownedBought':
         title = '新的收益'
         content = nickname + '付费查看了你的照片'
         # content = '有人购买了我主页的照片'
     else:
         logger.warn('push action error:%s', action)
         return None
     return {'title': title, 'content': content}
Esempio n. 3
0
 def send(self):
     try:
         logger.debug(self.jsonBody)
         obj = self.jsonBody
         logger.debug('to_id:' + obj.get('to_id'))
         logger.debug('c: %s', obj.get('c'))
         logger.debug('c_type: %s', obj.get('c_type'))
         logger.debug('m_id: %s', obj.get('m_id'))
         media_id = obj.get('m_id')
         from_id = self.user['_id']
         logger.debug('from_id: %s', from_id)
         user_query = MeQuery("UserInfo")
         user_info = user_query.find_one({'user': from_id})
         message_dict = {
             'from_id': from_id,
             'c': obj.get('c'),
             'to_id': obj.get('to_id'),
             'c_type': obj.get('c_type'),
             'msg_type': 2,
             'from_avatar': user_info['avatar'],
             'from_name': user_info['nickName'],
             'status': 0,
             'm_id': media_id
         }
         message = MeObject('Message', obj=message_dict)
         message['session'] = SessionUtil.create(from_id, obj.get('to_id'))
         message.save()
         # 格式化时间为long型
         message_dict['create_at'] = long(
             message['createAt'].strftime('%s')) * 1000
         message_dict['t'] = 'comment'
         message_dict['id'] = message['_id']
         message_json = json.dumps(message_dict, ensure_ascii=False)
         logger.debug(message_json)
         print type(message['createAt'])
         rc = RedisDb.get_connection()
         rc.publish(Constants.REDIS_CHANNEL_FOR_PUSH, message_json)
         # 发push
         push_cid_obj = ClassHelper('PushCid').find_one(
             {'userid': obj.get('to_id')})
         logger.debug('push_cid_obj: %s', push_cid_obj)
         if push_cid_obj and (push_cid_obj['logout'] is False):
             # push_cid = MeObject('PushCid', obj=push_cid_obj)
             title = user_info['nickName']
             content = obj.get('c')
             content = PushEmoji.getPushContent(content)
             data = 'honey://comment/' + from_id + '?m_id=' + media_id
             print title.encode('utf-8')
             print content.encode('utf-8')
             claim_count = 0
             message_count = 0
             stat1 = ClassHelper('StatCount').find_one(
                 {'name': 'toClaim_' + obj.get('to_id')})
             if stat1:
                 claim_count = stat1['count']
                 if claim_count < 0:
                     claim_count = 0
             stat2 = ClassHelper('StatCount').find_one(
                 {'name': 'unreadMsg_' + obj.get('to_id')})
             if stat2:
                 message_count = stat2['count']
                 if message_count < 0:
                     message_count = 0
             badge = claim_count + message_count
             t = threading.Thread(target=MyGtUtil.pushMessageToSingle,
                                  args=(
                                      push_cid_obj['cid'],
                                      title.encode('utf-8'),
                                      content.encode('utf-8'),
                                      data,
                                      badge,
                                  ))
             t.setDaemon(True)
             t.start()
         # logger.debug(ERR_SUCCESS.message)
         r = {}
         r['id'] = message['_id']
         r['code'] = 0
         r['errCode'] = 0
         r['create_at'] = message_dict['create_at']
         self.write(r)
         # 计数 unreadMsg +1
         logger.debug('update to_id:unreadMsg_%s unreadMsg count ',
                      obj.get('to_id'))
         ClassHelper('StatCount').updateOne(
             {'name': 'unreadMsg_' + obj.get('to_id')},
             {"$inc": {
                 'count': 1
             }},
             upsert=True)
     except Exception, e:
         logger.error(e)
         msg = traceback.format_exc()
         logger.error(msg)
         self.write(ERR_PARA.message)
Esempio n. 4
0
    def unreadList(self):
        try:
            logger.debug('self.userid: %s:', self.user['_id'])
            all = int(self.get_argument('all', 0))
            logger.debug('all: %s', all)
            userid = self.user['_id']
            logger.debug('userid:%s', userid)
            # userid = '5a0188ccca714319e603c9e8'
            # userid = '5a0d4d88ca71432378862c53'
            if all == 1:
                # match = {"$match": {"to_id": self.user['_id'],
                #                     "msg_type": 2}}
                # {"$or": [{"to_id": to_id, "from_id": from_id}, {"to_id": from_id, "from_id": to_id}]
                match = {
                    "$match": {
                        "$or": [{
                            "to_id": userid
                        }, {
                            "from_id": userid
                        }],
                        "msg_type": 2
                    }
                }
            else:
                match = {
                    "$match": {
                        "to_id": userid,
                        "status": 0,
                        "msg_type": 2
                    }
                }
            # "59ca0b46ca714306705996dc"
            logger.debug('match:%s', match)
            message_query = MeQuery("Message")
            unread_list = message_query.aggregate([
                match,
                {
                    "$group": {
                        "_id": {
                            "from_id": "$session",
                            "m_id": "$m_id"
                        },
                        # "count": {"$sum": 1},
                        "c": {
                            "$last": "$c"
                        },
                        "id": {
                            "$last": "$_id"
                        },
                        "create_at": {
                            "$last": "$createAt"
                        },
                        "c_type": {
                            "$last": "$c_type"
                        },
                        "status": {
                            "$last": "$status"
                        },
                        "from_name": {
                            "$last": "$from_name"
                        },
                        "msg_type": {
                            "$last": "$msg_type"
                        },
                        "from_id": {
                            "$last": "$from_id"
                        },
                        "to_id": {
                            "$last": "$t"
                            "o_id"
                        },
                        "from_avatar": {
                            "$last": "$from_avatar"
                        },
                        "m_id": {
                            "$last": "$m_id"
                        }
                    }
                },
                {
                    "$sort": {
                        "create_at": -1
                    }
                }
            ])  # 时间倒序
            count_match = {
                "$match": {
                    "to_id": userid,
                    "status": 0,
                    "msg_type": 2
                }
            }
            count_list = message_query.aggregate([
                count_match, {
                    "$group": {
                        "_id": {
                            "from_id": "$session",
                            "m_id": "$m_id"
                        },
                        "count": {
                            "$sum": 1
                        },
                        "from_id": {
                            "$last": "$from_id"
                        },
                        "m_id": {
                            "$last": "$m_id"
                        }
                    }
                }
            ])
            logger.debug('unread_list:%s', unread_list)
            logger.debug('count_list:%s', count_list)
            # 处理count_list
            count_dict = {}
            if count_list:
                for count_data in count_list:
                    otherid = count_data['from_id']
                    mid = count_data['m_id']
                    count_dict[otherid + '_' + mid] = count_data['count']
            logger.debug('count_dict:%s', count_dict)
            # 整理数据
            # other_userinfo = None
            if unread_list:
                for unread_msg in unread_list:
                    del unread_msg['_id']
                    # print type(unread_msg['id'])
                    # print str(unread_msg['id'])
                    # 转换objectId to string
                    unread_msg['id'] = str(unread_msg['id'])
                    # print type(unread_msg['create_at'])
                    unread_msg['create_at'] = long(
                        unread_msg['create_at'].strftime('%s')) * 1000
                    if unread_msg['from_id'] == userid:
                        otherid = unread_msg['to_id']
                        # if not other_userinfo:
                        other_userinfo = ClassHelper('UserInfo').find_one(
                            {'user': unread_msg['to_id']})
                        logger.debug('other_userinfo:%s', other_userinfo)
                        unread_msg['other_name'] = other_userinfo['nickName']
                        unread_msg['other_avatar'] = other_userinfo.get(
                            'avatar', None)
                    else:
                        otherid = unread_msg['from_id']
                        unread_msg['other_name'] = unread_msg['from_name']
                        unread_msg['other_avatar'] = unread_msg['from_avatar']
                    mid = unread_msg['m_id']
                    unread_msg['count'] = count_dict.get(
                        otherid + '_' + mid, 0)

            logger.debug('unread_list after make data :%s', unread_list)
            result = {}
            result['errCode'] = 0
            result['unread_list'] = unread_list
            r = json.dumps(result, ensure_ascii=False)
            self.write(str(r))  # , cls=CJsonEncoder #格式化时间
        except Exception, e:
            logger.error(e)
            msg = traceback.format_exc()
            logger.error(msg)
            self.write(ERR_PARA.message)
Esempio n. 5
0
 def send(self):
     try:
         logger.debug(self.jsonBody)
         obj = self.jsonBody
         logger.debug('to_id:' + obj.get('to_id'))
         logger.debug('c: %s', obj.get('c'))
         logger.debug('c_type: %s', obj.get('c_type'))
         logger.debug('m_id: %s', obj.get('m_id'))
         media_id = obj.get('m_id')
         from_id = self.user['_id']
         logger.debug('from_id: %s', from_id)
         user_query = MeQuery("UserInfo")
         user_info = user_query.find_one({'user': from_id})
         message_dict = {
             'from_id': from_id,
             'c': obj.get('c'),
             'to_id': obj.get('to_id'),
             'c_type': obj.get('c_type'),
             'msg_type': 2,
             'from_avatar': user_info['avatar'],
             'from_name': user_info['nickName'],
             'status': 0,
             'm_id': media_id
         }
         message = MeObject('Message', obj=message_dict)
         message.save()
         # 格式化时间为long型
         message_dict['create_at'] = long(
             message['createAt'].strftime('%s')) * 1000
         message_dict['t'] = 'comment'
         message_dict['id'] = message['_id']
         message_json = json.dumps(message_dict, ensure_ascii=False)
         logger.debug(message_json)
         print type(message['createAt'])
         rc = RedisDb.get_connection()
         rc.publish(Constants.REDIS_CHANNEL_FOR_PUSH, message_json)
         # 发push
         push_cid_obj = ClassHelper('PushCid').find_one(
             {'userid': obj.get('to_id')})
         logger.debug('push_cid_obj: %s', push_cid_obj)
         if push_cid_obj:
             # push_cid = MeObject('PushCid', obj=push_cid_obj)
             title = user_info['nickName']
             content = '新评论'
             data = 'honey://comment/' + from_id + '?m_id=' + media_id
             print title.encode('utf-8')
             print content.encode('utf-8')
             t = threading.Thread(target=MyGtUtil.pushMessageToSingle,
                                  args=(
                                      push_cid_obj['cid'],
                                      title.encode('utf-8'),
                                      content.encode('utf-8'),
                                      data,
                                  ))
             t.setDaemon(True)
             t.start()
         # logger.debug(ERR_SUCCESS.message)
         r = {}
         r['id'] = message['_id']
         r['code'] = 0
         r['create_at'] = message_dict['create_at']
         self.write(r)
     except Exception, e:
         logger.error(e)
         msg = traceback.format_exc()
         logger.error(msg)
         self.write(ERR_PARA.message)
Esempio n. 6
0
 def unreadList(self):
     try:
         logger.debug('self.userid: %s:', self.user['_id'])
         all = int(self.get_argument('all', 0))
         logger.debug('all: %s', all)
         if all == 1:
             match = {"$match": {"to_id": self.user['_id'], "msg_type": 2}}
         else:
             match = {
                 "$match": {
                     "to_id": self.user['_id'],
                     "status": 0,
                     "msg_type": 2
                 }
             }
         # "59ca0b46ca714306705996dc"
         message_query = MeQuery("Message")
         unread_list = message_query.aggregate([
             match, {
                 "$group": {
                     "_id": {
                         "from_id": "$from_id",
                         "m_id": "$m_id"
                     },
                     "count": {
                         "$sum": 1
                     },
                     "c": {
                         "$last": "$c"
                     },
                     "id": {
                         "$last": "$_id"
                     },
                     "create_at": {
                         "$last": "$createAt"
                     },
                     "c_type": {
                         "$last": "$c_type"
                     },
                     "status": {
                         "$last": "$status"
                     },
                     "from_name": {
                         "$last": "$from_name"
                     },
                     "msg_type": {
                         "$last": "$msg_type"
                     },
                     "from_id": {
                         "$last": "$from_id"
                     },
                     "to_id": {
                         "$last": "$t"
                         "o_id"
                     },
                     "from_avatar": {
                         "$last": "$from_avatar"
                     },
                     "m_id": {
                         "$last": "$m_id"
                     }
                 }
             }, {
                 "$sort": {
                     "create_at": -1
                 }
             }
         ])  # 时间倒序
         logger.debug(unread_list)
         # 整理数据
         if unread_list:
             for unread_msg in unread_list:
                 del unread_msg['_id']
                 # print type(unread_msg['id'])
                 # print str(unread_msg['id'])
                 # 转换objectId to string
                 unread_msg['id'] = str(unread_msg['id'])
                 # print type(unread_msg['create_at'])
                 unread_msg['create_at'] = long(
                     unread_msg['create_at'].strftime('%s')) * 1000
         result = {}
         result['errCode'] = 0
         result['unread_list'] = unread_list
         self.write(json.dumps(
             result, ensure_ascii=False))  # , cls=CJsonEncoder #格式化时间
     except Exception, e:
         logger.error(e)
         msg = traceback.format_exc()
         logger.error(msg)
         self.write(ERR_PARA.message)
Esempio n. 7
0
    def unreadList(self):
        try:
            # userid = '59dc58a9ca7143258bcf6bc7'
            userid = self.user['_id']
            logger.debug('to_id:%s', self.user['_id'])
            # "59ca0b46ca714306705996dc"
            message_query = MeQuery("Message")
            unread_list = message_query.aggregate([{
                "$match": {
                    "to_id": userid,
                    "status": 0,
                    "msg_type": 0
                }
            }, {
                "$group": {
                    "_id": "$from_id",
                    "count": {
                        "$sum": 1
                    },
                    "c": {
                        "$last": "$c"
                    },
                    "id": {
                        "$last": "$_id"
                    },
                    "create_at": {
                        "$last": "$createAt"
                    },
                    "c_type": {
                        "$last": "$c_type"
                    },
                    "status": {
                        "$last": "$status"
                    },
                    "from_name": {
                        "$last": "$from_name"
                    },
                    "msg_type": {
                        "$last": "$msg_type"
                    },
                    "from_id": {
                        "$last": "$from_id"
                    },
                    "to_id": {
                        "$last": "$to_id"
                    },
                    "from_avatar": {
                        "$last": "$from_avatar"
                    }
                }
            }, {
                "$sort": {
                    "create_at": -1
                }
            }])  # 时间倒序
            logger.debug(unread_list)
            # 整理数据
            if unread_list:
                for unread_msg in unread_list:
                    del unread_msg['_id']
                    # print type(unread_msg['id'])
                    # print str(unread_msg['id'])
                    # 转换objectId to string
                    unread_msg['id'] = str(unread_msg['id'])
                    # print type(unread_msg['create_at'])
                    unread_msg['create_at'] = long(
                        unread_msg['create_at'].strftime('%s')) * 1000
                    unread_msg['other_name'] = unread_msg['from_name']
                    unread_msg['other_avatar'] = unread_msg['from_avatar']
            result = {}
            result['errCode'] = 0
            result['unread_list'] = unread_list
            r = json.dumps(result, ensure_ascii=False)
            logger.debug('r:%s', r)
            logger.debug(type(r))
            self.write(str(r))  # , cls=CJsonEncoder #格式化时间

            # 计数 unreadMsg 清空
            # logger.debug('reset to_id:unreadMsg_%s unreadMsg count to 0', userid)
            # ClassHelper('StatCount').updateOne({'name': 'unreadMsg_' + userid}, {"$set": {'count': 0}},
            #                                    upsert=True)
        except Exception, e:
            logger.error(e)
            msg = traceback.format_exc()
            logger.error(msg)
            self.write(ERR_PARA.message)