slidge 0.2.2__py3-none-any.whl → 0.2.3.post1__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.
Files changed (40) hide show
  1. slidge/__version__.py +1 -1
  2. slidge/command/register.py +1 -3
  3. slidge/contact/contact.py +1 -1
  4. slidge/core/dispatcher/muc/admin.py +3 -4
  5. slidge/core/dispatcher/presence.py +3 -3
  6. slidge/core/mixins/attachment.py +1 -1
  7. slidge/core/mixins/avatar.py +6 -0
  8. slidge/core/mixins/message.py +13 -2
  9. slidge/db/store.py +9 -3
  10. slidge/group/archive.py +3 -3
  11. slidge/group/participant.py +11 -5
  12. slidge/main.py +1 -1
  13. slidge/slixfix/__init__.py +5 -16
  14. slidge/slixfix/xep_0153/__init__.py +0 -1
  15. slidge/slixfix/xep_0153/vcard_avatar.py +1 -10
  16. slidge/util/test.py +9 -2
  17. slidge-0.2.3.post1.dist-info/METADATA +793 -0
  18. {slidge-0.2.2.dist-info → slidge-0.2.3.post1.dist-info}/RECORD +35 -51
  19. {slidge-0.2.2.dist-info → slidge-0.2.3.post1.dist-info}/WHEEL +2 -1
  20. slidge-0.2.3.post1.dist-info/entry_points.txt +2 -0
  21. slidge-0.2.3.post1.dist-info/top_level.txt +1 -0
  22. slidge/slixfix/xep_0153/stanza.py +0 -25
  23. slidge/slixfix/xep_0264/__init__.py +0 -5
  24. slidge/slixfix/xep_0264/stanza.py +0 -36
  25. slidge/slixfix/xep_0264/thumbnail.py +0 -23
  26. slidge/slixfix/xep_0313/__init__.py +0 -12
  27. slidge/slixfix/xep_0313/mam.py +0 -262
  28. slidge/slixfix/xep_0313/stanza.py +0 -359
  29. slidge/slixfix/xep_0317/__init__.py +0 -5
  30. slidge/slixfix/xep_0317/hats.py +0 -17
  31. slidge/slixfix/xep_0317/stanza.py +0 -28
  32. slidge/slixfix/xep_0424/__init__.py +0 -9
  33. slidge/slixfix/xep_0424/retraction.py +0 -77
  34. slidge/slixfix/xep_0424/stanza.py +0 -28
  35. slidge/slixfix/xep_0490/__init__.py +0 -8
  36. slidge/slixfix/xep_0490/mds.py +0 -47
  37. slidge/slixfix/xep_0490/stanza.py +0 -17
  38. slidge-0.2.2.dist-info/LICENSE +0 -661
  39. slidge-0.2.2.dist-info/METADATA +0 -116
  40. slidge-0.2.2.dist-info/entry_points.txt +0 -3
slidge/__version__.py CHANGED
@@ -2,4 +2,4 @@ from slidge.util.util import get_version # noqa: F401
2
2
 
3
3
  # this is modified before publish, but if someone cloned from the repo,
4
4
  # it can help
5
- __version__ = "0.2.2"
5
+ __version__ = "v0.2.3.post1"
@@ -119,9 +119,7 @@ class Register(Command):
119
119
  elif self.xmpp.REGISTRATION_TYPE == RegistrationType.QRCODE:
120
120
  self.xmpp.qr_pending_registrations[ # type:ignore
121
121
  user.jid.bare
122
- ] = (
123
- self.xmpp.loop.create_future()
124
- )
122
+ ] = self.xmpp.loop.create_future()
125
123
  qr_text = await self.xmpp.get_qr_text(user)
126
124
  qr = qrcode.make(qr_text)
127
125
  with tempfile.NamedTemporaryFile(
slidge/contact/contact.py CHANGED
@@ -454,7 +454,7 @@ class LegacyContact(
454
454
  except PermissionError:
455
455
  warnings.warn(
456
456
  "Slidge does not have privileges to add contacts to the roster. Refer"
457
- " to https://slidge.im/core/admin/privilege.html for"
457
+ " to https://slidge.codeberg.page/docs/main/admin/privilege.html for"
458
458
  " more info."
459
459
  )
460
460
  if config.ROSTER_PUSH_PRESENCE_SUBSCRIPTION_REQUEST_FALLBACK:
@@ -11,7 +11,7 @@ class MucAdminMixin(DispatcherMixin):
11
11
  self.xmpp.register_handler(
12
12
  CoroutineCallback(
13
13
  "MUCModerate",
14
- StanzaPath("iq/apply_to/moderate"),
14
+ StanzaPath("iq/moderate"),
15
15
  self.on_user_moderation,
16
16
  )
17
17
  )
@@ -35,12 +35,11 @@ class MucAdminMixin(DispatcherMixin):
35
35
  assert isinstance(iq, Iq)
36
36
  muc = await self.get_muc_from_stanza(iq)
37
37
 
38
- apply_to = iq["apply_to"]
39
- xmpp_id = apply_to["id"]
38
+ moderate = iq["moderate"]
39
+ xmpp_id = iq["moderate"]["id"]
40
40
  if not xmpp_id:
41
41
  raise XMPPError("bad-request", "Missing moderated message ID")
42
42
 
43
- moderate = apply_to["moderate"]
44
43
  if not moderate["retract"]:
45
44
  raise XMPPError(
46
45
  "feature-not-implemented",
@@ -165,9 +165,9 @@ class PresenceHandlerMixin(DispatcherMixin):
165
165
  error_stanza["error"]["type"] = "cancel"
166
166
  error_stanza["error"]["by"] = muc.jid
167
167
  error_stanza["error"]["condition"] = "not-acceptable"
168
- error_stanza["error"][
169
- "text"
170
- ] = "Slidge does not let you change your nickname in groups."
168
+ error_stanza["error"]["text"] = (
169
+ "Slidge does not let you change your nickname in groups."
170
+ )
171
171
  error_stanza.send()
172
172
 
173
173
 
@@ -20,11 +20,11 @@ import thumbhash
20
20
  from PIL import Image, ImageOps
21
21
  from slixmpp import JID, Message
22
22
  from slixmpp.exceptions import IqError, IqTimeout
23
+ from slixmpp.plugins.xep_0264.stanza import Thumbnail
23
24
  from slixmpp.plugins.xep_0363 import FileUploadError
24
25
  from slixmpp.plugins.xep_0447.stanza import StatelessFileSharing
25
26
 
26
27
  from ...db.avatar import avatar_cache
27
- from ...slixfix.xep_0264.stanza import Thumbnail
28
28
  from ...util.types import (
29
29
  LegacyAttachment,
30
30
  LegacyMessageType,
@@ -3,6 +3,7 @@ from hashlib import sha1
3
3
  from pathlib import Path
4
4
  from typing import TYPE_CHECKING, Optional
5
5
 
6
+ from PIL import UnidentifiedImageError
6
7
  from slixmpp import JID
7
8
 
8
9
  from ...db.avatar import CachedAvatar, avatar_cache
@@ -100,6 +101,11 @@ class AvatarMixin:
100
101
  else:
101
102
  try:
102
103
  cached_avatar = await avatar_cache.convert_or_get(a)
104
+ except UnidentifiedImageError:
105
+ self.session.log.warning("%s is not a valid avatar", a)
106
+ self._avatar_pk = None
107
+ self.__avatar_unique_id = uid
108
+ return
103
109
  except Exception as e:
104
110
  self.session.log.error("Failed to set avatar %s", a, exc_info=e)
105
111
  self._avatar_pk = None
@@ -4,8 +4,8 @@ import warnings
4
4
  from typing import TYPE_CHECKING, Optional
5
5
 
6
6
  from slixmpp import Iq, Message
7
+ from slixmpp.plugins.xep_0004 import Form
7
8
 
8
- from ...slixfix.xep_0490.mds import PUBLISH_OPTIONS
9
9
  from ...util.types import ChatState, LegacyMessageType, Marker
10
10
  from .attachment import AttachmentMixin
11
11
  from .message_maker import MessageMaker
@@ -14,6 +14,17 @@ from .message_text import TextMessageMixin
14
14
  if TYPE_CHECKING:
15
15
  from ...group import LegacyMUC
16
16
 
17
+ # this is for MDS
18
+ PUBLISH_OPTIONS = Form()
19
+ PUBLISH_OPTIONS["type"] = "submit"
20
+ PUBLISH_OPTIONS.add_field(
21
+ "FORM_TYPE", "hidden", value="http://jabber.org/protocol/pubsub#publish-options"
22
+ )
23
+ PUBLISH_OPTIONS.add_field("pubsub#persist_items", value="true")
24
+ PUBLISH_OPTIONS.add_field("pubsub#max_items", value="max")
25
+ PUBLISH_OPTIONS.add_field("pubsub#send_last_published_item", value="never")
26
+ PUBLISH_OPTIONS.add_field("pubsub#access_model", value="whitelist")
27
+
17
28
 
18
29
  class ChatStateMixin(MessageMaker):
19
30
  def __init__(self):
@@ -172,7 +183,7 @@ class CarbonMessageMixin(ContentMessageMixin, MarkerMixin):
172
183
  warnings.warn(
173
184
  "Slidge does not have privileges to send message on behalf of"
174
185
  " user.Refer to"
175
- " https://slidge.im/core/admin/privilege.html"
186
+ " https://slidge.codeberg.page/docs/main/admin/privilege.html"
176
187
  " for more info."
177
188
  )
178
189
 
slidge/db/store.py CHANGED
@@ -18,9 +18,16 @@ from sqlalchemy.sql.functions import count
18
18
 
19
19
  from ..core import config
20
20
  from ..util.archive_msg import HistoryMessage
21
- from ..util.types import URL, CachedPresence, ClientType
21
+ from ..util.types import (
22
+ URL,
23
+ CachedPresence,
24
+ ClientType,
25
+ MamMetadata,
26
+ MucAffiliation,
27
+ MucRole,
28
+ Sticker,
29
+ )
22
30
  from ..util.types import Hat as HatTuple
23
- from ..util.types import MamMetadata, MucAffiliation, MucRole, Sticker
24
31
  from .meta import Base
25
32
  from .models import (
26
33
  ArchivedMessage,
@@ -545,7 +552,6 @@ class MAMStore(EngineMixin):
545
552
  sender: Optional[str] = None,
546
553
  flip=False,
547
554
  ) -> Iterator[HistoryMessage]:
548
-
549
555
  with self.session() as session:
550
556
  q = select(ArchivedMessage).where(ArchivedMessage.room_id == room_pk)
551
557
  if start_date is not None:
slidge/group/archive.py CHANGED
@@ -49,9 +49,9 @@ class MessageArchive:
49
49
  new_msg["muc"]["jid"] = participant.muc.jid
50
50
  else:
51
51
  log.warning("No real JID for participant in this group")
52
- new_msg["muc"][
53
- "jid"
54
- ] = f"{uuid.uuid4()}@{participant.xmpp.boundjid.bare}"
52
+ new_msg["muc"]["jid"] = (
53
+ f"{uuid.uuid4()}@{participant.xmpp.boundjid.bare}"
54
+ )
55
55
 
56
56
  self.__store.add_message(
57
57
  self.room_pk,
@@ -322,7 +322,10 @@ class LegacyParticipant(
322
322
  legacy_msg_id=None,
323
323
  **send_kwargs,
324
324
  ) -> MessageOrPresenceTypeVar:
325
- stanza["occupant-id"]["id"] = self.__occupant_id
325
+ if stanza.get_from().resource:
326
+ stanza["occupant-id"]["id"] = self.__occupant_id
327
+ else:
328
+ stanza["occupant-id"]["id"] = "room"
326
329
  self.__add_nick_element(stanza)
327
330
  if not self.is_user and isinstance(stanza, Presence):
328
331
  if stanza["type"] == "unavailable" and not self._presence_sent:
@@ -459,11 +462,14 @@ class LegacyParticipant(
459
462
 
460
463
  for i in msg_ids:
461
464
  m = self.muc.get_system_participant()._make_message()
462
- m["apply_to"]["id"] = i
463
- m["apply_to"]["moderated"].enable("retract")
464
- m["apply_to"]["moderated"]["by"] = self.jid
465
+ m["retract"]["id"] = i
466
+ if self.is_system:
467
+ m["retract"].enable("moderated")
468
+ else:
469
+ m["retract"]["moderated"]["by"] = self.jid
470
+ m["retract"]["moderated"]["occupant-id"]["id"] = self.__occupant_id
465
471
  if reason:
466
- m["apply_to"]["moderated"]["reason"] = reason
472
+ m["retract"]["reason"] = reason
467
473
  self._send(m)
468
474
 
469
475
  def set_room_subject(
slidge/main.py CHANGED
@@ -10,7 +10,7 @@ Use the long version of the CLI arg without the double dash prefix inside this
10
10
  INI file, eg ``debug=true``.
11
11
 
12
12
  An example configuration file is available at
13
- https://git.sr.ht/~nicoco/slidge/tree/master/item/dev/confs/slidge-example.ini
13
+ https://codeberg.org/slidge/slidge/src/branch/main/dev/confs/slidge-example.ini
14
14
  """
15
15
 
16
16
  import asyncio
@@ -8,21 +8,13 @@ from slixmpp import Iq, Message
8
8
  from slixmpp.exceptions import XMPPError
9
9
  from slixmpp.plugins.xep_0050 import XEP_0050, Command
10
10
  from slixmpp.plugins.xep_0231 import XEP_0231
11
+ from slixmpp.plugins.xep_0425.stanza import Moderate
11
12
  from slixmpp.xmlstream import StanzaBase
12
13
 
13
- from . import ( # xep_0356,
14
- link_preview,
15
- xep_0077,
16
- xep_0100,
17
- xep_0153,
18
- xep_0264,
19
- xep_0292,
20
- xep_0313,
21
- xep_0317,
22
- xep_0356_old,
23
- xep_0424,
24
- xep_0490,
25
- )
14
+ from . import link_preview, xep_0077, xep_0100, xep_0153, xep_0292, xep_0356_old
15
+
16
+ # TODO: remove this when the fix is included in slixmpp
17
+ Moderate.interfaces.add("id")
26
18
 
27
19
 
28
20
  async def _handle_bob_iq(self, iq: Iq):
@@ -86,11 +78,8 @@ def reply(self, body=None, clear=True):
86
78
  slixmpp.plugins.PLUGINS.extend(
87
79
  [
88
80
  "link_preview",
89
- "xep_0264",
90
81
  "xep_0292_provider",
91
- "xep_0317",
92
82
  "xep_0356_old",
93
- "xep_0490",
94
83
  ]
95
84
  )
96
85
 
@@ -4,7 +4,6 @@
4
4
  # See the file LICENSE for copying permission.
5
5
  from slixmpp.plugins.base import register_plugin
6
6
 
7
- from .stanza import VCardTempUpdate
8
7
  from .vcard_avatar import XEP_0153
9
8
 
10
9
  register_plugin(XEP_0153)
@@ -1,17 +1,8 @@
1
- # Slixmpp: The Slick XMPP Library
2
- # Copyright (C) 2012 Nathanael C. Fritz, Lance J.T. Stout
3
- # This file is part of Slixmpp.
4
- # See the file LICENSE for copying permission.
5
- import logging
6
-
7
1
  from slixmpp.plugins.base import BasePlugin
2
+ from slixmpp.plugins.xep_0153 import VCardTempUpdate, stanza
8
3
  from slixmpp.stanza import Presence
9
4
  from slixmpp.xmlstream import register_stanza_plugin
10
5
 
11
- from . import VCardTempUpdate, stanza
12
-
13
- log = logging.getLogger(__name__)
14
-
15
6
 
16
7
  class XEP_0153(BasePlugin):
17
8
  name = "xep_0153"
slidge/util/test.py CHANGED
@@ -5,7 +5,14 @@ from pathlib import Path
5
5
  from typing import Optional, Union
6
6
  from xml.dom.minidom import parseString
7
7
 
8
- import xmldiff.main
8
+ try:
9
+ import xmldiff.main
10
+
11
+ XML_DIFF_PRESENT = True
12
+ except ImportError:
13
+ xmldiff = None
14
+ XML_DIFF_PRESENT = False
15
+
9
16
  from slixmpp import (
10
17
  JID,
11
18
  ElementBase,
@@ -157,7 +164,7 @@ class SlixTestPlus(SlixTest):
157
164
  result = self.compare(xml, stanza.xml, stanza2.xml)
158
165
  stanza_class.namespace = old_ns
159
166
 
160
- if not result:
167
+ if XML_DIFF_PRESENT and not result:
161
168
  debug += str(
162
169
  xmldiff.main.diff_texts(tostring(xml), tostring(stanza.xml))
163
170
  )