slidge 0.2.7.post1__py3-none-any.whl → 0.2.9__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,16 +0,0 @@
1
- from slixmpp.plugins import BasePlugin
2
- from . import stanza
3
-
4
-
5
- class XEP_0492(BasePlugin):
6
- """
7
- XEP-0492: Chat notification settings
8
- """
9
-
10
- name = "xep_0492"
11
- description = "XEP-0492: Chat notification settings"
12
- dependencies = {"xep_0402"}
13
- stanza = stanza
14
-
15
- def plugin_init(self):
16
- stanza.register_plugin()
@@ -1,107 +0,0 @@
1
- from typing import Literal, Optional, cast
2
-
3
- from slixmpp import register_stanza_plugin
4
- from slixmpp.plugins.xep_0402.stanza import Extensions
5
- from slixmpp.xmlstream import ElementBase
6
-
7
- from ...util.types import ClientType
8
-
9
- NS = "urn:xmpp:notification-settings:0"
10
-
11
- WhenLiteral = Literal["never", "always", "on-mention"]
12
-
13
-
14
- class Notify(ElementBase):
15
- """
16
- Chat notification settings element
17
-
18
-
19
- To enable it on a Conference element, use configure() like this:
20
-
21
- .. code-block::python
22
-
23
- # C being a Conference element
24
- C['extensions']["notify"].configure("always", client_type="pc")
25
-
26
- Which will add the <notify> element to the <extensions> element.
27
- """
28
-
29
- namespace = NS
30
- name = "notify"
31
- plugin_attrib = "notify"
32
- interfaces = {"notify"}
33
-
34
- def configure(self, when: WhenLiteral, client_type: Optional[ClientType] = None) -> None:
35
- """
36
- Configure the chat notification settings for this bookmark.
37
-
38
- This method ensures that there are no conflicting settings, e.g.,
39
- both a <never /> and a <always /> element.
40
- """
41
- cls = _CLASS_MAP[when]
42
- element = cls()
43
- if client_type is not None:
44
- element["client-type"] = client_type
45
-
46
- match = client_type if client_type is not None else ""
47
- for child in self:
48
- if isinstance(child, _Base) and child["client-type"] == match:
49
- self.xml.remove(child.xml)
50
-
51
- self.append(element)
52
-
53
- def get_config(
54
- self, client_type: Optional[ClientType] = None
55
- ) -> Optional[WhenLiteral]:
56
- """
57
- Get the chat notification settings for this bookmark.
58
-
59
- :param client_type: Optionally, get the notification for a specific client type.
60
- If unset, returns the global notification setting.
61
-
62
- :return: The chat notification setting as a string, or None if unset.
63
- """
64
- match = client_type if client_type is not None else ""
65
- for child in self:
66
- if isinstance(child, _Base) and child["client-type"] == match:
67
- return cast(WhenLiteral, child.name)
68
- return None
69
-
70
- class _Base(ElementBase):
71
- namespace = NS
72
- interfaces = {"client-type"}
73
-
74
-
75
- class Never(_Base):
76
- name = "never"
77
- plugin_attrib = name
78
-
79
-
80
- class Always(_Base):
81
- name = "always"
82
- plugin_attrib = name
83
-
84
-
85
- class OnMention(_Base):
86
- name = "on-mention"
87
- plugin_attrib = name
88
-
89
-
90
- class Advanced(ElementBase):
91
- namespace = NS
92
- name = plugin_attrib = "advanced"
93
-
94
-
95
- _CLASS_MAP = {
96
- "never": Never,
97
- "always": Always,
98
- "on-mention": OnMention,
99
- }
100
-
101
-
102
- def register_plugin():
103
- register_stanza_plugin(Extensions, Notify)
104
- register_stanza_plugin(Notify, Advanced)
105
- register_stanza_plugin(Notify, Never, iterable=True)
106
- register_stanza_plugin(Notify, Always, iterable=True)
107
- register_stanza_plugin(Notify, OnMention, iterable=True)