Пример #1
0
    def _on_finish(self, _session, message, transfer):
        self._queued_messages.pop(id(transfer), None)
        transfer.set_finished()

        if message.props.status_code == Soup.Status.CANCELLED:
            self._log.info('Upload cancelled')
            return

        if message.props.status_code in (Soup.Status.OK, Soup.Status.CREATED):
            self._log.info('Upload completed successfully')
            uri = transfer.get_transformed_uri()
            self._text.append(uri)

            if transfer.is_groupchat:
                app.nec.push_outgoing_event(
                    GcMessageOutgoingEvent(None,
                                           account=self._account,
                                           jid=transfer.contact.jid,
                                           message=uri,
                                           automatic_message=False))
            else:
                app.nec.push_outgoing_event(
                    MessageOutgoingEvent(None,
                                         account=self._account,
                                         jid=transfer.contact.jid,
                                         message=uri,
                                         type_='chat',
                                         automatic_message=False))

        else:
            phrase = Soup.Status.get_phrase(message.props.status_code)
            self._log.error('Got unexpected http upload response code: %s',
                            phrase)
            self._raise_information_event('httpupload-response-error', phrase)
Пример #2
0
    def upload_complete(self, response_code, file):
        self.raise_progress_event('close', file)
        if 200 <= response_code < 300:
            log.info("Upload completed successfully")
            message = file.get
            if file.user_data:
                message += '#' + file.user_data
                message = self.convert_to_aegscm(message)
            else:
                self.messages.append(message)

            if file.groupchat:
                app.nec.push_outgoing_event(
                    GcMessageOutgoingEvent(None,
                                           account=self.name,
                                           jid=file.contact.jid,
                                           message=message,
                                           automatic_message=False,
                                           session=file.session))
            else:
                app.nec.push_outgoing_event(
                    MessageOutgoingEvent(None,
                                         account=self.name,
                                         jid=file.contact.jid,
                                         message=message,
                                         keyID=file.keyID,
                                         type_='chat',
                                         automatic_message=False,
                                         session=file.session))

        else:
            log.error('Got unexpected http upload response code: %s',
                      response_code)
            self.raise_information_event('httpupload-response-error',
                                         response_code)
Пример #3
0
    def _send_message(self,
                      jid,
                      message,
                      account,
                      type_='chat',
                      subject=None):
        """
        Can be called from send_chat_message (default when send_message) or
        send_single_message
        """
        if not jid or not message:
            return False

        connected_account = self._get_account_and_contact(account, jid)[0]
        if connected_account:
            connection = app.connections[connected_account]
            sessions = connection.get_sessions(jid)
            if not sessions:
                connection.make_new_session(jid)
            ctrl = app.interface.msg_win_mgr.search_control(
                jid, connected_account)
            if ctrl:
                ctrl.send_message(message)
            else:
                app.nec.push_outgoing_event(
                    MessageOutgoingEvent(
                        None,
                        account=connected_account,
                        jid=jid,
                        message=message,
                        type_=type_,
                        control=ctrl))

            return True
        return False
Пример #4
0
    def execute(self, request):
        account = self.connection.name
        # Forward messages
        events = app.events.get_events(account, types=['chat', 'normal'])
        j, resource = app.get_room_and_nick_from_fjid(self.jid)
        for jid in events:
            for event in events[jid]:
                ev_typ = event.type_
                if ev_typ == 'printed_chat':
                    ev_typ = 'chat'
                app.nec.push_outgoing_event(MessageOutgoingEvent(None,
                    account=account, jid=j, message=event.message, type_=ev_typ,
                    subject=event.subject, resource=resource, forward_from=jid,
                    delayed=event.time_, now=True))

        response, cmd = self.buildResponse(request, status = 'completed')
        cmd.addChild('note', {}, _('The status has been changed.'))

        # if going offline, we need to push response so it won't go into
        # queue and disappear
        self.connection.connection.send(response, now = True)

        # send new status
        app.interface.roster.send_status(self.connection.name, 'offline', '')
        # finish the session
        return False
Пример #5
0
    def _send_single_message(self):
        if not app.account_is_connected(self.account):
            # if offline or connecting
            ErrorDialog(_('Connection not available'),
                        _('Please make sure you are connected with "%s".') %
                        self.account)
            return True
        if isinstance(self._to, list):
            sender_list = []
            for i in self._to:
                if i[0].resource:
                    sender_list.append(i[0].jid + '/' + i[0].resource)
                else:
                    sender_list.append(i[0].jid)
        else:
            sender_list = [j.strip() for j
                           in self._ui.to_entry.get_text().split(',')]

        subject = self._ui.subject_entry.get_text()
        begin, end = self._message_tv_buffer.get_bounds()
        message = self._message_tv_buffer.get_text(begin, end, True)

        recipient_list = []

        for to_whom_jid in sender_list:
            if to_whom_jid in self._completion_dict:
                to_whom_jid = self._completion_dict[to_whom_jid].jid
            try:
                to_whom_jid = helpers.parse_jid(to_whom_jid)
            except helpers.InvalidFormat:
                ErrorDialog(
                    _('Invalid XMPP Address'),
                    _('It is not possible to send a message to %s, this '
                      'XMPP Address is not valid.') % to_whom_jid)
                return True

            if '/announce/' in to_whom_jid:
                con = app.connections[self.account]
                con.get_module('Announce').set_announce(
                    to_whom_jid, subject, message)
                continue

            recipient_list.append(to_whom_jid)

        app.nec.push_outgoing_event(MessageOutgoingEvent(
            None,
            account=self.account,
            jid=recipient_list,
            message=message,
            type_='normal',
            subject=subject))

        self._ui.subject_entry.set_text('') # we sent ok, clear the subject
        self._message_tv_buffer.set_text('') # we sent ok, clear the textview
        return False
Пример #6
0
    def send_single_message(self):
        if app.connections[self.account].connected <= 1:
            # if offline or connecting
            ErrorDialog(_('Connection not available'),
                _('Please make sure you are connected with "%s".') % self.account)
            return True
        if isinstance(self.to, list):
            sender_list = []
            for i in self.to:
                if i[0].resource:
                    sender_list.append(i[0].jid + '/' + i[0].resource)
                else:
                    sender_list.append(i[0].jid)
        else:
            sender_list = [j.strip() for j in self.to_entry.get_text().split(
                ',')]

        subject = self.subject_entry.get_text()
        begin, end = self.message_tv_buffer.get_bounds()
        message = self.message_tv_buffer.get_text(begin, end, True)

        if self.form_widget:
            form_node = self.form_widget.data_form
        else:
            form_node = None

        recipient_list = []

        for to_whom_jid in sender_list:
            if to_whom_jid in self.completion_dict:
                to_whom_jid = self.completion_dict[to_whom_jid].jid
            try:
                to_whom_jid = helpers.parse_jid(to_whom_jid)
            except helpers.InvalidFormat:
                ErrorDialog(_('Invalid JID'),
                    _('It is not possible to send a message to %s, this JID is not '
                    'valid.') % to_whom_jid)
                return True

            if '/announce/' in to_whom_jid:
                app.connections[self.account].send_motd(to_whom_jid, subject,
                    message)
                continue

            recipient_list.append(to_whom_jid)

        app.nec.push_outgoing_event(MessageOutgoingEvent(None,
            account=self.account, jid=recipient_list, message=message,
            type_='normal', subject=subject, form_node=form_node))

        self.subject_entry.set_text('') # we sent ok, clear the subject
        self.message_tv_buffer.set_text('') # we sent ok, clear the textview
Пример #7
0
 def _on_send_clicked(self, _button):
     form = self._form_widget.get_submit_form()
     app.nec.push_outgoing_event(
         MessageOutgoingEvent(None,
                              account=self._account,
                              jid=self._jid,
                              form_node=form,
                              is_loggable=False))
     control = find_control(self._account, self._jid)
     if control is None:
         return
     control.add_status_message('Form has successfully been sent')
     self.destroy()
Пример #8
0
    def execute(self, request):
        account = self.connection.name
        # Forward messages
        events = app.events.get_events(account, types=['chat', 'normal',
            'printed_chat'])
        j, resource = app.get_room_and_nick_from_fjid(self.jid)
        for jid in events:
            for event in events[jid]:
                ev_typ = event.type_
                if ev_typ == 'printed_chat':
                    ev_typ = 'chat'
                app.nec.push_outgoing_event(MessageOutgoingEvent(None,
                    account=account, jid=j, message=event.message, type_=ev_typ,
                    subject=event.subject, resource=resource, forward_from=jid,
                    delayed=event.time_))

        # Inform other client of completion
        response, cmd = self.buildResponse(request, status = 'completed')
        cmd.addChild('note', {}, _('All unread messages have been forwarded.'))

        self.connection.connection.send(response)

        return False    # finish the session
Пример #9
0
    def set_chatstate(self, contact: ContactT, state: State) -> None:
        # Dont send chatstates to ourself
        if self._con.get_own_jid().bareMatch(contact.jid):
            return

        if contact.jid in self._blocked:
            return

        self.remove_delay_timeout(contact)
        current_state = self._chatstates.get(contact.jid)
        setting = self._get_chatstate_setting(contact)
        if setting == 'disabled':
            # Send a last 'active' state after user disabled chatstates
            if current_state is not None:
                self._log.info('Disabled for %s', contact.jid)
                self._log.info('Send last state: %-10s - %s',
                               State.ACTIVE, contact.jid)

                event_attrs = {'account': self._account,
                               'jid': contact.jid,
                               'chatstate': str(State.ACTIVE)}

                if contact.is_groupchat:
                    if contact.is_connected:
                        app.nec.push_outgoing_event(
                            GcMessageOutgoingEvent(None, **event_attrs))
                else:
                    app.nec.push_outgoing_event(
                        MessageOutgoingEvent(None, **event_attrs))

            self._chatstates.pop(contact.jid, None)
            self._last_mouse_activity.pop(contact.jid, None)
            self._last_keyboard_activity.pop(contact.jid, None)
            return

        if not contact.is_groupchat:
            # Dont leak presence to contacts
            # which are not allowed to see our status
            if not contact.is_pm_contact:
                if contact and contact.sub in ('to', 'none'):
                    self._log.info('Contact not subscribed: %s', contact.jid)
                    return

            if contact.show == 'offline':
                self._log.info('Contact offline: %s', contact.jid)
                return

            if not contact.supports(nbxmpp.NS_CHATSTATES):
                self._log.info('Chatstates not supported: %s', contact.jid)
                return

        if state in (State.ACTIVE, State.COMPOSING):
            self._last_mouse_activity[contact.jid] = time.time()

        if setting == 'composing_only':
            if state in (State.INACTIVE, State.GONE):
                state = State.ACTIVE

        if current_state == state:
            return

        self._log.info('Send: %-10s - %s', state, contact.jid)

        event_attrs = {'account': self._account,
                       'jid': contact.jid,
                       'chatstate': str(state)}

        if contact.is_groupchat:
            if contact.is_connected:
                app.nec.push_outgoing_event(
                    GcMessageOutgoingEvent(None, **event_attrs))
        else:
            app.nec.push_outgoing_event(
                MessageOutgoingEvent(None, **event_attrs))

        self._chatstates[contact.jid] = state