Matridge 0.2.3__tar.gz → 0.3.0__tar.gz

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 (54) hide show
  1. {matridge-0.2.3 → matridge-0.3.0}/.copier-answers.yml +2 -2
  2. {matridge-0.2.3 → matridge-0.3.0}/.woodpecker/container.yaml +3 -3
  3. {matridge-0.2.3 → matridge-0.3.0}/Dockerfile +5 -10
  4. {matridge-0.2.3/matridge.egg-info → matridge-0.3.0}/PKG-INFO +2 -2
  5. {matridge-0.2.3 → matridge-0.3.0}/matridge/command.py +5 -2
  6. {matridge-0.2.3 → matridge-0.3.0}/matridge/gateway.py +3 -5
  7. {matridge-0.2.3 → matridge-0.3.0}/matridge/group.py +4 -4
  8. {matridge-0.2.3 → matridge-0.3.0}/matridge/matrix.py +28 -5
  9. {matridge-0.2.3 → matridge-0.3.0}/matridge/session.py +2 -3
  10. {matridge-0.2.3 → matridge-0.3.0}/matridge/util.py +19 -2
  11. {matridge-0.2.3 → matridge-0.3.0/matridge.egg-info}/PKG-INFO +2 -2
  12. {matridge-0.2.3 → matridge-0.3.0}/matridge.egg-info/requires.txt +1 -1
  13. {matridge-0.2.3 → matridge-0.3.0}/pyproject.toml +1 -1
  14. matridge-0.3.0/uv.lock +2040 -0
  15. matridge-0.2.3/uv.lock +0 -1826
  16. {matridge-0.2.3 → matridge-0.3.0}/.gitignore +0 -0
  17. {matridge-0.2.3 → matridge-0.3.0}/.pre-commit-config.yaml +0 -0
  18. {matridge-0.2.3 → matridge-0.3.0}/.woodpecker/autoupdate-deps.yaml +0 -0
  19. {matridge-0.2.3 → matridge-0.3.0}/.woodpecker/docs.yaml +0 -0
  20. {matridge-0.2.3 → matridge-0.3.0}/.woodpecker/package.yaml +0 -0
  21. {matridge-0.2.3 → matridge-0.3.0}/.woodpecker/test.yaml +0 -0
  22. {matridge-0.2.3 → matridge-0.3.0}/CONTRIBUTING.md +0 -0
  23. {matridge-0.2.3 → matridge-0.3.0}/LICENSE +0 -0
  24. {matridge-0.2.3 → matridge-0.3.0}/README.md +0 -0
  25. {matridge-0.2.3 → matridge-0.3.0}/assets/matrix_outline.png +0 -0
  26. {matridge-0.2.3 → matridge-0.3.0}/assets/matrix_outline.svg +0 -0
  27. {matridge-0.2.3 → matridge-0.3.0}/commitlint.config.js +0 -0
  28. {matridge-0.2.3 → matridge-0.3.0}/doap.xml +0 -0
  29. {matridge-0.2.3 → matridge-0.3.0}/docker-compose.yml +0 -0
  30. {matridge-0.2.3 → matridge-0.3.0}/docs/Makefile +0 -0
  31. {matridge-0.2.3 → matridge-0.3.0}/docs/source/admin/config.rst +0 -0
  32. {matridge-0.2.3 → matridge-0.3.0}/docs/source/admin/index.rst +0 -0
  33. {matridge-0.2.3 → matridge-0.3.0}/docs/source/admin/install.rst +0 -0
  34. {matridge-0.2.3 → matridge-0.3.0}/docs/source/codeberg.svg +0 -0
  35. {matridge-0.2.3 → matridge-0.3.0}/docs/source/conf.py +0 -0
  36. {matridge-0.2.3 → matridge-0.3.0}/docs/source/contributing.rst +0 -0
  37. {matridge-0.2.3 → matridge-0.3.0}/docs/source/index.rst +0 -0
  38. {matridge-0.2.3 → matridge-0.3.0}/docs/source/user/features.rst +0 -0
  39. {matridge-0.2.3 → matridge-0.3.0}/docs/source/user/index.rst +0 -0
  40. {matridge-0.2.3 → matridge-0.3.0}/docs/source/user/registration.rst +0 -0
  41. {matridge-0.2.3 → matridge-0.3.0}/docs/source/user/usage.rst +0 -0
  42. {matridge-0.2.3 → matridge-0.3.0}/matridge/__init__.py +0 -0
  43. {matridge-0.2.3 → matridge-0.3.0}/matridge/__main__.py +0 -0
  44. {matridge-0.2.3 → matridge-0.3.0}/matridge/config.py +0 -0
  45. {matridge-0.2.3 → matridge-0.3.0}/matridge/contact.py +0 -0
  46. {matridge-0.2.3 → matridge-0.3.0}/matridge/reactions.py +0 -0
  47. {matridge-0.2.3 → matridge-0.3.0}/matridge.egg-info/SOURCES.txt +0 -0
  48. {matridge-0.2.3 → matridge-0.3.0}/matridge.egg-info/dependency_links.txt +0 -0
  49. {matridge-0.2.3 → matridge-0.3.0}/matridge.egg-info/entry_points.txt +0 -0
  50. {matridge-0.2.3 → matridge-0.3.0}/matridge.egg-info/top_level.txt +0 -0
  51. {matridge-0.2.3 → matridge-0.3.0}/setup.cfg +0 -0
  52. {matridge-0.2.3 → matridge-0.3.0}/tests/test_base.py +0 -0
  53. {matridge-0.2.3 → matridge-0.3.0}/tests/test_conversion.py +0 -0
  54. {matridge-0.2.3 → matridge-0.3.0}/tests/test_reactions.py +0 -0
@@ -1,7 +1,7 @@
1
1
  # Do not edit manually!
2
2
  # Changes here will be overwritten by copier.
3
3
  # https://copier.readthedocs.io/
4
- _commit: c2c396f
4
+ _commit: 88d0a39
5
5
  _src_path: git+https://codeberg.org/slidge/legacy-module-template
6
6
  authors:
7
7
  - email: nicoco@nicoco.fr
@@ -33,7 +33,7 @@ dependencies:
33
33
  - beautifulsoup4>=4.12.2,<5
34
34
  - async-lru>=2.0.3,<3
35
35
  - slidge-style-parser>=0.1.6
36
- - slidge>=0.2.5,<0.3
36
+ - slidge>=0.3.0alpha3,<0.4
37
37
  dev_dependencies:
38
38
  - types-beautifulsoup4>=4.12.0.20241020
39
39
  intersphinx_mappings: []
@@ -37,7 +37,7 @@ variables:
37
37
 
38
38
  steps:
39
39
  build-tag:
40
- image: woodpeckerci/plugin-docker-buildx
40
+ image: woodpeckerci/plugin-docker-buildx:6.0.2
41
41
  when:
42
42
  event: [tag]
43
43
  settings:
@@ -49,7 +49,7 @@ steps:
49
49
  build-branch:
50
50
  when:
51
51
  event: [push]
52
- image: woodpeckerci/plugin-docker-buildx
52
+ image: woodpeckerci/plugin-docker-buildx:6.0.2
53
53
  settings:
54
54
  <<: *settings
55
55
  tags:
@@ -59,7 +59,7 @@ steps:
59
59
  when:
60
60
  event: [push]
61
61
  branch: ${CI_REPO_DEFAULT_BRANCH}
62
- image: woodpeckerci/plugin-docker-buildx
62
+ image: woodpeckerci/plugin-docker-buildx:6.0.2
63
63
  settings:
64
64
  <<: *settings
65
65
  target: ci
@@ -18,13 +18,7 @@ RUN apt-get update -y && \
18
18
  WORKDIR /build
19
19
  ENV UV_PROJECT_ENVIRONMENT=/venv
20
20
  ENV PATH="/venv/bin:/root/.cargo/bin:$PATH"
21
- # By making the venv relocatable, we can copy it to /workspace/.venv in CI, and only update
22
- # dependencies that might be out-of-date. If uv.lock is not modified, then updating
23
- # the .venv is a no-op.
24
- # This allows us to not wait on the CI container build for the test workflows to run,
25
- # and also to run workflows for pull requests that modify the lockfile. In this,
26
- # situation, updating the CI container is not an option.
27
- RUN uv venv $UV_PROJECT_ENVIRONMENT --relocatable
21
+ RUN uv venv $UV_PROJECT_ENVIRONMENT
28
22
  COPY uv.lock pyproject.toml README.md .
29
23
  COPY matridge matridge
30
24
  # install dependencies in /venv
@@ -36,12 +30,13 @@ RUN --mount=source=.git,target=/build/.git,type=bind \
36
30
  # ************
37
31
  FROM builder AS ci
38
32
 
39
- # In CI we copy /venv to .venv, then update it for the whole workflow.
33
+ # We won't use this venv in CI, but this populates the uv cache in the container,
34
+ # minimizing (or even nulling) downloads.
40
35
  RUN --mount=source=.git,target=/build/.git,type=bind \
41
36
  uv sync --all-groups --no-install-project
42
- ENV UV_PROJECT_ENVIRONMENT=.venv
37
+ ENV UV_PROJECT_ENVIRONMENT="/woodpecker/src/codeberg.org/slidge/matridge/.venv"
43
38
  ENV UV_LINK_MODE=copy
44
- ENV PATH="/woodpecker/src/codeberg.org/slidge/matridge/.venv/bin:$PATH"
39
+ ENV PATH="$UV_PROJECT_ENVIRONMENT/bin:$PATH"
45
40
 
46
41
  # Dev container
47
42
  # *************
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: matridge
3
- Version: 0.2.3
3
+ Version: 0.3.0
4
4
  Summary: A Matrix/XMPP gateway
5
5
  Author-email: Nicolas Cedilnik <nicoco@nicoco.fr>
6
6
  License-Expression: AGPL-3.0-or-later
@@ -19,7 +19,7 @@ Requires-Dist: matrix-nio[e2e]<0.26,>=0.25
19
19
  Requires-Dist: beautifulsoup4<5,>=4.12.2
20
20
  Requires-Dist: async-lru<3,>=2.0.3
21
21
  Requires-Dist: slidge-style-parser>=0.1.6
22
- Requires-Dist: slidge<0.3,>=0.2.5
22
+ Requires-Dist: slidge<0.4,>=0.3.0alpha3
23
23
  Dynamic: license-file
24
24
 
25
25
  # matridge
@@ -58,12 +58,15 @@ class ListSpaces(Command):
58
58
  except XMPPError:
59
59
  continue
60
60
 
61
- mucs = sorted(mucs, key=lambda muc: muc.name)
61
+ mucs = sorted(mucs, key=lambda muc: muc.name or "Unnamed room")
62
62
  return TableResult(
63
63
  fields=[FormField("name"), FormField("jid", type="jid-single")],
64
64
  description=f"Rooms of '{space.display_name}'",
65
65
  jids_are_mucs=True,
66
- items=[{"name": muc.name, "jid": str(muc.jid)} for muc in mucs],
66
+ items=[
67
+ {"name": muc.name or "Unnamed room", "jid": str(muc.jid)}
68
+ for muc in mucs
69
+ ],
67
70
  )
68
71
 
69
72
 
@@ -70,7 +70,7 @@ class Gateway(BaseGateway):
70
70
  await asyncio.sleep(self.DB_PURGE_SLEEP)
71
71
  reactions.purge_old_messages(config.REACTION_CACHE_SIZE)
72
72
 
73
- async def validate(
73
+ async def validate( # type:ignore[override]
74
74
  self, user_jid: JID, registration_form: dict[str, Optional[str]]
75
75
  ) -> Credentials:
76
76
  client = AuthenticationClient(
@@ -88,10 +88,8 @@ class Gateway(BaseGateway):
88
88
  raise XMPPError("not-authorized", f"Could not login: {resp}")
89
89
  return client.get_credentials(resp)
90
90
 
91
- async def unregister(self, user):
92
- session: "Session" = self.get_session_from_user(user) # type: ignore
93
- session.matrix.stop_listen()
94
- await session.matrix.logout()
91
+ async def unregister(self, session: "Session"): # type:ignore[override]
92
+ await session.logout()
95
93
  rmtree(session.matrix.store_path)
96
94
 
97
95
 
@@ -59,7 +59,10 @@ class MUC(LegacyMUC[str, str, Participant, str]):
59
59
  room = await self.get_room()
60
60
 
61
61
  if new := room.replacement_room:
62
- raise XMPPError("redirect", f"{new}")
62
+ localpart = await self.session.bookmarks.legacy_id_to_jid_username(new)
63
+ raise XMPPError(
64
+ "redirect", f"xmpp:{localpart}@{self.xmpp.boundjid.bare}?join"
65
+ )
63
66
  self.log.debug("Children: %s", room.children)
64
67
  if room.children:
65
68
  raise XMPPError("bad-request", "This is not a real room but a 'space'")
@@ -98,9 +101,6 @@ class MUC(LegacyMUC[str, str, Participant, str]):
98
101
 
99
102
  power_levels = room.power_levels.users
100
103
  i = 0
101
- if len(room.users.items()) > config.MAX_PARTICIPANTS_FETCH:
102
- # matrix groups are huge
103
- self.KEEP_BACKFILLED_PARTICIPANTS = True
104
104
 
105
105
  for user_id, user in list(room.users.items()):
106
106
  power_level = power_levels.get(user_id, 0)
@@ -1,5 +1,6 @@
1
1
  import logging
2
2
  import time
3
+ import warnings
3
4
  from asyncio import Task, create_task, sleep
4
5
  from functools import wraps
5
6
  from typing import TYPE_CHECKING, AsyncIterator, Awaitable, Callable, Optional, Union
@@ -297,14 +298,36 @@ class Client(AuthenticationClient):
297
298
  emoji = event.key
298
299
 
299
300
  with self.reactions.session() as s:
300
- await self.reactions.add(
301
- s, room.room_id, msg_id, sender, emoji, event.event_id
301
+ reactions = await self.reactions.get(
302
+ s, room.room_id, msg_id, sender, with_event_ids=True
302
303
  )
303
- reactions = await self.reactions.get(s, room.room_id, msg_id, sender)
304
- s.commit()
304
+
305
+ if event.event_id in reactions.values():
306
+ if reactions[event.event_id] != emoji:
307
+ warnings.warn(
308
+ f"Received an emoji reaction update for the event ID '{event.event_id}': "
309
+ f"'{reactions[event.event_id]}' → '{emoji}'. This is illegal in Matrix, ignoring."
310
+ )
311
+ else:
312
+ if emoji in reactions:
313
+ warnings.warn(
314
+ f"We already had an event ID for the emoji reaction '{emoji}':"
315
+ f" '{event.event_id}' → {reactions[emoji]}."
316
+ )
317
+ with self.reactions.session() as s:
318
+ await self.reactions.add(
319
+ s, room.room_id, msg_id, sender, emoji, event.event_id
320
+ )
321
+ s.commit()
322
+ if emoji in reactions:
323
+ warnings.warn(
324
+ f"The emoji '{emoji}' was already present with a different event ID"
325
+ )
326
+ else:
327
+ reactions[emoji] = event.event_id
305
328
 
306
329
  participant = await self.get_participant(room, event)
307
- participant.react(msg_id, reactions, **kw)
330
+ participant.react(msg_id, list(reactions), **kw)
308
331
 
309
332
  @catch_all
310
333
  async def on_redact(self, room: nio.MatrixRoom, event: nio.RedactionEvent):
@@ -29,7 +29,6 @@ Recipient = Union[MUC, Contact]
29
29
  class Session(BaseSession[str, Recipient]):
30
30
  bookmarks: Bookmarks
31
31
  contacts: Roster
32
- matrix: Client
33
32
 
34
33
  MESSAGE_IDS_ARE_THREAD_IDS = True
35
34
 
@@ -38,6 +37,8 @@ class Session(BaseSession[str, Recipient]):
38
37
  self.events_to_ignore = set[str]()
39
38
  self.migrate_shelf()
40
39
  self.send_lock = Lock()
40
+ f = self.user.legacy_module_data
41
+ self.matrix = Client(f["homeserver"], f["user_id"], self) # type:ignore
41
42
 
42
43
  def migrate_shelf(self):
43
44
  store_path = global_config.HOME_DIR / self.user_jid.bare
@@ -53,8 +54,6 @@ class Session(BaseSession[str, Recipient]):
53
54
  store_path.unlink()
54
55
 
55
56
  async def login(self):
56
- f = self.user.legacy_module_data
57
- self.matrix = Client(f["homeserver"], f["user_id"], self) # type:ignore
58
57
  await self.matrix.login_token()
59
58
  await self.matrix.listen()
60
59
  self.contacts.user_legacy_id = self.matrix.user_id # type:ignore
@@ -72,13 +72,30 @@ class MatrixMixin(MessageMixin):
72
72
  ]
73
73
 
74
74
  if isinstance(msg, nio.RoomEncryptedMedia):
75
- return await self.__get_encrytped_attachments(msg)
75
+ return await self.__get_encrypted_attachments(msg)
76
+
77
+ # workaround for bots sending attachments that nio does not understand
78
+ url = msg.source["content"].get("url")
79
+ if url is not None:
80
+ return [
81
+ LegacyAttachment(
82
+ url=await self.session.matrix.mxc_to_http(url),
83
+ legacy_file_id=quote(url),
84
+ name=msg.source["content"].get("filename") or get_body(msg) or None,
85
+ )
86
+ ]
76
87
 
77
88
  return []
78
89
 
79
- async def __get_encrytped_attachments(self, msg: nio.RoomMessage):
90
+ async def __get_encrypted_attachments(self, msg: nio.RoomEncryptedMedia):
80
91
  resp = await self.session.matrix.download(mxc=msg.url, filename=None)
81
92
  if isinstance(resp, nio.DownloadError):
93
+ self.log.warning(
94
+ "Failed to download an encrypted media in %s: %s", msg, resp
95
+ )
96
+ self.send_text(
97
+ f"/me sent an encrypted media but matridge failed to download it: {resp.message}"
98
+ )
82
99
  return []
83
100
  else:
84
101
  media_data = resp.body
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: matridge
3
- Version: 0.2.3
3
+ Version: 0.3.0
4
4
  Summary: A Matrix/XMPP gateway
5
5
  Author-email: Nicolas Cedilnik <nicoco@nicoco.fr>
6
6
  License-Expression: AGPL-3.0-or-later
@@ -19,7 +19,7 @@ Requires-Dist: matrix-nio[e2e]<0.26,>=0.25
19
19
  Requires-Dist: beautifulsoup4<5,>=4.12.2
20
20
  Requires-Dist: async-lru<3,>=2.0.3
21
21
  Requires-Dist: slidge-style-parser>=0.1.6
22
- Requires-Dist: slidge<0.3,>=0.2.5
22
+ Requires-Dist: slidge<0.4,>=0.3.0alpha3
23
23
  Dynamic: license-file
24
24
 
25
25
  # matridge
@@ -2,4 +2,4 @@ matrix-nio[e2e]<0.26,>=0.25
2
2
  beautifulsoup4<5,>=4.12.2
3
3
  async-lru<3,>=2.0.3
4
4
  slidge-style-parser>=0.1.6
5
- slidge<0.3,>=0.2.5
5
+ slidge<0.4,>=0.3.0alpha3
@@ -19,7 +19,7 @@ dependencies = [
19
19
  "beautifulsoup4>=4.12.2,<5",
20
20
  "async-lru>=2.0.3,<3",
21
21
  "slidge-style-parser>=0.1.6",
22
- "slidge>=0.2.5,<0.3",
22
+ "slidge>=0.3.0alpha3,<0.4",
23
23
  ]
24
24
 
25
25
  [project.urls]