Exemplo n.º 1
0
 def record(self):
     return deserialize_record({
         '_id': 'conversation/1',
         '_access': None,
         '_ownerID': 'user1',
         'participant_ids': ['user1', 'user2'],
         'admin_ids': ['user1']
     })
Exemplo n.º 2
0
 def record(self):
     return deserialize_record({
         '_id': 'message/1',
         '_access': None,
         '_ownerID': 'user1',
         'conversation_id': 'conversation1',
         'body': 'hihi'
     })
 def original_record(self):
     return deserialize_record({
         '_id': 'conversation/1',
         '_access': None,
         '_ownerID': 'user1',
         'participant_ids': ['user2', 'user3'],
         'admin_ids': ['user1']
     })
 def invalid_record(self):
     return deserialize_record({
         '_id': 'conversation/invalid',
         '_access': None,
         '_ownerID': 'user1',
         'participant_ids': ['user1', 'user2'],
         'admin_ids': ['user10']
     })
 def original_record(self):
     return deserialize_record({
         '_id': 'message/1',
         '_access': None,
         '_ownerID': 'user1',
         'conversation_id': 'conversation1',
         'body': 'hihi'
     })
 def test_conversation__paticipant_id_format(self):
     wrong_user_id = deserialize_record({
         '_id': 'conversation/wronguserid',
         '_access': None,
         '_ownerID': 'user1',
         'participant_ids': ['user/user1', 'user/user2'],
         'admin_ids': []
     })
     with self.assertRaises(SkygearChatException) as cm:
         validate_conversation(wrong_user_id)
 def test_conversation_paticipant_id_format(self):
     conv_with_wrong_user_id = deserialize_record({
         '_id': 'conversation/wronguserid',
         '_access': None,
         '_ownerID': 'user1',
         'participant_ids': ['user/user1', 'user/user2'],
         'admin_ids': []
     })
     with self.assertRaises(SkygearChatException) as cm:
         Conversation(conv_with_wrong_user_id).validate()
Exemplo n.º 8
0
 def conversation(self):
     return deserialize_record(
         {
             "_id": "conversation/1",
             "_access": None,
             "_ownerID": "user1",
             "participant_ids": ["user1", "user2"],
             "admin_ids": ["user1"],
         }
     )
 def original_record(self):
     return deserialize_record({
         '_id': 'message/1',
         '_access': None,
         '_ownerID': 'user1',
         'conversation_id': {
             '$type': 'ref',
             '$id': 'conversation/1'
         },
         'body': 'hihi'
     })
Exemplo n.º 10
0
 def record(self):
     return deserialize_record({
         '_id': 'message/1',
         '_access': None,
         '_ownerID': 'user1',
         'conversation_id': {
             '$type': 'ref',
             '$id': 'conversation/1'
         },
         'body': 'hihi'
     })
 def record(self):
     return deserialize_record({
         '_id': 'message/1',
         '_access': None,
         '_ownerID': 'user1',
         'conversation': {
             '$type': 'ref',
             '$id': 'conversation/1'
         },
         'body': 'hihi',
         'deleted': False
     })
Exemplo n.º 12
0
    def fetch(cls, message_id: str):
        """
        Fetch the message from skygear.

        The conversation record is also fetched using eager load.
        """
        # FIXME checking should not be necessary, passing correct type
        # is the responsibility of the caller.
        # message_id can be Reference, recordID or string
        if isinstance(message_id, Reference):
            message_id = message_id.recordID.key
        if isinstance(message_id, RecordID):
            message_id = message_id.key
        if not isinstance(message_id, str):
            raise ValueError()

        container = SkygearContainer(api_key=skyoptions.masterkey,
                                     user_id=current_user_id())
        response = container.send_action(
            'record:query',
            {
                'database_id': '_union',
                'record_type': 'message',
                'limit': 1,
                'sort': [],
                'count': False,
                'predicate': [
                    'eq', {
                        '$type': 'keypath',
                        '$val': '_id'
                    },
                    message_id
                ]
            }
        )

        if 'error' in response:
            raise SkygearChatException(response['error'])

        if len(response['result']) == 0:
            raise SkygearChatException('no messages found',
                                       code=ResourceNotFound)

        obj = cls()
        messageDict = response['result'][0]
        obj.record = deserialize_record(messageDict)
        # Conversation is in publicDB, do cannot transient include
        print(obj.record['conversation_id'].recordID.key)
        response = container.send_action(
            'record:query',
            {
                'database_id': '_public',
                'record_type': 'conversation',
                'limit': 1,
                'sort': [],
                'count': False,
                'predicate': [
                    'eq', {
                        '$type': 'keypath',
                        '$val': '_id'
                    },
                    obj.record['conversation_id'].recordID.key
                ]
            }
        )
        if len(response['result']) == 0:
            raise SkygearChatException("no conversation found")
        conversationDict = response['result'][0]
        obj.conversationRecord = deserialize_record(conversationDict)
        return obj