diff options
author | lovetox <philipp@hoerist.com> | 2020-10-04 17:22:07 +0300 |
---|---|---|
committer | lovetox <philipp@hoerist.com> | 2020-10-05 21:25:01 +0300 |
commit | e89b53c16ba16dacae5e7bc5b246f030e227597b (patch) | |
tree | e77b563b9e96cf6a09f767815f38c16de031da31 /nbxmpp/modules | |
parent | 7970e23ca6808b90446a1becdad9e3aa469a2061 (diff) |
Pubsub: Move set_access_model()/get_access_model() into pubsub module
Diffstat (limited to 'nbxmpp/modules')
-rw-r--r-- | nbxmpp/modules/pubsub.py | 44 | ||||
-rw-r--r-- | nbxmpp/modules/user_avatar.py | 45 |
2 files changed, 44 insertions, 45 deletions
diff --git a/nbxmpp/modules/pubsub.py b/nbxmpp/modules/pubsub.py index 5bac95d..f4d9be7 100644 --- a/nbxmpp/modules/pubsub.py +++ b/nbxmpp/modules/pubsub.py @@ -23,11 +23,14 @@ from nbxmpp.errors import PubSubStanzaError from nbxmpp.errors import MalformedStanzaError from nbxmpp.structs import StanzaHandler from nbxmpp.structs import PubSubEventData +from nbxmpp.structs import CommonResult from nbxmpp.protocol import Iq from nbxmpp.protocol import Node from nbxmpp.namespaces import Namespace from nbxmpp.modules.base import BaseModule from nbxmpp.modules.util import process_response +from nbxmpp.modules.util import raise_if_error +from nbxmpp.modules.util import finalize from nbxmpp.modules.dataforms import extend_form @@ -142,6 +145,47 @@ class PubSub(BaseModule): yield PubSubPublishResult(jid, node, item_id) @iq_request_task + def get_access_model(self, node): + _task = yield + + self._log.info('Request access model') + + result = yield self.get_node_configuration(node) + + raise_if_error(result) + + yield result.form['pubsub#access_model'].value + + @iq_request_task + def set_access_model(self, node, model): + task = yield + + if model not in ('open', 'presence'): + raise ValueError('Invalid access model') + + result = yield self.get_node_configuration(node) + + raise_if_error(result) + + try: + access_model = result.form['pubsub#access_model'].value + except Exception: + yield task.set_error('warning', + condition='access-model-not-supported') + + if access_model == model: + jid = self._client.get_bound_jid().new_as_bare() + yield CommonResult(jid=jid) + + result.form['pubsub#access_model'].value = model + + self._log.info('Set access model %s', model) + + result = yield self.set_node_configuration(node, result.form) + + yield finalize(task, result) + + @iq_request_task def retract(self, node, id_, jid=None, notify=True): _task = yield diff --git a/nbxmpp/modules/user_avatar.py b/nbxmpp/modules/user_avatar.py index 1e976c4..a42c964 100644 --- a/nbxmpp/modules/user_avatar.py +++ b/nbxmpp/modules/user_avatar.py @@ -27,7 +27,6 @@ from nbxmpp.namespaces import Namespace from nbxmpp.protocol import NodeProcessed from nbxmpp.protocol import Node from nbxmpp.structs import StanzaHandler -from nbxmpp.structs import CommonResult from nbxmpp.util import b64encode from nbxmpp.util import b64decode from nbxmpp.errors import MalformedStanzaError @@ -40,8 +39,6 @@ from nbxmpp.modules.util import finalize class UserAvatar(BaseModule): _depends = { - 'get_node_configuration': 'PubSub', - 'set_node_configuration': 'PubSub', 'publish': 'PubSub', 'request_item': 'PubSub', } @@ -160,48 +157,6 @@ class UserAvatar(BaseModule): yield finalize(task, result) - @iq_request_task - def get_access_model(self): - _task = yield - - self._log.info('Request access model') - - result = yield self.get_node_configuration(Namespace.AVATAR_DATA) - - raise_if_error(result) - - yield result.form['pubsub#access_model'].value - - @iq_request_task - def set_access_model(self, model): - task = yield - - if model not in ('open', 'presence'): - raise ValueError('Invalid access model') - - result = yield self.get_node_configuration(Namespace.AVATAR_DATA) - - raise_if_error(result) - - try: - access_model = result.form['pubsub#access_model'].value - except Exception: - yield task.set_error('warning', - condition='access-model-not-supported') - - if access_model == model: - jid = self._client.get_bound_jid().new_as_bare() - yield CommonResult(jid=jid) - - result.form['pubsub#access_model'].value = model - - self._log.info('Set access model %s', model) - - result = yield self.set_node_configuration(Namespace.AVATAR_DATA, - result.form) - - yield finalize(task, result) - def _get_avatar_data(item, id_): data_node = item.getTag('data', namespace=Namespace.AVATAR_DATA) |