summaryrefslogtreecommitdiff
path: root/poezio/contact.py
diff options
context:
space:
mode:
Diffstat (limited to 'poezio/contact.py')
-rw-r--r--poezio/contact.py47
1 files changed, 28 insertions, 19 deletions
diff --git a/poezio/contact.py b/poezio/contact.py
index 50ccab1f..90f34c7e 100644
--- a/poezio/contact.py
+++ b/poezio/contact.py
@@ -3,7 +3,7 @@
# This file is part of Poezio.
#
# Poezio is free software: you can redistribute it and/or modify
-# it under the terms of the zlib license. See the COPYING file.
+# it under the terms of the GPL-3.0+ license. See the COPYING file.
"""
Defines the Resource and Contact classes, which are used in
the roster.
@@ -11,9 +11,17 @@ the roster.
from collections import defaultdict
import logging
-from typing import Dict, Iterator, List, Optional, Union
+from typing import (
+ Any,
+ Dict,
+ Iterator,
+ List,
+ Optional,
+ Union,
+)
from slixmpp import InvalidJID, JID
+from slixmpp.roster import RosterItem
log = logging.getLogger(__name__)
@@ -29,8 +37,8 @@ class Resource:
data: the dict to use as a source
"""
# Full JID
- self._jid = jid # type: str
- self._data = data # type: Dict[str, Union[str, int]]
+ self._jid: str = jid
+ self._data: Dict[str, Union[str, int]] = data
@property
def jid(self) -> str:
@@ -38,15 +46,18 @@ class Resource:
@property
def priority(self) -> int:
- return self._data.get('priority') or 0
+ try:
+ return int(self._data.get('priority', 0))
+ except Exception:
+ return 0
@property
def presence(self) -> str:
- return self._data.get('show') or ''
+ return str(self._data.get('show')) or ''
@property
def status(self) -> str:
- return self._data.get('status') or ''
+ return str(self._data.get('status')) or ''
def __repr__(self) -> str:
return '<%s>' % self._jid
@@ -64,19 +75,16 @@ class Contact:
to get the resource with the highest priority, etc
"""
- def __init__(self, item):
+ def __init__(self, item: RosterItem):
"""
item: a slixmpp RosterItem pointing to that contact
"""
self.__item = item
- self.folded_states = defaultdict(lambda: True) # type: Dict[str, bool]
+ self.folded_states: Dict[str, bool] = defaultdict(lambda: True)
self._name = ''
self.avatar = None
self.error = None
- self.tune = {} # type: Dict[str, str]
- self.gaming = {} # type: Dict[str, str]
- self.mood = ''
- self.activity = ''
+ self.rich_presence: Dict[str, Any] = defaultdict(lambda: None)
@property
def groups(self) -> List[str]:
@@ -89,7 +97,7 @@ class Contact:
return self.__item.jid
@property
- def name(self):
+ def name(self) -> str:
"""The name of the contact or an empty string."""
return self.__item['name'] or self._name or ''
@@ -99,26 +107,27 @@ class Contact:
self._name = value
@property
- def ask(self):
+ def ask(self) -> Optional[str]:
if self.__item['pending_out']:
return 'asked'
+ return None
@property
- def pending_in(self):
+ def pending_in(self) -> bool:
"""We received a subscribe stanza from this contact."""
return self.__item['pending_in']
@pending_in.setter
- def pending_in(self, value):
+ def pending_in(self, value: bool):
self.__item['pending_in'] = value
@property
- def pending_out(self):
+ def pending_out(self) -> bool:
"""We sent a subscribe stanza to this contact."""
return self.__item['pending_out']
@pending_out.setter
- def pending_out(self, value):
+ def pending_out(self, value: bool):
self.__item['pending_out'] = value
@property