예제 #1
0
    def staffJoined(self, muc_user):
        """To be called after the staffmember has joined
        the room at the jabber-server.
        """

        if not self.chat:
            chat = Chat(created_at=datetime.datetime.now(), subject=_('Chat'))
            chat.save()
            self.chat = chat

        if not self.staff:
            user = AccessToken.objects.get(jid=muc_user.real_jid).created_by
            staff = Participant(
                conversation=self.chat,
                name=muc_user.nick,
                user=user,
                role=Participant.ROLE_STAFF
            )
            staff.save()
            self.staff = staff

        self.staff_nick = muc_user.nick

        if self.getStatus() == "available":
            self.setStatus("staffWaiting")
        elif self.getStatus() == "availableForInvitation":
            self.setStatus("staffWaitingForInvitee")
        else:
            raise StatusError("staff joining room while not room status is not 'available' or 'availableForInvitation'")
예제 #2
0
    def import_chats(self):
        for c in self.data['chats']:
            print '>>  Chat(%s)' % str(c)

            new_chat = Chat(created_at=c['started_at'], subject=c['subject'])
            new_chat.save()
            self.chat_ids[c['id']] = new_chat.id

            if not c['staff_name'] is None:
                try:
                    staff_user = User.objects.filter(username__exact=c['staff_name'])[0]
                except:
                    print "Couldnt find associated User with username: %s" % c['staff_name']
                    staff_user = None

                staff = Participant(conversation=new_chat, name=c['staff_name'], user=staff_user, role=Participant.ROLE_STAFF, ip_hash=c['staff_ip'])
                staff.save()

            if not c['client_name'] is None:
                client = Participant(conversation=new_chat, name=c['client_name'], user=None, role=Participant.ROLE_CLIENT, ip_hash=c['client_ip'], blocked=c['client_blocked'], blocked_at=c['client_blocked_at'])
                client.save(keep_blocked_at=True)

            for msg in c['messages']:
                self.print_indent('>>  Message(%s)' % str(msg))
                
                if msg['who'] == 'CLIENT':
                    sender = client
                else:
                    sender = staff

                new_chat.create_message(sender=sender, sender_name=sender.name, created_at=msg['created_at'], body=msg['body'], event=msg['event'])
예제 #3
0
    def userJoined(self, muc_user):
        """To be called after the staffmember has joined
        the room at the jabber-server.
        """

        if not self.chat:
            chat = Chat(created_at=datetime.datetime.now(), subject=_('Chat'))
            chat.save()
            self.chat = chat

        ac = AccessToken.objects.get(jid=muc_user.real_jid)
        if ac.role == Participant.ROLE_STAFF:
            if not self.staff:
                staff = Participant(
                    conversation=self.chat,
                    name=muc_user.nick,
                    user=ac.created_by,
                    role=Participant.ROLE_STAFF
                    )
                staff.save()
                self.staff = staff
                self.staff_nick = muc_user.nick
        else:
            if not self.client:
                client = Participant(
                    conversation=self.chat,
                    name=muc_user.nick,
                    user=ac.created_by,
                    role=Participant.ROLE_CLIENT
                    )
                client.save()
                self.client = client
                self.client_nick = muc_user.nick

        status = self.getStatus()
        if status in ("available", "abandoned"):
            self.setStatus("waiting")
        elif status in ("waiting", "lost"):
            self.setStatus("chatting")
        else:
            raise StatusError("client joining room while room in status %s" % status)
예제 #4
0
    def clientJoined(self, muc_user):
        """To be called after a client has joined
           the room at the jabber-server.
           """

        if not self.chat:
            chat = Chat(created_at=datetime.datetime.now(), subject=_('Chat'))
            chat.save()
            self.chat = chat

        if not self.client:
            client = Participant(
                conversation=self.chat, name=muc_user.nick, role=Participant.ROLE_CLIENT)

            # store participant to access token so that we're able to block
            accessToken = AccessToken.objects.filter(jid=muc_user.real_jid).filter(role=Participant.ROLE_CLIENT)[0]
            client.ip_hash = accessToken.ip_hash

            # link form entry from questionnaire to participant
            conversationFormEntry = None
            try:
                waitingRoomToken = WaitingRoomToken.objects.get(token=accessToken)
                if not waitingRoomToken.conversation_form_entry is None:
                    conversationFormEntry = WaitingRoomToken.objects.get(token=accessToken).conversation_form_entry
                    conversationFormEntry.conversation=self.chat
                    conversationFormEntry.save()
            except WaitingRoomToken.DoesNotExist:
                # HU!
                pass

            client.save()

            self.client = client
            self.client_nick = muc_user.nick

        if self.getStatus() in ("staffWaiting", "staffWaitingForInvitee"):
            self.setStatus("chatting")
            if not conversationFormEntry is None:
                return conversationFormEntry.entry
        else:
            raise StatusError("client joining room while not room status is not 'staffWaiting' or 'staffWaitingForInvitee'")