Philipp Hörist pushed to branch master at gajim / gajim
Commits:
-
e0557fda
by Philipp Hörist at 2019-07-05T21:51:34Z
-
4acecfef
by Philipp Hörist at 2019-07-05T21:56:29Z
-
d369ff91
by Philipp Hörist at 2019-07-05T22:53:39Z
8 changed files:
- gajim/command_system/implementation/standard.py
- gajim/common/modules/bookmarks.py
- gajim/common/modules/muc.py
- gajim/common/structs.py
- gajim/groupchat_control.py
- gajim/gtk/discovery.py
- gajim/gtk/join_groupchat.py
- gajim/roster_window.py
Changes:
| ... | ... | @@ -308,6 +308,7 @@ class StandardGroupChatCommands(CommandContainer): |
| 308 | 308 |
@command('part', 'close', raw=True, empty=True)
|
| 309 | 309 |
@doc(_("Leave the groupchat, optionally giving a reason, and close tab or window"))
|
| 310 | 310 |
def leave(self, reason):
|
| 311 |
+ self.connection.get_module('MUC').leave(self.room_jid)
|
|
| 311 | 312 |
self.parent_win.remove_tab(self, self.parent_win.CLOSE_COMMAND, reason)
|
| 312 | 313 |
|
| 313 | 314 |
@command(raw=True, empty=True)
|
| ... | ... | @@ -21,6 +21,7 @@ from typing import Optional |
| 21 | 21 |
import copy
|
| 22 | 22 |
|
| 23 | 23 |
import nbxmpp
|
| 24 |
+from nbxmpp.protocol import JID
|
|
| 24 | 25 |
from nbxmpp.util import is_error_result
|
| 25 | 26 |
from nbxmpp.structs import BookmarkData
|
| 26 | 27 |
from nbxmpp.const import BookmarkStoreType
|
| ... | ... | @@ -129,7 +130,7 @@ class Bookmarks(BaseModule): |
| 129 | 130 |
if not bookmark_copy.name:
|
| 130 | 131 |
# No name was given for this bookmark
|
| 131 | 132 |
# Use the first part of JID instead
|
| 132 |
- name = bookmark_copy.jid.split("@")[0]
|
|
| 133 |
+ name = bookmark_copy.jid.getNode()
|
|
| 133 | 134 |
bookmark_copy = bookmark_copy._replace(name=name)
|
| 134 | 135 |
|
| 135 | 136 |
if short_name:
|
| ... | ... | @@ -206,12 +207,33 @@ class Bookmarks(BaseModule): |
| 206 | 207 |
self._account, str(bookmark.jid), bookmark.nick,
|
| 207 | 208 |
bookmark.password, minimize=minimize)
|
| 208 | 209 |
|
| 209 |
- def add_bookmark(self, name, jid, autojoin, password, nick):
|
|
| 210 |
- bookmark = BookmarkData(jid=jid,
|
|
| 211 |
- name=name,
|
|
| 212 |
- autojoin=autojoin,
|
|
| 213 |
- password=password,
|
|
| 214 |
- nick=nick)
|
|
| 210 |
+ def add_bookmark(self,
|
|
| 211 |
+ name: str,
|
|
| 212 |
+ jid: JID,
|
|
| 213 |
+ autojoin: bool,
|
|
| 214 |
+ password: str,
|
|
| 215 |
+ nick: str) -> None:
|
|
| 216 |
+ |
|
| 217 |
+ bookmark = self.get_bookmark_from_jid(jid)
|
|
| 218 |
+ if bookmark is None:
|
|
| 219 |
+ bookmark = BookmarkData(jid=jid,
|
|
| 220 |
+ name=name,
|
|
| 221 |
+ autojoin=autojoin,
|
|
| 222 |
+ password=password,
|
|
| 223 |
+ nick=nick)
|
|
| 224 |
+ self._bookmarks.append(bookmark)
|
|
| 225 |
+ self.store_bookmarks()
|
|
| 226 |
+ |
|
| 227 |
+ elif not bookmark.autojoin:
|
|
| 228 |
+ self.set_autojoin(jid, True)
|
|
| 229 |
+ |
|
| 230 |
+ def set_autojoin(self, jid, enabled):
|
|
| 231 |
+ bookmark = self.get_bookmark_from_jid(jid)
|
|
| 232 |
+ if bookmark is None:
|
|
| 233 |
+ return
|
|
| 234 |
+ self._log.info('Set autojoin for: %s to %s', jid, enabled)
|
|
| 235 |
+ self._bookmarks.remove(bookmark)
|
|
| 236 |
+ bookmark = bookmark._replace(autojoin=enabled)
|
|
| 215 | 237 |
self._bookmarks.append(bookmark)
|
| 216 | 238 |
self.store_bookmarks()
|
| 217 | 239 |
|
| ... | ... | @@ -134,39 +134,39 @@ class MUC(BaseModule): |
| 134 | 134 |
if not app.account_is_connected(self._account):
|
| 135 | 135 |
return
|
| 136 | 136 |
|
| 137 |
- self._muc_data[room_jid] = MUCData(room_jid, nick,
|
|
| 138 |
- password, rejoin, config)
|
|
| 137 |
+ muc_data = MUCData(room_jid, nick, password, rejoin, config)
|
|
| 138 |
+ self._muc_data[room_jid] = muc_data
|
|
| 139 | 139 |
|
| 140 | 140 |
self._con.get_module('Discovery').disco_muc(
|
| 141 |
- room_jid, partial(self._join, room_jid))
|
|
| 141 |
+ room_jid, partial(self._join, muc_data))
|
|
| 142 | 142 |
|
| 143 |
- def _join(self, room_jid):
|
|
| 143 |
+ def _join(self, muc_data):
|
|
| 144 | 144 |
show = helpers.get_xmpp_show(app.SHOW_LIST[self._con.connected])
|
| 145 |
- muc = self._get_muc_data(room_jid)
|
|
| 146 | 145 |
|
| 147 | 146 |
presence = self._con.get_module('Presence').get_presence(
|
| 148 |
- '%s/%s' % (room_jid, muc.nick),
|
|
| 147 |
+ muc_data.occupant_jid,
|
|
| 149 | 148 |
show=show,
|
| 150 | 149 |
status=self._con.status)
|
| 151 | 150 |
|
| 152 | 151 |
muc_x = presence.setTag(nbxmpp.NS_MUC + ' x')
|
| 153 |
- if room_jid is not None:
|
|
| 154 |
- self._add_history_query(muc_x, room_jid, muc.rejoin)
|
|
| 152 |
+ self._add_history_query(muc_x, str(muc_data.jid), muc_data.rejoin)
|
|
| 155 | 153 |
|
| 156 |
- if muc.password is not None:
|
|
| 157 |
- muc_x.setTagData('password', muc.password)
|
|
| 154 |
+ if muc_data.password is not None:
|
|
| 155 |
+ muc_x.setTagData('password', muc_data.password)
|
|
| 158 | 156 |
|
| 159 |
- self._log.info('Join MUC: %s', room_jid)
|
|
| 160 |
- self._set_muc_state(room_jid, MUCJoinedState.JOINING)
|
|
| 157 |
+ self._log.info('Join MUC: %s', muc_data.jid)
|
|
| 158 |
+ self._set_muc_state(muc_data.jid, MUCJoinedState.JOINING)
|
|
| 161 | 159 |
self._con.connection.send(presence)
|
| 162 | 160 |
|
| 163 | 161 |
def leave(self, room_jid):
|
| 164 | 162 |
self._log.info('Leave MUC: %s', room_jid)
|
| 165 | 163 |
self._set_muc_state(room_jid, MUCJoinedState.NOT_JOINED)
|
| 166 |
- muc = self._get_muc_data(room_jid)
|
|
| 164 |
+ muc_data = self._get_muc_data(room_jid)
|
|
| 167 | 165 |
self._con.get_module('Presence').send_presence(
|
| 168 |
- '%s/%s' % (room_jid, muc.nick),
|
|
| 166 |
+ muc_data.occupant_jid,
|
|
| 169 | 167 |
typ='unavailable')
|
| 168 |
+ # We leave a group chat, disable bookmark autojoin
|
|
| 169 |
+ self._con.get_module('Bookmarks').set_autojoin(room_jid, False)
|
|
| 170 | 170 |
|
| 171 | 171 |
def configure_room(self, room_jid):
|
| 172 | 172 |
self._nbxmpp('MUC').request_config(room_jid,
|
| ... | ... | @@ -184,8 +184,8 @@ class MUC(BaseModule): |
| 184 | 184 |
|
| 185 | 185 |
self._log.info('Configure room: %s', result.jid)
|
| 186 | 186 |
|
| 187 |
- muc = self._get_muc_data(result.jid)
|
|
| 188 |
- self._apply_config(result.form, muc.config)
|
|
| 187 |
+ muc_data = self._get_muc_data(result.jid)
|
|
| 188 |
+ self._apply_config(result.form, muc_data.config)
|
|
| 189 | 189 |
self.set_config(result.jid,
|
| 190 | 190 |
result.form,
|
| 191 | 191 |
callback=self._on_config_result)
|
| ... | ... | @@ -245,16 +245,15 @@ class MUC(BaseModule): |
| 245 | 245 |
def update_presence(self, auto=False):
|
| 246 | 246 |
mucs = self.get_mucs_with_state([MUCJoinedState.JOINED,
|
| 247 | 247 |
MUCJoinedState.JOINING])
|
| 248 |
- for muc in mucs:
|
|
| 249 |
- self._send_presence(muc.jid, auto)
|
|
| 248 |
+ for muc_data in mucs:
|
|
| 249 |
+ self._send_presence(muc_data, auto)
|
|
| 250 | 250 |
|
| 251 |
- def _send_presence(self, room_jid, auto):
|
|
| 251 |
+ def _send_presence(self, muc_data, auto):
|
|
| 252 | 252 |
show = app.SHOW_LIST[self._con.connected]
|
| 253 | 253 |
if show in ('invisible', 'offline'):
|
| 254 | 254 |
# FIXME: Check if this
|
| 255 | 255 |
return
|
| 256 | 256 |
|
| 257 |
- muc = self._get_muc_data(room_jid)
|
|
| 258 | 257 |
status = self._con.status
|
| 259 | 258 |
|
| 260 | 259 |
xmpp_show = helpers.get_xmpp_show(show)
|
| ... | ... | @@ -265,13 +264,11 @@ class MUC(BaseModule): |
| 265 | 264 |
idle_time = time.strftime('%Y-%m-%dT%H:%M:%SZ',
|
| 266 | 265 |
time.gmtime(time.time() - idle_sec))
|
| 267 | 266 |
|
| 268 |
- full_jid = '%s/%s' % (room_jid, muc.nick)
|
|
| 269 |
- |
|
| 270 | 267 |
self._log.info('Send presence: %s, show: %s, status: %s, idle_time: %s',
|
| 271 |
- full_jid, xmpp_show, status, idle_time)
|
|
| 268 |
+ muc_data.occupant_jid, xmpp_show, status, idle_time)
|
|
| 272 | 269 |
|
| 273 | 270 |
self._con.get_module('Presence').send_presence(
|
| 274 |
- full_jid,
|
|
| 271 |
+ muc_data.occupant_jid,
|
|
| 275 | 272 |
show=xmpp_show,
|
| 276 | 273 |
status=status,
|
| 277 | 274 |
caps=True,
|
| ... | ... | @@ -317,13 +314,13 @@ class MUC(BaseModule): |
| 317 | 314 |
muc_x.setTag('history', tags)
|
| 318 | 315 |
|
| 319 | 316 |
def _on_muc_presence(self, _con, _stanza, properties):
|
| 320 |
- muc = self._get_muc_data(properties.jid.getBare())
|
|
| 317 |
+ muc_data = self._get_muc_data(properties.muc_jid)
|
|
| 321 | 318 |
if (properties.error.type == Error.CONFLICT and
|
| 322 |
- muc.state == MUCJoinedState.JOINING):
|
|
| 323 |
- muc.nick += '_'
|
|
| 319 |
+ muc_data.state == MUCJoinedState.JOINING):
|
|
| 320 |
+ muc_data.nick += '_'
|
|
| 324 | 321 |
self._log.info('Nickname conflict: %s change to %s',
|
| 325 |
- muc.jid, muc.nick)
|
|
| 326 |
- self._join(muc.jid)
|
|
| 322 |
+ muc_data.jid, muc_data.nick)
|
|
| 323 |
+ self._join(muc_data)
|
|
| 327 | 324 |
return
|
| 328 | 325 |
self._raise_muc_event('muc-presence-error', properties)
|
| 329 | 326 |
|
| ... | ... | @@ -331,7 +328,7 @@ class MUC(BaseModule): |
| 331 | 328 |
if properties.type == PresenceType.ERROR:
|
| 332 | 329 |
return
|
| 333 | 330 |
|
| 334 |
- room_jid = properties.jid.getBare()
|
|
| 331 |
+ room_jid = str(properties.muc_jid)
|
|
| 335 | 332 |
if room_jid not in self._muc_data:
|
| 336 | 333 |
self._log.warning('Presence from unknown MUC')
|
| 337 | 334 |
self._log.warning(stanza)
|
| ... | ... | @@ -347,7 +344,7 @@ class MUC(BaseModule): |
| 347 | 344 |
return
|
| 348 | 345 |
|
| 349 | 346 |
contact = app.contacts.get_gc_contact(self._account,
|
| 350 |
- properties.jid.getBare(),
|
|
| 347 |
+ room_jid,
|
|
| 351 | 348 |
properties.muc_nickname)
|
| 352 | 349 |
|
| 353 | 350 |
if properties.is_nickname_changed:
|
| ... | ... | @@ -498,7 +495,7 @@ class MUC(BaseModule): |
| 498 | 495 |
if not properties.is_muc_subject:
|
| 499 | 496 |
return
|
| 500 | 497 |
|
| 501 |
- jid = properties.jid.getBare()
|
|
| 498 |
+ jid = str(properties.muc_jid)
|
|
| 502 | 499 |
contact = app.contacts.get_groupchat_contact(self._account, jid)
|
| 503 | 500 |
if contact is None:
|
| 504 | 501 |
return
|
| ... | ... | @@ -513,8 +510,15 @@ class MUC(BaseModule): |
| 513 | 510 |
nickname=properties.muc_nickname,
|
| 514 | 511 |
user_timestamp=properties.user_timestamp))
|
| 515 | 512 |
|
| 516 |
- if self._get_muc_state(jid) == MUCJoinedState.JOINING:
|
|
| 513 |
+ muc_data = self._get_muc_data(jid)
|
|
| 514 |
+ if muc_data.state == MUCJoinedState.JOINING:
|
|
| 517 | 515 |
self._set_muc_state(jid, MUCJoinedState.JOINED)
|
| 516 |
+ # We successfully joined a MUC, set autojoin bookmark
|
|
| 517 |
+ self._con.get_module('Bookmarks').add_bookmark(None,
|
|
| 518 |
+ muc_data.jid,
|
|
| 519 |
+ True,
|
|
| 520 |
+ muc_data.password,
|
|
| 521 |
+ muc_data.nick)
|
|
| 518 | 522 |
|
| 519 | 523 |
raise nbxmpp.NodeProcessed
|
| 520 | 524 |
|
| ... | ... | @@ -530,7 +534,7 @@ class MUC(BaseModule): |
| 530 | 534 |
app.nec.push_incoming_event(
|
| 531 | 535 |
NetworkEvent('muc-voice-approval',
|
| 532 | 536 |
account=self._account,
|
| 533 |
- room_jid=properties.jid.getBare(),
|
|
| 537 |
+ room_jid=str(properties.muc_jid),
|
|
| 534 | 538 |
form=properties.voice_request.form))
|
| 535 | 539 |
raise nbxmpp.NodeProcessed
|
| 536 | 540 |
|
| ... | ... | @@ -557,7 +561,7 @@ class MUC(BaseModule): |
| 557 | 561 |
if not properties.is_muc_config_change:
|
| 558 | 562 |
return
|
| 559 | 563 |
|
| 560 |
- room_jid = properties.jid.getBare()
|
|
| 564 |
+ room_jid = str(properties.muc_jid)
|
|
| 561 | 565 |
self._log.info('Received config change: %s %s',
|
| 562 | 566 |
room_jid, properties.muc_status_codes)
|
| 563 | 567 |
app.nec.push_incoming_event(
|
| ... | ... | @@ -14,6 +14,8 @@ |
| 14 | 14 |
|
| 15 | 15 |
from collections import namedtuple
|
| 16 | 16 |
|
| 17 |
+from nbxmpp.protocol import JID
|
|
| 18 |
+ |
|
| 17 | 19 |
from gajim.common.const import MUCJoinedState
|
| 18 | 20 |
|
| 19 | 21 |
URI = namedtuple('URI', 'type action data')
|
| ... | ... | @@ -25,7 +27,7 @@ CapsIdentity = namedtuple('CapsIdentity', 'category type name lang') |
| 25 | 27 |
|
| 26 | 28 |
class MUCData:
|
| 27 | 29 |
def __init__(self, room_jid, nick, password, rejoin, config=None):
|
| 28 |
- self._room_jid = room_jid
|
|
| 30 |
+ self._room_jid = JID(room_jid)
|
|
| 29 | 31 |
self._nick = nick
|
| 30 | 32 |
self._password = password
|
| 31 | 33 |
self._rejoin = rejoin
|
| ... | ... | @@ -36,6 +38,12 @@ class MUCData: |
| 36 | 38 |
def jid(self):
|
| 37 | 39 |
return self._room_jid
|
| 38 | 40 |
|
| 41 |
+ @property
|
|
| 42 |
+ def occupant_jid(self):
|
|
| 43 |
+ jid = self._room_jid.copy()
|
|
| 44 |
+ jid.setResource(self._nick)
|
|
| 45 |
+ return jid
|
|
| 46 |
+ |
|
| 39 | 47 |
@property
|
| 40 | 48 |
def nick(self):
|
| 41 | 49 |
return self._nick
|
| ... | ... | @@ -33,6 +33,7 @@ import logging |
| 33 | 33 |
from enum import IntEnum, unique
|
| 34 | 34 |
|
| 35 | 35 |
import nbxmpp
|
| 36 |
+from nbxmpp.protocol import JID
|
|
| 36 | 37 |
from nbxmpp.const import StatusCode
|
| 37 | 38 |
from nbxmpp.const import Affiliation
|
| 38 | 39 |
from nbxmpp.const import Role
|
| ... | ... | @@ -642,6 +643,7 @@ class GroupchatControl(ChatControlBase): |
| 642 | 643 |
prompt, change_nick=True, transient_for=self.parent_win.window)
|
| 643 | 644 |
|
| 644 | 645 |
def _on_disconnect(self, action, param):
|
| 646 |
+ app.connections[self.account].get_module('MUC').leave(self.room_jid)
|
|
| 645 | 647 |
self.force_non_minimizable = True
|
| 646 | 648 |
self.parent_win.remove_tab(self, self.parent_win.CLOSE_COMMAND)
|
| 647 | 649 |
self.force_non_minimizable = False
|
| ... | ... | @@ -705,7 +707,7 @@ class GroupchatControl(ChatControlBase): |
| 705 | 707 |
password = app.gc_passwords.get(self.room_jid, '')
|
| 706 | 708 |
con = app.connections[self.account]
|
| 707 | 709 |
con.get_module('Bookmarks').add_bookmark(self.name,
|
| 708 |
- self.room_jid,
|
|
| 710 |
+ JID(self.room_jid),
|
|
| 709 | 711 |
True,
|
| 710 | 712 |
password,
|
| 711 | 713 |
self.nick)
|
| ... | ... | @@ -2229,9 +2231,6 @@ class GroupchatControl(ChatControlBase): |
| 2229 | 2231 |
for handler in self._event_handlers:
|
| 2230 | 2232 |
app.ged.remove_event_handler(*handler)
|
| 2231 | 2233 |
|
| 2232 |
- if self.is_connected:
|
|
| 2233 |
- app.connections[self.account].get_module('MUC').leave(self.room_jid)
|
|
| 2234 |
- |
|
| 2235 | 2234 |
nick_list = app.contacts.get_nick_list(self.account, self.room_jid)
|
| 2236 | 2235 |
for nick in nick_list:
|
| 2237 | 2236 |
# Update pm chat window
|
| ... | ... | @@ -46,6 +46,7 @@ import weakref |
| 46 | 46 |
import uuid
|
| 47 | 47 |
|
| 48 | 48 |
import nbxmpp
|
| 49 |
+from nbxmpp.protocol import JID
|
|
| 49 | 50 |
from nbxmpp.util import is_error_result
|
| 50 | 51 |
from nbxmpp.structs import DiscoIdentity
|
| 51 | 52 |
|
| ... | ... | @@ -1740,7 +1741,7 @@ class MucBrowser(AgentBrowser): |
| 1740 | 1741 |
return
|
| 1741 | 1742 |
|
| 1742 | 1743 |
con.get_module('Bookmarks').add_bookmark(room_jid.split('@')[0],
|
| 1743 |
- room_jid,
|
|
| 1744 |
+ JID(room_jid),
|
|
| 1744 | 1745 |
False,
|
| 1745 | 1746 |
'',
|
| 1746 | 1747 |
'')
|
| ... | ... | @@ -17,6 +17,7 @@ from gi.repository import Gtk |
| 17 | 17 |
from gi.repository import Gdk
|
| 18 | 18 |
|
| 19 | 19 |
import nbxmpp
|
| 20 |
+from nbxmpp.protocol import JID
|
|
| 20 | 21 |
from nbxmpp.util import is_error_result
|
| 21 | 22 |
from nbxmpp.structs import DiscoIdentity
|
| 22 | 23 |
|
| ... | ... | @@ -267,7 +268,7 @@ class JoinGroupchatWindow(Gtk.ApplicationWindow): |
| 267 | 268 |
# Add as bookmark, with autojoin and not minimized
|
| 268 | 269 |
name = app.get_nick_from_jid(self.room_jid)
|
| 269 | 270 |
con.get_module('Bookmarks').add_bookmark(name,
|
| 270 |
- self.room_jid,
|
|
| 271 |
+ JID(self.room_jid),
|
|
| 271 | 272 |
autojoin,
|
| 272 | 273 |
password,
|
| 273 | 274 |
nickname)
|
| ... | ... | @@ -2965,6 +2965,7 @@ class RosterWindow: |
| 2965 | 2965 |
"""
|
| 2966 | 2966 |
When disconnect menuitem is activated: disconnect from room
|
| 2967 | 2967 |
"""
|
| 2968 |
+ app.connections[account].get_module('MUC').leave(jid)
|
|
| 2968 | 2969 |
if jid in app.interface.minimized_controls[account]:
|
| 2969 | 2970 |
ctrl = app.interface.minimized_controls[account][jid]
|
| 2970 | 2971 |
ctrl.shutdown()
|