ChatTab: Introduce self.jid as a JID object

Signed-off-by: Maxime Buquet's avatarMaxime “pep” Buquet <>
parent bf222546
......@@ -18,9 +18,9 @@ import string
import time
from datetime import datetime
from xml.etree import cElementTree as ET
from typing import Any, Callable, Dict, List, Optional
from typing import Any, Callable, Dict, List, Optional, Union
from slixmpp import JID, Message
from slixmpp import JID, InvalidJID, Message
from poezio.core.structs import Command, Completion, Status
from poezio import timed_events
......@@ -462,7 +462,7 @@ class ChatTab(Tab):
plugin_keys = {} # type: Dict[str, Callable]
message_type = 'chat'
def __init__(self, core, jid=''):
def __init__(self, core, jid: Union[JID, str]):
Tab.__init__(self, core) = jid
self.text_win = None
......@@ -509,12 +509,48 @@ class ChatTab(Tab):
for message in logs:
def name(self) -> str:
if self.jid is not None:
return self.jid.full
def name(self, value: Union[JID, str]) -> None:
if isinstance(value, JID):
self.jid = value
elif isinstance(value, str):
value = JID(value)
if value.domain:
self.jid = value = value.full
except InvalidJID: = value
raise TypeError("Name must be of type JID or str.")
def jid(self) -> Optional[JID]:
return self.jid
def jid(self, value: Optional[JID]) -> None:
if value is None:
self.jid = None
return None
if not isinstance(value, JID):
raise TypeError("Jid must be of type Optional[JID].")
if not value.domain:
raise ValueError("Jid must contain at least a domain.")
self.jid = value
def general_jid(self) -> JID:
raise NotImplementedError
def load_logs(self, log_nb: int) -> Optional[List[Dict[str, Any]]]:
logs = logger.get_logs(safeJID(, log_nb)
logs = logger.get_logs(self.jid.bare, log_nb)
return logs
def log_message(self,
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