Philipp Hörist pushed to branch master at gajim / gajim

Commits:

5 changed files:

Changes:

  • gajim/common/const.py
    ... ... @@ -205,6 +205,7 @@ class MUCJoinedState(Enum):
    205 205
         JOINED = 'joined'
    
    206 206
         NOT_JOINED = 'not joined'
    
    207 207
         JOINING = 'joining'
    
    208
    +    CREATING = 'creating'
    
    208 209
         CAPTCHA_REQUEST = 'captcha in progress'
    
    209 210
         CAPTCHA_FAILED = 'captcha failed'
    
    210 211
     
    

  • gajim/common/modules/mam.py
    ... ... @@ -112,6 +112,11 @@ class MAM(BaseModule):
    112 112
             if properties.type.is_groupchat:
    
    113 113
                 archive_jid = properties.jid.getBare()
    
    114 114
                 disco_info = app.logger.get_last_disco_info(archive_jid)
    
    115
    +            if disco_info is None:
    
    116
    +                # This is the case on MUC creation
    
    117
    +                # After MUC configuration we receive a configuration change
    
    118
    +                # message before we had the chance to disco the new MUC
    
    119
    +                return
    
    115 120
                 namespace = disco_info.mam_namespace
    
    116 121
                 timestamp = properties.timestamp
    
    117 122
                 if namespace is None:
    

  • gajim/common/modules/muc.py
    ... ... @@ -149,6 +149,13 @@ class MUC(BaseModule):
    149 149
             else:
    
    150 150
                 self._join(muc_data)
    
    151 151
     
    
    152
    +    def create(self, muc_data):
    
    153
    +        if not app.account_is_connected(self._account):
    
    154
    +            return
    
    155
    +
    
    156
    +        self._muc_data[muc_data.jid] = muc_data
    
    157
    +        self._create(muc_data)
    
    158
    +
    
    152 159
         def _on_disco_result(self, result):
    
    153 160
             if is_error_result(result):
    
    154 161
                 self._log.info('Disco %s failed: %s', result.jid, result.get_text())
    
    ... ... @@ -179,6 +186,20 @@ class MUC(BaseModule):
    179 186
             self._set_muc_state(muc_data.jid, MUCJoinedState.JOINING)
    
    180 187
             self._con.connection.send(presence)
    
    181 188
     
    
    189
    +    def _create(self, muc_data):
    
    190
    +        show = helpers.get_xmpp_show(app.SHOW_LIST[self._con.connected])
    
    191
    +
    
    192
    +        presence = self._con.get_module('Presence').get_presence(
    
    193
    +            muc_data.occupant_jid,
    
    194
    +            show=show,
    
    195
    +            status=self._con.status)
    
    196
    +
    
    197
    +        presence.setTag(nbxmpp.NS_MUC + ' x')
    
    198
    +
    
    199
    +        self._log.info('Create MUC: %s', muc_data.jid)
    
    200
    +        self._set_muc_state(muc_data.jid, MUCJoinedState.CREATING)
    
    201
    +        self._con.connection.send(presence)
    
    202
    +
    
    182 203
         def leave(self, room_jid, reason=None):
    
    183 204
             self._log.info('Leave MUC: %s', room_jid)
    
    184 205
             self._remove_join_timeout(room_jid)
    
    ... ... @@ -236,13 +257,8 @@ class MUC(BaseModule):
    236 257
                     error=result))
    
    237 258
                 return
    
    238 259
     
    
    239
    -        self._log.info('Configuration finished: %s', result.jid)
    
    240
    -        app.nec.push_incoming_event(NetworkEvent(
    
    241
    -            'muc-configuration-finished',
    
    242
    -            account=self._account,
    
    243
    -            room_jid=result.jid))
    
    244
    -
    
    245
    -        self._con.get_module('Discovery').disco_muc(result.jid)
    
    260
    +        self._con.get_module('Discovery').disco_muc(
    
    261
    +            result.jid, callback=self._on_disco_result_after_config)
    
    246 262
     
    
    247 263
             # If this is an automatic room creation
    
    248 264
             try:
    
    ... ... @@ -258,6 +274,19 @@ class MUC(BaseModule):
    258 274
             for jid in invites:
    
    259 275
                 self.invite(result.jid, jid)
    
    260 276
     
    
    277
    +    def _on_disco_result_after_config(self, result):
    
    278
    +        if is_error_result(result):
    
    279
    +            self._log.info('Disco %s failed: %s', result.jid, result.get_text())
    
    280
    +            return
    
    281
    +
    
    282
    +        self._room_join_complete(self._get_muc_data(result.jid))
    
    283
    +
    
    284
    +        self._log.info('Configuration finished: %s', result.jid)
    
    285
    +        app.nec.push_incoming_event(NetworkEvent(
    
    286
    +            'muc-configuration-finished',
    
    287
    +            account=self._account,
    
    288
    +            room_jid=result.jid))
    
    289
    +
    
    261 290
         def update_presence(self, auto=False):
    
    262 291
             mucs = self.get_mucs_with_state([MUCJoinedState.JOINED,
    
    263 292
                                              MUCJoinedState.JOINING])
    
    ... ... @@ -345,6 +374,14 @@ class MUC(BaseModule):
    345 374
                                      room_jid=room_jid,
    
    346 375
                                      error=properties.error))
    
    347 376
     
    
    377
    +        elif muc_data.state == MUCJoinedState.CREATING:
    
    378
    +            self._set_muc_state(room_jid, MUCJoinedState.NOT_JOINED)
    
    379
    +            app.nec.push_incoming_event(
    
    380
    +                NetworkEvent('muc-creation-failed',
    
    381
    +                             account=self._account,
    
    382
    +                             room_jid=room_jid,
    
    383
    +                             error=properties.error))
    
    384
    +
    
    348 385
             elif muc_data.state == MUCJoinedState.CAPTCHA_REQUEST:
    
    349 386
                 app.nec.push_incoming_event(
    
    350 387
                     NetworkEvent('muc-captcha-error',
    
    ... ... @@ -407,15 +444,19 @@ class MUC(BaseModule):
    407 444
                 if properties.is_muc_self_presence:
    
    408 445
                     self._log.info('Self presence: %s', properties.jid)
    
    409 446
                     if muc_data.state == MUCJoinedState.JOINING:
    
    410
    -                    self._start_join_timeout(room_jid)
    
    411 447
                         if (properties.is_nickname_modified or
    
    412 448
                                 muc_data.nick != properties.muc_nickname):
    
    413 449
                             muc_data.nick = properties.muc_nickname
    
    414 450
                             self._log.info('Server modified nickname to: %s',
    
    415 451
                                            properties.muc_nickname)
    
    452
    +
    
    453
    +                elif muc_data.state == MUCJoinedState.CREATING:
    
    454
    +                    if properties.is_new_room:
    
    455
    +                        self.configure_room(room_jid)
    
    456
    +
    
    457
    +                self._start_join_timeout(room_jid)
    
    416 458
                     self._raise_muc_event('muc-self-presence', properties)
    
    417
    -                if properties.is_new_room:
    
    418
    -                    self.configure_room(room_jid)
    
    459
    +
    
    419 460
                 else:
    
    420 461
                     self._log.info('User joined: %s', properties.jid)
    
    421 462
                     self._raise_muc_event('muc-user-joined', properties)
    
    ... ... @@ -592,19 +633,21 @@ class MUC(BaseModule):
    592 633
     
    
    593 634
             muc_data = self._get_muc_data(room_jid)
    
    594 635
             if muc_data.state == MUCJoinedState.JOINING:
    
    595
    -            self._remove_join_timeout(room_jid)
    
    596
    -            self._set_muc_state(room_jid, MUCJoinedState.JOINED)
    
    597
    -
    
    636
    +            self._room_join_complete(muc_data)
    
    598 637
                 app.nec.push_incoming_event(
    
    599 638
                     NetworkEvent('muc-joined',
    
    600 639
                                  account=self._account,
    
    601
    -                             room_jid=room_jid))
    
    640
    +                             room_jid=muc_data.jid))
    
    641
    +
    
    642
    +    def _room_join_complete(self, muc_data):
    
    643
    +        self._remove_join_timeout(muc_data.jid)
    
    644
    +        self._set_muc_state(muc_data.jid, MUCJoinedState.JOINED)
    
    602 645
     
    
    603
    -            # We successfully joined a MUC, set add bookmark with autojoin
    
    604
    -            self._con.get_module('Bookmarks').modify(muc_data.jid,
    
    605
    -                                                     autojoin=True,
    
    606
    -                                                     password=muc_data.password,
    
    607
    -                                                     nick=muc_data.nick)
    
    646
    +        # We successfully joined a MUC, set add bookmark with autojoin
    
    647
    +        self._con.get_module('Bookmarks').modify(muc_data.jid,
    
    648
    +                                                 autojoin=True,
    
    649
    +                                                 password=muc_data.password,
    
    650
    +                                                 nick=muc_data.nick)
    
    608 651
     
    
    609 652
         def _on_voice_request(self, _con, _stanza, properties):
    
    610 653
             if not properties.is_voice_request:
    

  • gajim/groupchat_control.py
    ... ... @@ -305,6 +305,7 @@ class GroupchatControl(ChatControlBase):
    305 305
             settings_menu.set_menu_model(self.control_menu)
    
    306 306
     
    
    307 307
             self._event_handlers = [
    
    308
    +            ('muc-creation-failed', ged.GUI1, self._on_muc_creation_failed),
    
    308 309
                 ('muc-joined', ged.GUI1, self._on_muc_joined),
    
    309 310
                 ('muc-join-failed', ged.GUI1, self._on_muc_join_failed),
    
    310 311
                 ('muc-user-joined', ged.GUI1, self._on_user_joined),
    
    ... ... @@ -325,6 +326,7 @@ class GroupchatControl(ChatControlBase):
    325 326
                 ('muc-voice-approval', ged.GUI1, self._on_voice_approval),
    
    326 327
                 ('muc-disco-update', ged.GUI1, self._on_disco_update),
    
    327 328
                 ('muc-configuration-finished', ged.GUI1, self._on_configuration_finished),
    
    329
    +            ('muc-configuration-failed', ged.GUI1, self._on_configuration_failed),
    
    328 330
                 ('gc-message-received', ged.GUI1, self._nec_gc_message_received),
    
    329 331
                 ('mam-decrypted-message-received', ged.GUI1, self._nec_mam_decrypted_message_received),
    
    330 332
                 ('update-gc-avatar', ged.GUI1, self._nec_update_avatar),
    
    ... ... @@ -1695,8 +1697,15 @@ class GroupchatControl(ChatControlBase):
    1695 1697
     
    
    1696 1698
         @event_filter(['account', 'room_jid'])
    
    1697 1699
         def _on_configuration_finished(self, _event):
    
    1700
    +        self.got_connected()
    
    1701
    +        self._show_page('groupchat')
    
    1698 1702
             self.add_info_message(_('A new group chat has been created'))
    
    1699 1703
     
    
    1704
    +    @event_filter(['account', 'room_jid'])
    
    1705
    +    def _on_configuration_failed(self, _event):
    
    1706
    +        self.xml.error_label.set_text(to_user_string(event.error))
    
    1707
    +        self._show_page('error')
    
    1708
    +
    
    1700 1709
         @event_filter(['account', 'room_jid'])
    
    1701 1710
         def _on_nickname_changed(self, event):
    
    1702 1711
             nick = event.properties.muc_nickname
    
    ... ... @@ -1950,6 +1959,11 @@ class GroupchatControl(ChatControlBase):
    1950 1959
             self._show_page('error')
    
    1951 1960
             self.autorejoin = False
    
    1952 1961
     
    
    1962
    +    @event_filter(['account', 'room_jid'])
    
    1963
    +    def _on_muc_creation_failed(self, event):
    
    1964
    +        self.xml.error_label.set_text(to_user_string(event.error))
    
    1965
    +        self._show_page('error')
    
    1966
    +
    
    1953 1967
         @event_filter(['account', 'room_jid'])
    
    1954 1968
         def _on_presence_error(self, event):
    
    1955 1969
             error_message = to_user_string(event.properties.error)
    

  • gajim/gui_interface.py
    ... ... @@ -1564,7 +1564,7 @@ class Interface:
    1564 1564
         def create_groupchat(self, account, room_jid, config=None):
    
    1565 1565
             muc_data = self._create_muc_data(account, room_jid, None, config)
    
    1566 1566
             self.create_groupchat_control(account, room_jid, muc_data)
    
    1567
    -        app.connections[account].get_module('MUC').join(muc_data)
    
    1567
    +        app.connections[account].get_module('MUC').create(muc_data)
    
    1568 1568
     
    
    1569 1569
         def show_or_join_groupchat(self, account, room_jid, **kwargs):
    
    1570 1570
             if self.show_groupchat(account, room_jid):