Matridge 0.2.3__tar.gz → 0.3.1__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.1}/.copier-answers.yml +2 -3
  2. {matridge-0.2.3 → matridge-0.3.1}/.woodpecker/container.yaml +18 -14
  3. {matridge-0.2.3 → matridge-0.3.1}/Dockerfile +6 -11
  4. {matridge-0.2.3/matridge.egg-info → matridge-0.3.1}/PKG-INFO +2 -2
  5. {matridge-0.2.3 → matridge-0.3.1}/matridge/command.py +5 -2
  6. {matridge-0.2.3 → matridge-0.3.1}/matridge/gateway.py +3 -5
  7. {matridge-0.2.3 → matridge-0.3.1}/matridge/group.py +4 -4
  8. {matridge-0.2.3 → matridge-0.3.1}/matridge/matrix.py +33 -6
  9. {matridge-0.2.3 → matridge-0.3.1}/matridge/session.py +2 -3
  10. {matridge-0.2.3 → matridge-0.3.1}/matridge/util.py +19 -2
  11. {matridge-0.2.3 → matridge-0.3.1/matridge.egg-info}/PKG-INFO +2 -2
  12. {matridge-0.2.3 → matridge-0.3.1}/matridge.egg-info/SOURCES.txt +0 -1
  13. {matridge-0.2.3 → matridge-0.3.1}/matridge.egg-info/requires.txt +1 -1
  14. {matridge-0.2.3 → matridge-0.3.1}/pyproject.toml +1 -1
  15. matridge-0.3.1/uv.lock +2040 -0
  16. matridge-0.2.3/.woodpecker/autoupdate-deps.yaml +0 -14
  17. matridge-0.2.3/uv.lock +0 -1826
  18. {matridge-0.2.3 → matridge-0.3.1}/.gitignore +0 -0
  19. {matridge-0.2.3 → matridge-0.3.1}/.pre-commit-config.yaml +0 -0
  20. {matridge-0.2.3 → matridge-0.3.1}/.woodpecker/docs.yaml +0 -0
  21. {matridge-0.2.3 → matridge-0.3.1}/.woodpecker/package.yaml +0 -0
  22. {matridge-0.2.3 → matridge-0.3.1}/.woodpecker/test.yaml +0 -0
  23. {matridge-0.2.3 → matridge-0.3.1}/CONTRIBUTING.md +0 -0
  24. {matridge-0.2.3 → matridge-0.3.1}/LICENSE +0 -0
  25. {matridge-0.2.3 → matridge-0.3.1}/README.md +0 -0
  26. {matridge-0.2.3 → matridge-0.3.1}/assets/matrix_outline.png +0 -0
  27. {matridge-0.2.3 → matridge-0.3.1}/assets/matrix_outline.svg +0 -0
  28. {matridge-0.2.3 → matridge-0.3.1}/commitlint.config.js +0 -0
  29. {matridge-0.2.3 → matridge-0.3.1}/doap.xml +0 -0
  30. {matridge-0.2.3 → matridge-0.3.1}/docker-compose.yml +0 -0
  31. {matridge-0.2.3 → matridge-0.3.1}/docs/Makefile +0 -0
  32. {matridge-0.2.3 → matridge-0.3.1}/docs/source/admin/config.rst +0 -0
  33. {matridge-0.2.3 → matridge-0.3.1}/docs/source/admin/index.rst +0 -0
  34. {matridge-0.2.3 → matridge-0.3.1}/docs/source/admin/install.rst +0 -0
  35. {matridge-0.2.3 → matridge-0.3.1}/docs/source/codeberg.svg +0 -0
  36. {matridge-0.2.3 → matridge-0.3.1}/docs/source/conf.py +0 -0
  37. {matridge-0.2.3 → matridge-0.3.1}/docs/source/contributing.rst +0 -0
  38. {matridge-0.2.3 → matridge-0.3.1}/docs/source/index.rst +0 -0
  39. {matridge-0.2.3 → matridge-0.3.1}/docs/source/user/features.rst +0 -0
  40. {matridge-0.2.3 → matridge-0.3.1}/docs/source/user/index.rst +0 -0
  41. {matridge-0.2.3 → matridge-0.3.1}/docs/source/user/registration.rst +0 -0
  42. {matridge-0.2.3 → matridge-0.3.1}/docs/source/user/usage.rst +0 -0
  43. {matridge-0.2.3 → matridge-0.3.1}/matridge/__init__.py +0 -0
  44. {matridge-0.2.3 → matridge-0.3.1}/matridge/__main__.py +0 -0
  45. {matridge-0.2.3 → matridge-0.3.1}/matridge/config.py +0 -0
  46. {matridge-0.2.3 → matridge-0.3.1}/matridge/contact.py +0 -0
  47. {matridge-0.2.3 → matridge-0.3.1}/matridge/reactions.py +0 -0
  48. {matridge-0.2.3 → matridge-0.3.1}/matridge.egg-info/dependency_links.txt +0 -0
  49. {matridge-0.2.3 → matridge-0.3.1}/matridge.egg-info/entry_points.txt +0 -0
  50. {matridge-0.2.3 → matridge-0.3.1}/matridge.egg-info/top_level.txt +0 -0
  51. {matridge-0.2.3 → matridge-0.3.1}/setup.cfg +0 -0
  52. {matridge-0.2.3 → matridge-0.3.1}/tests/test_base.py +0 -0
  53. {matridge-0.2.3 → matridge-0.3.1}/tests/test_conversion.py +0 -0
  54. {matridge-0.2.3 → matridge-0.3.1}/tests/test_reactions.py +0 -0
@@ -1,14 +1,13 @@
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: 787361e
5
5
  _src_path: git+https://codeberg.org/slidge/legacy-module-template
6
6
  authors:
7
7
  - email: nicoco@nicoco.fr
8
8
  name: Nicolas Cedilnik
9
9
  ci_id: 14069
10
10
  container_build_files:
11
- - uv.lock
12
11
  - pyproject.toml
13
12
  container_build_native: false
14
13
  container_builder_deps:
@@ -33,7 +32,7 @@ dependencies:
33
32
  - beautifulsoup4>=4.12.2,<5
34
33
  - async-lru>=2.0.3,<3
35
34
  - slidge-style-parser>=0.1.6
36
- - slidge>=0.2.5,<0.3
35
+ - slidge>=0.3.0alpha3,<0.4
37
36
  dev_dependencies:
38
37
  - types-beautifulsoup4>=4.12.0.20241020
39
38
  intersphinx_mappings: []
@@ -1,14 +1,6 @@
1
1
  # DO NOT EDIT
2
2
  # Generated from .copier-answers.yml
3
3
 
4
- when:
5
- event: [push, tag]
6
- path:
7
- - "matridge/**"
8
- - Dockerfile
9
- - pyproject.toml
10
- - uv.lock
11
- - .woodpecker/container.yaml
12
4
 
13
5
  labels:
14
6
  platform: linux/amd64
@@ -37,7 +29,7 @@ variables:
37
29
 
38
30
  steps:
39
31
  build-tag:
40
- image: woodpeckerci/plugin-docker-buildx
32
+ image: woodpeckerci/plugin-docker-buildx:6.0.2
41
33
  when:
42
34
  event: [tag]
43
35
  settings:
@@ -48,8 +40,15 @@ steps:
48
40
 
49
41
  build-branch:
50
42
  when:
51
- event: [push]
52
- image: woodpeckerci/plugin-docker-buildx
43
+ - event: push
44
+ path:
45
+ - "matridge/**"
46
+ - Dockerfile
47
+ - pyproject.toml
48
+ - .woodpecker/container.yaml
49
+ - event: cron
50
+ cron: container-main
51
+ image: woodpeckerci/plugin-docker-buildx:6.0.2
53
52
  settings:
54
53
  <<: *settings
55
54
  tags:
@@ -57,9 +56,14 @@ steps:
57
56
 
58
57
  build-ci:
59
58
  when:
60
- event: [push]
61
- branch: ${CI_REPO_DEFAULT_BRANCH}
62
- image: woodpeckerci/plugin-docker-buildx
59
+ - event: push
60
+ path:
61
+ - "matridge/**"
62
+ - Dockerfile
63
+ - pyproject.toml
64
+ - .woodpecker/container.yaml
65
+ branch: ${CI_REPO_DEFAULT_BRANCH}
66
+ image: woodpeckerci/plugin-docker-buildx:6.0.2
63
67
  settings:
64
68
  <<: *settings
65
69
  target: ci
@@ -18,14 +18,8 @@ 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
28
- COPY uv.lock pyproject.toml README.md .
21
+ RUN uv venv $UV_PROJECT_ENVIRONMENT
22
+ COPY pyproject.toml README.md .
29
23
  COPY matridge matridge
30
24
  # install dependencies in /venv
31
25
  # .git/ needs to be mounted for setuptools-scm to set the version
@@ -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.1
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
@@ -84,7 +85,7 @@ class AuthenticationClient(nio.AsyncClient):
84
85
  class Client(AuthenticationClient):
85
86
  MIN_RETRY_TIME = 3
86
87
  MAX_RETRY_TIME = 300
87
- REQUEST_TIMEOUT = 60
88
+ REQUEST_TIMEOUT = 30000
88
89
  CONSIDER_SUCCESSFUL = 10
89
90
 
90
91
  def __init__(self, server: str, handle: str, session: "Session"):
@@ -297,14 +298,40 @@ 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
+ event_ids = list(reactions.values())
306
+ emojis = list(reactions.keys())
307
+ if event.event_id in event_ids:
308
+ idx = event_ids.index(event.event_id)
309
+ stored_emoji = emojis[idx]
310
+ if stored_emoji != emoji:
311
+ warnings.warn(
312
+ f"Received an emoji reaction update for the event ID '{event.event_id}': "
313
+ f"'{stored_emoji}' → '{emoji}'. This is illegal in Matrix, ignoring."
314
+ )
315
+ else:
316
+ if emoji in emojis:
317
+ warnings.warn(
318
+ f"We already had an event ID for the emoji reaction '{emoji}':"
319
+ f" '{event.event_id}' → {reactions[emoji]}."
320
+ )
321
+ with self.reactions.session() as s:
322
+ await self.reactions.add(
323
+ s, room.room_id, msg_id, sender, emoji, event.event_id
324
+ )
325
+ s.commit()
326
+ if emoji in reactions:
327
+ warnings.warn(
328
+ f"The emoji '{emoji}' was already present with a different event ID"
329
+ )
330
+ else:
331
+ emojis.append(emoji)
305
332
 
306
333
  participant = await self.get_participant(room, event)
307
- participant.react(msg_id, reactions, **kw)
334
+ participant.react(msg_id, emojis, **kw)
308
335
 
309
336
  @catch_all
310
337
  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.1
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
@@ -10,7 +10,6 @@ doap.xml
10
10
  docker-compose.yml
11
11
  pyproject.toml
12
12
  uv.lock
13
- .woodpecker/autoupdate-deps.yaml
14
13
  .woodpecker/container.yaml
15
14
  .woodpecker/docs.yaml
16
15
  .woodpecker/package.yaml
@@ -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]