Mercurial > libervia-backend
comparison libervia/backend/plugins/plugin_xep_0191.py @ 4270:0d7bb4df2343
Reformatted code base using black.
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 19 Jun 2024 18:44:57 +0200 |
parents | 4b842c1fb686 |
children |
comparison
equal
deleted
inserted
replaced
4269:64a85ce8be70 | 4270:0d7bb4df2343 |
---|---|
82 | 82 |
83 def get_handler(self, client): | 83 def get_handler(self, client): |
84 return XEP_0191_Handler(self) | 84 return XEP_0191_Handler(self) |
85 | 85 |
86 @ensure_deferred | 86 @ensure_deferred |
87 async def _block_list( | 87 async def _block_list(self, profile_key=C.PROF_KEY_NONE) -> List[str]: |
88 self, | |
89 profile_key=C.PROF_KEY_NONE | |
90 ) -> List[str]: | |
91 client = self.host.get_client(profile_key) | 88 client = self.host.get_client(profile_key) |
92 blocked_jids = await self.block_list(client) | 89 blocked_jids = await self.block_list(client) |
93 return [j.full() for j in blocked_jids] | 90 return [j.full() for j in blocked_jids] |
94 | 91 |
95 async def block_list(self, client: SatXMPPEntity) -> Set[jid.JID]: | 92 async def block_list(self, client: SatXMPPEntity) -> Set[jid.JID]: |
111 else: | 108 else: |
112 blocked_jids.add(blocked_jid) | 109 blocked_jids.add(blocked_jid) |
113 | 110 |
114 return blocked_jids | 111 return blocked_jids |
115 | 112 |
116 def _block( | 113 def _block(self, entities: List[str], profile_key: str = C.PROF_KEY_NONE) -> str: |
117 self, | |
118 entities: List[str], | |
119 profile_key: str = C.PROF_KEY_NONE | |
120 ) -> str: | |
121 client = self.host.get_client(profile_key) | 114 client = self.host.get_client(profile_key) |
122 return defer.ensureDeferred( | 115 return defer.ensureDeferred( |
123 self.block(client, [jid.JID(entity) for entity in entities]) | 116 self.block(client, [jid.JID(entity) for entity in entities]) |
124 ) | 117 ) |
125 | 118 |
130 for entity in entities: | 123 for entity in entities: |
131 item_elt = block_elt.addElement("item") | 124 item_elt = block_elt.addElement("item") |
132 item_elt["jid"] = entity.full() | 125 item_elt["jid"] = entity.full() |
133 await iq_elt.send() | 126 await iq_elt.send() |
134 | 127 |
135 def _unblock( | 128 def _unblock(self, entities: List[str], profile_key: str = C.PROF_KEY_NONE) -> None: |
136 self, | |
137 entities: List[str], | |
138 profile_key: str = C.PROF_KEY_NONE | |
139 ) -> None: | |
140 client = self.host.get_client(profile_key) | 129 client = self.host.get_client(profile_key) |
141 return defer.ensureDeferred( | 130 return defer.ensureDeferred(self.unblock(client, [jid.JID(e) for e in entities])) |
142 self.unblock(client, [jid.JID(e) for e in entities]) | |
143 ) | |
144 | 131 |
145 async def unblock(self, client: SatXMPPEntity, entities: List[jid.JID]) -> None: | 132 async def unblock(self, client: SatXMPPEntity, entities: List[jid.JID]) -> None: |
146 await self.host.check_feature(client, NS_BLOCKING) | 133 await self.host.check_feature(client, NS_BLOCKING) |
147 iq_elt = client.IQ("set") | 134 iq_elt = client.IQ("set") |
148 unblock_elt = iq_elt.addElement((NS_BLOCKING, "unblock")) | 135 unblock_elt = iq_elt.addElement((NS_BLOCKING, "unblock")) |
190 def __init__(self, plugin_parent: XEP_0191): | 177 def __init__(self, plugin_parent: XEP_0191): |
191 self.plugin_parent = plugin_parent | 178 self.plugin_parent = plugin_parent |
192 | 179 |
193 def connectionInitialized(self): | 180 def connectionInitialized(self): |
194 self.xmlstream.addObserver( | 181 self.xmlstream.addObserver( |
195 IQ_BLOCK_PUSH, | 182 IQ_BLOCK_PUSH, self.plugin_parent.on_block_push, client=self.parent |
196 self.plugin_parent.on_block_push, | |
197 client=self.parent | |
198 | |
199 ) | 183 ) |
200 self.xmlstream.addObserver( | 184 self.xmlstream.addObserver( |
201 IQ_UNBLOCK_PUSH, | 185 IQ_UNBLOCK_PUSH, self.plugin_parent.on_unblock_push, client=self.parent |
202 self.plugin_parent.on_unblock_push, | |
203 client=self.parent | |
204 ) | 186 ) |
205 | 187 |
206 def getDiscoInfo(self, requestor, service, nodeIdentifier=""): | 188 def getDiscoInfo(self, requestor, service, nodeIdentifier=""): |
207 return [disco.DiscoFeature(NS_BLOCKING)] | 189 return [disco.DiscoFeature(NS_BLOCKING)] |
208 | 190 |