def __split_group_message(self, msg: ReliableMessage,
                           members: List[ID]) -> Optional[Content]:
     """ Split group message for each member """
     messages = msg.split(members=members)
     success_list = []
     failed_list = []
     for item in messages:
         if item.delegate is None:
             item.delegate = msg.delegate
         if self.__forward_group_message(msg=item):
             success_list.append(item.receiver)
         else:
             failed_list.append(item.receiver)
     response = ReceiptCommand(message='Group message delivering')
     if len(success_list) > 0:
         response['success'] = ID.revert(success_list)
     if len(failed_list) > 0:
         response['failed'] = ID.revert(failed_list)
         # failed to get keys for this members,
         # query from sender by invite members
         sender = msg.sender
         group = msg.receiver
         cmd = GroupCommand.invite(group=group, members=failed_list)
         self.send_content(sender=None, receiver=sender, content=cmd)
     return response
Beispiel #2
0
 def __split_group_message(self, msg: ReliableMessage) -> Optional[Content]:
     receiver = self.facebook.identifier(msg.envelope.receiver)
     assert receiver.type.is_group(), 'receiver not a group: %s' % receiver
     members = self.facebook.members(identifier=receiver)
     if members is not None:
         messages = msg.split(members=members)
         success_list = []
         failed_list = []
         for item in messages:
             if self.deliver(msg=item) is None:
                 failed_list.append(item.envelope.receiver)
             else:
                 success_list.append(item.envelope.receiver)
         response = ReceiptCommand.new(
             message='Message split and delivering')
         if len(success_list) > 0:
             response['success'] = success_list
         if len(failed_list) > 0:
             response['failed'] = failed_list
         return response