def members(self, identifier: ID) -> Optional[List[ID]]: # check for broadcast if identifier.is_broadcast: # members of broadcast group name = identifier.name if name is None: length = 0 else: length = len(name) if length == 0 or (length == 8 and name == 'everyone'): # Consensus: the member of group 'everyone@everywhere' # 'anyone@anywhere' member = ANYONE owner = ANYONE else: # DISCUSS: who should be the member of group 'xxx@everywhere'? # 'anyone@anywhere', or 'xxx.member@anywhere' member = name + '.member@anywhere' owner = name + '.owner@anywhere' member = ID.parse(identifier=member) owner = ID.parse(identifier=owner) if member == owner: return [owner] else: return [owner, member]
def _broadcast_members(self, identifier: ID) -> List[ID]: name = self.__id_name(identifier=identifier) if name is None: # Consensus: the member of group 'everyone@everywhere' # 'anyone@anywhere' return [ANYONE] else: # DISCUSS: who should be the member of group 'xxx@everywhere'? # 'anyone@anywhere', or 'xxx.member@anywhere' owner = ID.parse(identifier=name + '.owner@anywhere') member = ID.parse(identifier=name + '.member@anywhere') return [owner, member]
def _broadcast_owner(self, identifier: ID) -> Optional[ID]: name = self.__id_name(identifier=identifier) if name is None: # Consensus: the owner of group 'everyone@everywhere' # 'anyone@anywhere' return ANYONE else: # DISCUSS: who should be the owner of group 'xxx@everywhere'? # 'anyone@anywhere', or 'xxx.owner@anywhere' return ID.parse(identifier=name + '.owner@anywhere')
def _broadcast_founder(self, identifier: ID) -> Optional[ID]: name = self.__id_name(identifier=identifier) if name is None: # Consensus: the founder of group 'everyone@everywhere' # 'Albert Moky' return FOUNDER else: # DISCUSS: who should be the founder of group 'xxx@everywhere'? # 'anyone@anywhere', or 'xxx.founder@anywhere' return ID.parse(identifier=name + '.founder@anywhere')
def owner(self, identifier: ID) -> Optional[ID]: # check for broadcast if identifier.is_broadcast: # owner of broadcast group name = identifier.name if name is None: length = 0 else: length = len(name) if length == 0 or (length == 8 and name == 'everyone'): # Consensus: the owner of group 'everyone@everywhere' # 'anyone@anywhere' owner = ANYONE else: # DISCUSS: who should be the owner of group 'xxx@everywhere'? # 'anyone@anywhere', or 'xxx.owner@anywhere' owner = name + '.owner@anywhere' return ID.parse(identifier=owner) # check group type if identifier.type == NetworkType.POLYLOGUE: # Polylogue's owner is its founder return self.founder(identifier=identifier)
def founder(self, identifier: ID) -> Optional[ID]: # check for broadcast if identifier.is_broadcast: # founder of broadcast group name = identifier.name if name is None: length = 0 else: length = len(name) if length == 0 or (length == 8 and name == 'everyone'): # Consensus: the founder of group 'everyone@everywhere' # 'Albert Moky' founder = 'moky@anywhere' else: # DISCUSS: who should be the founder of group 'xxx@everywhere'? # 'anyone@anywhere', or 'xxx.founder@anywhere' founder = name + '.founder@anywhere' return ID.parse(identifier=founder) # check group meta g_meta = self.meta(identifier=identifier) if g_meta is None: # FIXME: when group profile was arrived but the meta still on the way, # here will cause founder not found return None # check each member's public key with group meta members = self.members(identifier=identifier) if members is not None: for item in members: u_meta = self.meta(identifier=item) if u_meta is None: # failed to get member's meta continue if g_meta.match_key(key=u_meta.key): # if the member's public key matches with the group's meta, # it means this meta was generated by the member's private key return item
def identifier(self) -> ID: return ID.parse(identifier=self.get('ID'))
def members(self, value: List[ID]): if value is None: self.pop('members', None) else: self['members'] = ID.revert(members=value)
def members(self) -> Optional[List[ID]]: array = self.get('members') if array is not None: # convert all items to ID objects return ID.convert(members=array)
def member(self) -> Optional[ID]: return ID.parse(identifier=self.get('member'))
def envelope_group(envelope: dict) -> Optional[ID]: group = envelope.get('group') if group is not None: return ID.parse(identifier=group)
def envelope_receiver(envelope: dict) -> ID: return ID.parse(identifier=envelope.get('receiver'))
def envelope_sender(envelope: dict) -> ID: return ID.parse(identifier=envelope.get('sender'))
def content_group(content: dict) -> Optional[ID]: group = content.get('group') if group is not None: return ID.parse(identifier=group)