Commit bf222546 authored by Maxime Buquet's avatar Maxime Buquet

Revert work on tabs module to change tab.name to JID.

This reverts commits:
d693479d
2d0cc092
89a61b84
8194d9af
e256c318
a21335ac
c96e528a
0551867b
6ab49c18
parent 6ab49c18
Pipeline #2027 passed with stages
in 2 minutes and 22 seconds
......@@ -199,7 +199,7 @@ class Plugin(BasePlugin):
already_opened = False
for tab in self.core.tabs:
if tab.name.full.endswith(room_suffix) and tab.joined:
if tab.name.endswith(room_suffix) and tab.joined:
already_opened = True
break
......
......@@ -106,7 +106,7 @@ def replace_random_user(message, tab):
else:
# that doesn’t make any sense. By why use this pattern in a
# ConversationTab anyway?
return tab.name.full
return str(tab.name)
def replace_dice(message, tab):
......
......@@ -53,7 +53,7 @@ class Plugin(BasePlugin):
message = args[1]
for tab in self.core.get_tabs(MucTab):
if tab.name.full.endswith(jid):
if tab.name.endswith(jid):
tab.command_part(message)
def completion_server_part(self, the_input):
......
......@@ -49,7 +49,7 @@ class Bookmark:
password: Optional[str] = None,
method='local') -> None:
self.jid = jid
self.name = name or str(jid)
self.name = name or jid
self.autojoin = autojoin
self.nick = nick
self.password = password
......
......@@ -335,7 +335,7 @@ class CommandCore:
if room.find('@') == -1 and not server_root:
tab = self.core.tabs.current_tab
if isinstance(tab, tabs.MucTab):
if tab.name.full.find('@') != -1:
if tab.name.find('@') != -1:
domain = safeJID(tab.name).domain
room += '@%s' % domain
return (room, set_nick)
......@@ -369,8 +369,7 @@ class CommandCore:
# New tab
if tab is None:
tab = self.core.open_new_room(room, nick, password=password)
if tab is not None:
tab.join()
tab.join()
else:
self.core.focus_tab(tab)
if tab.own_nick == nick and tab.joined:
......@@ -1024,17 +1023,14 @@ class CommandCore:
"""
if args is None:
return self.help('message')
try:
jid = JID(args[0])
except InvalidJID:
return self.core.information('Invalid JID.', 'Error')
if not jid.bare:
jid = safeJID(args[0])
if not jid.user and not jid.domain and not jid.resource:
return self.core.information('Invalid JID.', 'Error')
tab = self.core.get_conversation_by_jid(
jid.full, False, fallback_barejid=False)
muc = self.core.tabs.by_name_and_class(jid.bare, tabs.MucTab)
if not tab and not muc:
tab = self.core.open_conversation_window(jid, focus=True)
tab = self.core.open_conversation_window(jid.full, focus=True)
elif muc:
if jid.resource:
tab = self.core.tabs.by_name_and_class(jid.full,
......
......@@ -1164,7 +1164,7 @@ class Core:
provided, we open a StaticConversationTab, else a
DynamicConversationTab
"""
if jid.resource:
if safeJID(jid).resource:
new_tab = tabs.StaticConversationTab(self, jid)
else:
new_tab = tabs.DynamicConversationTab(self, jid)
......@@ -1179,12 +1179,7 @@ class Core:
"""
Open a Private conversation in a MUC and focus if needed.
"""
try:
complete_jid_str = room_name + '/' + user_nick
complete_jid = JID(complete_jid_str)
except InvalidJID:
self.information('Invalid XMPP address %r for chat tab.', complete_jid_str)
return None
complete_jid = room_name + '/' + user_nick
# if the room exists, focus it and return
for tab in self.get_tabs(tabs.PrivateTab):
if tab.name == complete_jid:
......@@ -1210,15 +1205,10 @@ class Core:
nick: str,
*,
password: Optional[str] = None,
focus=True) -> Optional[tabs.MucTab]:
focus=True) -> tabs.MucTab:
"""
Open a new tab.MucTab containing a muc Room, using the specified nick
"""
try:
room = JID(room)
except InvalidJID:
self.information('Invalid XMPP address %r for chat tab.', room)
return None
new_tab = tabs.MucTab(self, room, nick, password=password)
self.add_tab(new_tab, focus)
self.refresh_window()
......@@ -1277,7 +1267,7 @@ class Core:
if reason is None:
reason = '\x195}You left the room\x193}'
for tab in self.get_tabs(tabs.PrivateTab):
if tab.name.full.startswith(room_name):
if tab.name.startswith(room_name):
tab.deactivate(reason=reason)
def enable_private_tabs(self, room_name: str,
......@@ -1288,7 +1278,7 @@ class Core:
if reason is None:
reason = '\x195}You joined the room\x193}'
for tab in self.get_tabs(tabs.PrivateTab):
if tab.name.full.startswith(room_name):
if tab.name.startswith(room_name):
tab.activate(reason=reason)
def on_user_changed_status_in_private(self, jid: JID, status: str) -> None:
......
......@@ -20,7 +20,7 @@ from datetime import datetime
from xml.etree import cElementTree as ET
from typing import Any, Callable, Dict, List, Optional
from slixmpp import JID, InvalidJID, Message
from slixmpp import JID, Message
from poezio.core.structs import Command, Completion, Status
from poezio import timed_events
......@@ -462,16 +462,8 @@ class ChatTab(Tab):
plugin_keys = {} # type: Dict[str, Callable]
message_type = 'chat'
def __init__(self, core, jid: Optional[JID] = None):
def __init__(self, core, jid=''):
Tab.__init__(self, core)
if jid is not None and not isinstance(jid, JID):
# XXX: Remove logging once we're more or less sure we've switched
# all calls.
log.debug('ChatTab.name: %r: Not a JID object.', jid, exc_info=True)
try:
jid = JID(jid)
except InvalidJID:
log.debug('ChatTab.name: invalid JID.')
self.name = jid
self.text_win = None
self.directed_presence = None
......@@ -522,9 +514,8 @@ class ChatTab(Tab):
raise NotImplementedError
def load_logs(self, log_nb: int) -> Optional[List[Dict[str, Any]]]:
if self.name is not None:
return logger.get_logs(self.name.bare, log_nb)
return None
logs = logger.get_logs(safeJID(self.name).bare, log_nb)
return logs
def log_message(self,
txt: str,
......@@ -534,9 +525,7 @@ class ChatTab(Tab):
"""
Log the messages in the archives.
"""
if self.name is None:
return None
name = self.name.bare
name = safeJID(self.name).bare
if not logger.log_message(name, nickname, txt, date=time, typ=typ):
self.core.information('Unable to write in the log file', 'Error')
......@@ -781,9 +770,8 @@ class ChatTab(Tab):
class OneToOneTab(ChatTab):
def __init__(self, core, jid: JID):
def __init__(self, core, jid=''):
ChatTab.__init__(self, core, jid)
assert self.name.bare
self.__status = Status("", "")
self.last_remote_message = datetime.now()
......@@ -813,7 +801,7 @@ class OneToOneTab(ChatTab):
return
self.__status = status
hide_status_change = config.get_by_tabname('hide_status_change',
self.name.bare)
safeJID(self.name).bare)
now = datetime.now()
dff = now - self.last_remote_message
if hide_status_change > -1 and dff.total_seconds() > hide_status_change:
......
......@@ -15,8 +15,6 @@ import curses
import logging
from typing import Dict, Callable
from slixmpp import JID
from poezio.tabs.basetabs import OneToOneTab, Tab
from poezio import common
......@@ -44,7 +42,7 @@ class ConversationTab(OneToOneTab):
additional_information = {} # type: Dict[str, Callable[[str], str]]
message_type = 'chat'
def __init__(self, core, jid: JID):
def __init__(self, core, jid):
OneToOneTab.__init__(self, core, jid)
self.nick = None
self.nick_sent = False
......@@ -402,10 +400,10 @@ class DynamicConversationTab(ConversationTab):
plugin_commands = {} # type: Dict[str, Command]
plugin_keys = {} # type: Dict[str, Callable]
def __init__(self, core, jid: JID, resource=None):
def __init__(self, core, jid, resource=None):
self.locked_resource = None
self.name = safeJID(jid).bare
ConversationTab.__init__(self, core, jid)
self.name.resource = None
self.info_header = windows.DynamicConversationInfoWin()
self.register_command(
'unlock', self.unlock_command, shortdesc='Deprecated, do nothing.')
......@@ -472,8 +470,8 @@ class StaticConversationTab(ConversationTab):
plugin_commands = {} # type: Dict[str, Command]
plugin_keys = {} # type: Dict[str, Callable]
def __init__(self, core, jid: JID):
assert jid.resource
def __init__(self, core, jid):
assert (safeJID(jid).resource)
ConversationTab.__init__(self, core, jid)
self.info_header = windows.ConversationInfoWin()
self.resize()
......
......@@ -55,7 +55,7 @@ class MucTab(ChatTab):
additional_information = {} # type: Dict[str, Callable[[str], str]]
lagged = False
def __init__(self, core, jid: JID, nick: str, password: str = None):
def __init__(self, core, jid, nick, password=None):
ChatTab.__init__(self, core, jid)
self.joined = False
self._state = 'disconnected'
......@@ -63,6 +63,7 @@ class MucTab(ChatTab):
self.own_nick = nick
# self User object
self.own_user = None # type: Optional[User]
self.name = jid
self.password = password
# buffered presences
self.presence_buffer = []
......@@ -1481,7 +1482,7 @@ class MucTab(ChatTab):
r = None
for user in self.users:
if user.nick == nick:
r = self.core.open_private_window(str(self.name), user.nick)
r = self.core.open_private_window(self.name, user.nick)
if r and len(args) == 2:
msg = args[1]
self.core.tabs.current_tab.command_say(
......
......@@ -20,6 +20,7 @@ from poezio.tabs import OneToOneTab, MucTab, Tab
from poezio import windows
from poezio import xhtml
from poezio.common import safeJID
from poezio.config import config
from poezio.core.structs import Command
from poezio.decorators import refresh_wrapper
......@@ -39,9 +40,10 @@ class PrivateTab(OneToOneTab):
message_type = 'chat'
additional_information = {} # type: Dict[str, Callable[[str], str]]
def __init__(self, core, name: JID, nick: str):
def __init__(self, core, name, nick):
OneToOneTab.__init__(self, core, name)
self.own_nick = nick
self.name = name
self.text_win = windows.TextWin()
self._text_buffer.add_window(self.text_win)
self.info_header = windows.PrivateInfoWin()
......@@ -63,13 +65,13 @@ class PrivateTab(OneToOneTab):
shortdesc='Get the software version of a jid.')
self.resize()
self.parent_muc = self.core.tabs.by_name_and_class(
self.name.bare, MucTab)
safeJID(name).bare, MucTab)
self.on = True
self.update_commands()
self.update_keys()
def remote_user_color(self):
user = self.parent_muc.get_user_by_name(self.name.resource)
user = self.parent_muc.get_user_by_name(safeJID(self.name).resource)
if user:
return dump_tuple(user.color)
return super().remote_user_color()
......@@ -103,7 +105,9 @@ class PrivateTab(OneToOneTab):
del PrivateTab.additional_information[plugin_name]
def load_logs(self, log_nb):
return logger.get_logs(self.name.full.replace('/', '\\'), log_nb)
logs = logger.get_logs(
safeJID(self.name).full.replace('/', '\\'), log_nb)
return logs
def log_message(self, txt, nickname, time=None, typ=1):
"""
......@@ -217,7 +221,7 @@ class PrivateTab(OneToOneTab):
"""
if args:
return self.core.command.version(args[0])
jid = self.name
jid = safeJID(self.name)
self.core.xmpp.plugin['xep_0092'].get_version(
jid, callback=self.core.handler.on_version_result)
......@@ -229,7 +233,7 @@ class PrivateTab(OneToOneTab):
if arg and arg[0]:
self.parent_muc.command_info(arg[0])
else:
user = self.name.resource
user = safeJID(self.name).resource
self.parent_muc.command_info(user)
def resize(self):
......@@ -272,7 +276,7 @@ class PrivateTab(OneToOneTab):
self.input.refresh()
def get_nick(self):
return self.name.resource
return safeJID(self.name).resource
def on_input(self, key, raw):
if not raw and key in self.key_func:
......@@ -284,7 +288,7 @@ class PrivateTab(OneToOneTab):
empty_after = self.input.get_text() == '' or (
self.input.get_text().startswith('/')
and not self.input.get_text().startswith('//'))
tab = self.core.tabs.by_name_and_class(self.name.bare, MucTab)
tab = self.core.tabs.by_name_and_class(safeJID(self.name).bare, MucTab)
if tab and tab.joined:
self.send_composing_chat_state(empty_after)
return False
......@@ -297,7 +301,7 @@ class PrivateTab(OneToOneTab):
self.text_win.remove_line_separator()
self.text_win.add_line_separator(self._text_buffer)
tab = self.core.tabs.by_name_and_class(self.name.bare, MucTab)
tab = self.core.tabs.by_name_and_class(safeJID(self.name).bare, MucTab)
if tab and tab.joined and config.get_by_tabname(
'send_chat_states', self.general_jid) and self.on:
self.send_chat_state('inactive')
......@@ -306,7 +310,7 @@ class PrivateTab(OneToOneTab):
def on_gain_focus(self):
self.state = 'current'
curses.curs_set(1)
tab = self.core.tabs.by_name_and_class(self.name.bare, MucTab)
tab = self.core.tabs.by_name_and_class(safeJID(self.name).bare, MucTab)
if tab and tab.joined and config.get_by_tabname(
'send_chat_states',
self.general_jid,
......@@ -341,7 +345,7 @@ class PrivateTab(OneToOneTab):
'info_col': dump_tuple(get_theme().COLOR_INFORMATION_TEXT)
},
typ=2)
new_jid = self.name.bare + '/' + user.nick
new_jid = safeJID(self.name).bare + '/' + user.nick
self.name = new_jid
return self.core.tabs.current_tab is self
......@@ -422,7 +426,7 @@ class PrivateTab(OneToOneTab):
self.add_message(txt=reason, typ=2)
def matching_names(self):
return [(3, self.name.resource), (4, self.name)]
return [(3, safeJID(self.name).resource), (4, self.name)]
def add_error(self, error_message):
theme = get_theme()
......
......@@ -6,7 +6,6 @@ info buffer in normal tabs
import logging
log = logging.getLogger(__name__)
from slixmpp import JID
from poezio.common import safeJID
from poezio.config import config
......@@ -92,7 +91,8 @@ class PrivateInfoWin(InfoWin):
self.addstr(plugin(jid),
to_curses_attr(get_theme().COLOR_INFORMATION_BAR))
def write_room_name(self, jid: JID):
def write_room_name(self, name):
jid = safeJID(name)
room_name, nick = jid.bare, jid.resource
theme = get_theme()
self.addstr(nick, to_curses_attr(theme.COLOR_PRIVATE_NAME))
......@@ -266,7 +266,7 @@ class MucInfoWin(InfoWin):
def refresh(self, room, window=None, user=None, information=None):
log.debug('Refresh: %s', self.__class__.__name__)
self._win.erase()
self.write_room_name(str(room.name))
self.write_room_name(room)
self.write_participants_number(room)
self.write_own_nick(room)
self.write_disconnected(room)
......@@ -287,11 +287,11 @@ class MucInfoWin(InfoWin):
for plugin in information.values():
self.addstr(plugin(jid), color)
def write_room_name(self, name: str):
def write_room_name(self, room):
theme = get_theme()
color = to_curses_attr(theme.COLOR_INFORMATION_BAR)
self.addstr('[', color)
self.addstr(name,
self.addstr(room.name,
to_curses_attr(theme.COLOR_GROUPCHAT_NAME))
self.addstr(']', color)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment