Philipp Hörist pushed to branch master at gajim / gajim

Commits:

1 changed file:

Changes:

  • gajim/common/modules/annotations.py
    ... ... @@ -18,7 +18,9 @@ from typing import Any
    18 18
     from typing import Dict  # pylint: disable=unused-import
    
    19 19
     from typing import Tuple
    
    20 20
     
    
    21
    -from nbxmpp.util import is_error_result
    
    21
    +from nbxmpp.errors import StanzaError
    
    22
    +from nbxmpp.errors import MalformedStanzaError
    
    23
    +from nbxmpp.structs import AnnotationNote
    
    22 24
     
    
    23 25
     from gajim.common.types import ConnectionT
    
    24 26
     from gajim.common.modules.base import BaseModule
    
    ... ... @@ -32,29 +34,31 @@ class Annotations(BaseModule):
    32 34
             'set_annotations',
    
    33 35
         ]
    
    34 36
     
    
    35
    -    def __init__(self, con: ConnectionT):
    
    37
    +    def __init__(self, con: ConnectionT) -> None:
    
    36 38
             BaseModule.__init__(self, con)
    
    37 39
     
    
    38
    -        self._register_callback('request_annotations',
    
    39
    -                                self._annotations_received)
    
    40
    -        self._annotations = {}  # type: Dict[str, Any]
    
    40
    +        self._annotations = {}  # type: Dict[str, AnnotationNote]
    
    41 41
     
    
    42
    -    def set_annotations(self):
    
    43
    -        self._nbxmpp('Annotations').set_annotations(self._annotations.values())
    
    42
    +    def request_annotations(self) -> None:
    
    43
    +        self._nbxmpp('Annotations').request_annotations(
    
    44
    +            callback=self._annotations_received)
    
    44 45
     
    
    45
    -    def _annotations_received(self, result):
    
    46
    -        if is_error_result(result):
    
    46
    +    def _annotations_received(self, task: Any) -> None:
    
    47
    +        try:
    
    48
    +            annotations = task.finish()
    
    49
    +        except (StanzaError, MalformedStanzaError) as error:
    
    50
    +            self._log.warning(error)
    
    47 51
                 self._annotations = {}
    
    48
    -            return
    
    49
    -        for note in result:
    
    52
    +
    
    53
    +        for note in annotations:
    
    50 54
                 self._annotations[note.jid] = note
    
    51 55
     
    
    52
    -    def get_note(self, jid):
    
    56
    +    def get_note(self, jid: str) -> AnnotationNote:
    
    53 57
             return self._annotations.get(jid)
    
    54 58
     
    
    55
    -    def set_note(self, note):
    
    59
    +    def set_note(self, note: AnnotationNote) -> None:
    
    56 60
             self._annotations[note.jid] = note
    
    57
    -        self.set_annotations()
    
    61
    +        self.set_annotations(self._annotations.values())
    
    58 62
     
    
    59 63
     
    
    60 64
     def get_instance(*args: Any, **kwargs: Any) -> Tuple[Annotations, str]: