Example #1
0
    def upsert_lookups_for_participants(self, user, participants):
        """
        Ensure that participants lookup and hash lookup tables are filled
        for these participants

        :param user:
        :param participants: a collection of parameters/Participant
        :type uris: set
        :return: Discussion
        """
        if not participants:
            raise Exception(
                "missing mandatory property to create lookup entry")

        uris = hash_participants_uri(participants)
        self.uris = uris['uris']
        self.uris_hash = uris['hash']
        hash_lookup = ParticipantHash.find(user_id=user.user_id,
                                           kind="uris",
                                           key=uris['hash'])
        if len(hash_lookup) > 0:
            self.participants = hash_lookup[0].components
            self.participants_hash = hash_lookup[0].value
        else:
            parts = participants_from_uris(user, uris['uris'], uris['hash'])
            self.participants = parts['components']
            self.participants_hash = parts['hash']

        return self
Example #2
0
 def collection_post(self):
     parts = self.request.swagger_data['participants']
     participants = []
     for part in parts:
         participant = Participant()
         participant.address = part['address']
         participant.label = part['label']
         participant.protocol = part['protocol']
         participant.contact_id = part.get('contact_ids', [])
         participants.append(participant)
     uris = hash_participants_uri(participants)
     return {'hash': uris['hash'], 'discussion_id': uris['hash']}
Example #3
0
    def lookup_discussion_sequence(self, mail, message):
        """
        Return list of lookups (type, value) from a mail message
        and the first lookup'hash from that list
        """
        seq = []

        # lists lookup first
        lists = []
        for list_id in mail.extra_parameters.get('lists', []):
            lists.append(list_id)
        if len(lists) > 0:
            # list_ids are considered `participants`
            # build uris' hash and upsert lookup tables
            participants = []
            for list_id in lists:
                participant = Participant()
                participant.address = list_id.lower()
                participant.protocol = 'email'
                participant.type = 'list-id'
                participants.append(participant)
                discuss = Discussion(self.user)
                discuss.upsert_lookups_for_participants(participants)
                # add list-id as a participant to the message
                message.participants.append(participant)
            hash = hash_participants_uri(participants)
            seq.append(('list', hash['hash']))

        # then participants
        seq.append(('hash', message.hash_participants))

        # try to link message to external thread's root message-id
        #        if len(message.external_references["ancestors_ids"]) > 0:
        #            seq.append(("thread",
        #                        message.external_references["ancestors_ids"][0]))
        #        elif message.external_references["parent_id"]:
        #            seq.append(("thread", message.external_references["parent_id"]))
        #        elif message.external_references["message_id"]:
        #            seq.append(("thread", message.external_references["message_id"]))

        return seq, seq[0][1]
 def hash_participants(self):
     ids_hash = hash_participants_uri(self.participants)
     return ids_hash['hash']