コード例 #1
0
ファイル: mongoapi.py プロジェクト: pdxwebdev/yadaproject
 def getFriendRequest(self, data, decrypted):
     posts = []
     connection = Connection('localhost',27021)
     db = connection.yadaserver
     
     friend = db.command(
             {
                 "aggregate" : "identities", "pipeline" : [
                     {
                         "$match" : {
                             "public_key" : data['public_key']
                         }
                     },
                     {
                         "$match" : {
                             "data.friends" : { "$not" : {"$size" : 0}}
                         }
                     },
                     {
                         "$project" : {
                             "friend" : "$data.friends",
                         }
                     },
                     {
                         "$unwind" : "$friend"
                      },
                     {
                         "$match" : {
                             "friend.data.routed_friend_requests" : { "$not" : {"$size" : 0}}
                         }
                     },
                     {
                         "$unwind" : "$friend.data.routed_friend_requests"
                     },
                     {
                         "$match" : {
                             "friend.data.routed_friend_requests.public_key" : decrypted['public_key']
                         }
                     },
                     {
                         "$project" : {
                                       "routed_public_key" :"$friend.data.routed_friend_requests.routed_public_key",
                                       "friendRequest" : "$friend.data.routed_friend_requests"
                                     }
                     },
                 ]
             })['result']
             
     localFriendRequest = db.command(
         {
             "aggregate" : "identities", "pipeline" : [
                 {
                     "$match" : {
                         "public_key" : data['public_key']
                     }
                 },
                 {
                     "$match" : {
                         "friend_requests" : { "$not" : {"$size" : 0}}
                     }
                 },
                 {
                     "$unwind" : "$friend_requests"
                  },
                 {
                     "$match" : {
                         "friend_requests.public_key" : decrypted['public_key']
                     }
                 },
                 {
                     "$project" : {
                                   "request_public_key" : "$friend_requests.public_key",
                                   "friendRequest" : "$friend_requests"
                                 }
                 },
             ]
         })['result']
         
     try:
         friend = friend[0]
     except:
         friend = localFriendRequest[0]
     friendNode = Node(friend['friendRequest'])
     friendNode.stripIdentityAndFriendsForProtocolV1()
     return friendNode.get()