summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxime “pep” Buquet <pep@bouah.net>2019-04-08 14:27:40 +0100
committerMaxime “pep” Buquet <pep@bouah.net>2019-04-08 14:27:40 +0100
commit4a3d1c76e3da6cca7ff378291d351428ddff4074 (patch)
tree5ab7a395c6ec312c838d5c8555ce3cc9795e3301
parentbf2225468e8f496a45db477b596eb7d233cb813f (diff)
downloadpoezio-4a3d1c76e3da6cca7ff378291d351428ddff4074.tar.gz
poezio-4a3d1c76e3da6cca7ff378291d351428ddff4074.tar.bz2
poezio-4a3d1c76e3da6cca7ff378291d351428ddff4074.tar.xz
poezio-4a3d1c76e3da6cca7ff378291d351428ddff4074.zip
ChatTab: Introduce self.jid as a JID object
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
-rw-r--r--poezio/tabs/basetabs.py44
1 files changed, 40 insertions, 4 deletions
diff --git a/poezio/tabs/basetabs.py b/poezio/tabs/basetabs.py
index 213f39d7..048a8187 100644
--- a/poezio/tabs/basetabs.py
+++ b/poezio/tabs/basetabs.py
@@ -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)
self.name = jid
self.text_win = None
@@ -510,11 +510,47 @@ class ChatTab(Tab):
self._text_buffer.add_message(**message)
@property
+ def name(self) -> str:
+ if self.jid is not None:
+ return self.jid.full
+ return self.name
+
+ @name.setter
+ def name(self, value: Union[JID, str]) -> None:
+ if isinstance(value, JID):
+ self.jid = value
+ elif isinstance(value, str):
+ try:
+ value = JID(value)
+ if value.domain:
+ self.jid = value
+ self.name = value.full
+ except InvalidJID:
+ self.name = value
+ else:
+ raise TypeError("Name must be of type JID or str.")
+
+ @property
+ def jid(self) -> Optional[JID]:
+ return self.jid
+
+ @jid.setter
+ 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
+
+ @property
def general_jid(self) -> JID:
raise NotImplementedError
def load_logs(self, log_nb: int) -> Optional[List[Dict[str, Any]]]:
- logs = logger.get_logs(safeJID(self.name).bare, log_nb)
+ logs = logger.get_logs(self.jid.bare, log_nb)
return logs
def log_message(self,