create room instance Args: contacts: contact list topic: room topic Examples: >>> room = await Room.create([contact1, contact2], 'topic') Returns: Room instance
(cls, contacts: List[Contact], topic: str)
| 112 | |
| 113 | @classmethod |
| 114 | async def create(cls, contacts: List[Contact], topic: str) -> Room: |
| 115 | """ |
| 116 | create room instance |
| 117 | Args: |
| 118 | contacts: contact list |
| 119 | topic: room topic |
| 120 | Examples: |
| 121 | >>> room = await Room.create([contact1, contact2], 'topic') |
| 122 | Returns: |
| 123 | Room instance |
| 124 | """ |
| 125 | if not hasattr(contacts, '__len__'): |
| 126 | raise WechatyOperationError('contacts should be list type') |
| 127 | if len(contacts) < 2: |
| 128 | raise WechatyOperationError( |
| 129 | 'contactList need at least 2 contact to create a new room' |
| 130 | ) |
| 131 | |
| 132 | log.info( |
| 133 | 'Room create <%s - %s>', |
| 134 | ','.join([contact.contact_id for contact in contacts]), |
| 135 | topic |
| 136 | ) |
| 137 | |
| 138 | try: |
| 139 | contact_ids = list(map(lambda x: x.contact_id, contacts)) |
| 140 | room_id = await cls.get_puppet(). \ |
| 141 | room_create(contact_ids=contact_ids, topic=topic) |
| 142 | room = cls.load(room_id=room_id) |
| 143 | await room.ready() |
| 144 | return room |
| 145 | except Exception as exception: |
| 146 | message = 'Room create error <%s>' % str(exception.args) |
| 147 | log.error(message) |
| 148 | raise WechatyOperationError(message) |
| 149 | |
| 150 | @classmethod |
| 151 | def _filter_rooms(cls, |
no test coverage detected