Пример #1
0
 def process_key_discovery(self, msg, payload):
     """Discover public keys related to a new contact identifier."""
     if 'user_id' not in payload or 'contact_id' not in payload:
         raise Exception('Invalid contact_update structure')
     user = User.get(payload['user_id'])
     contact = Contact(user.user_id, contact_id=payload['contact_id'])
     contact.get_db()
     contact.unmarshall_db()
     manager = ContactPublicKeyManager()
     founds = []
     for ident in payload.get('emails', []):
         log.info('Process email identity {0}'.format(ident['address']))
         discovery = manager.process_identity(user, contact,
                                              ident['address'], 'email')
         if discovery:
             founds.append(discovery)
     for ident in payload.get('identities', []):
         log.info('Process identity {0}:{1}'.format(ident['type'],
                                                    ident['name']))
         discovery = manager.process_identity(user, contact, ident['name'],
                                              ident['type'])
         if discovery:
             founds.append(discovery)
     if founds:
         log.info('Found %d results' % len(founds))
         self._process_results(user, contact, founds)
Пример #2
0
 def process_update(self, msg, payload):
     """Process a contact update message."""
     # XXX validate payload structure
     if 'user_id' not in payload or 'contact_id' not in payload:
         raise Exception('Invalid contact_update structure')
     user = User.get(payload['user_id'])
     contact = Contact(user.user_id, contact_id=payload['contact_id'])
     contact.get_db()
     contact.unmarshall_db()
     qualifier = ContactMessageQualifier(user)
     log.info('Will process update for contact {0} of user {1}'.format(
         contact.contact_id, user.user_id))
     qualifier.process(contact)