Skip to content

Commit

Permalink
Merge branch 'master' into auto_create_group
Browse files Browse the repository at this point in the history
  • Loading branch information
maltee1 authored Sep 20, 2022
2 parents 58b16af + 90542f7 commit 994f483
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 41 deletions.
33 changes: 27 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# v0.4.0 (unreleased)
# v0.4.0 (2022-09-17)

Target signald version: [v0.21.0](https://gitlab.com/signald/signald/-/releases/0.21.0)
Target signald version: [v0.21.1](https://gitlab.com/signald/signald/-/releases/0.21.1)

**N.B.** This release requires a homeserver with Matrix v1.1 support, which
bumps up the minimum homeserver versions to Synapse 1.54 and Dendrite 0.8.7.
Expand All @@ -15,6 +15,17 @@ Minimum Conduit version remains at 0.4.0.
(thanks to [@maltee1] in [#250]).
* Added Matrix -> Signal power level change bridging
(thanks to [@maltee1] in [#260] and [#263]).
* Added join rule bridging in both directions (thanks to [@maltee1] in [#268]).
* Added Matrix -> Signal bridging of location messages
(thanks to [@maltee1] in [#287]).
* Since Signal doesn't have actual location messages, they're just bridged as
map links. The link template is configurable.
* Added command to link devices when the bridge is the primary device
(thanks to [@Craeckie] in [#221]).
* Added command to bridge existing Matrix rooms to existing Signal groups
(thanks to [@MaximilianGaedig] in [#288]).
* Added config option to auto-enable relay mode when a specific user is invited
(thanks to [@maltee1] in [#293]).
* Added options to make encryption more secure.
* The `encryption` -> `verification_levels` config options can be used to
make the bridge require encrypted messages to come from cross-signed
Expand All @@ -36,24 +47,34 @@ Minimum Conduit version remains at 0.4.0.
(thanks to [@maltee1] in [#265]).
* Syncing chat members will no longer be interrupted if one of the member
profiles is unavailable (thanks to [@maltee1] in [#270]).
* Member moderation actions from Signal are now bridged to Matrix with the
correct ghost user if possible instead of always using the bridge bot
(thanks to [@maltee1] in [#273]).
* Group metadata changes are now bridged based on the event itself rather than
resyncing the whole group, which means changes will use the correct ghost
user instead of always using the bridge bot (thanks to [@maltee1] in [#283]).
* Added proper captcha error handling when registering
(thanks to [@maltee1] in [#280]).
* Added user's phone number as topic in private chat portals
(thanks to [@maltee1] in [#282]).

### Fixed
* Call start notices work again

[@Craeckie]: https://github.com/Craeckie
[@MaximilianGaedig]: https://github.com/MaximilianGaedig
[#221]: https://github.com/mautrix/signal/pull/221
[#246]: https://github.com/mautrix/signal/pull/246
[#250]: https://github.com/mautrix/signal/pull/250
[#257]: https://github.com/mautrix/signal/pull/257
[#260]: https://github.com/mautrix/signal/pull/260
[#263]: https://github.com/mautrix/signal/pull/263
[#265]: https://github.com/mautrix/signal/pull/265
[#268]: https://github.com/mautrix/signal/pull/268
[#270]: https://github.com/mautrix/signal/pull/270
[#273]: https://github.com/mautrix/signal/pull/273
[#280]: https://github.com/mautrix/signal/pull/280
[#282]: https://github.com/mautrix/signal/pull/282
[#283]: https://github.com/mautrix/signal/pull/283
[#287]: https://github.com/mautrix/signal/pull/287
[#288]: https://github.com/mautrix/signal/pull/288
[#293]: https://github.com/mautrix/signal/pull/293

# v0.3.0 (2022-04-20)

Expand Down
2 changes: 1 addition & 1 deletion mausignald/signald.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ async def subscribe(self, username: str) -> bool:
async def unsubscribe(self, username: str) -> bool:
try:
await self.request_v1("unsubscribe", account=username)
self._subscriptions.remove(username)
self._subscriptions.discard(username)
return True
except RPCError as e:
self.log.debug("Failed to unsubscribe from %s: %s", username, e)
Expand Down
2 changes: 1 addition & 1 deletion mautrix_signal/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version__ = "0.3.0"
__version__ = "0.4.0"
__author__ = "Tulir Asokan <tulir@maunium.net>"
4 changes: 3 additions & 1 deletion mautrix_signal/commands/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from mausignald.errors import (
AuthorizationFailedError,
CaptchaRequiredError,
ScanTimeoutError,
TimeoutException,
UnexpectedResponse,
)
Expand Down Expand Up @@ -97,6 +98,7 @@ async def connect_existing(evt: CommandEvent) -> EventID:
help_section=SECTION_AUTH,
help_text="Link the bridge as a secondary device",
help_args="[device name]",
aliases=["login"],
)
async def link(evt: CommandEvent) -> None:
if qrcode is None:
Expand All @@ -118,7 +120,7 @@ async def link(evt: CommandEvent) -> None:
account = await evt.bridge.signal.finish_link(
session_id=sess.session_id, overwrite=True, device_name=device_name
)
except TimeoutException:
except (TimeoutException, ScanTimeoutError):
await evt.reply("Linking timed out, please try again.")
except Exception:
evt.log.exception("Fatal error while waiting for linking to finish")
Expand Down
8 changes: 0 additions & 8 deletions mautrix_signal/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@


class Config(BaseBridgeConfig):
def __getitem__(self, key: str) -> Any:
try:
return os.environ[f"MAUTRIX_SIGNAL_{key.replace('.', '_').upper()}"]
except KeyError:
return super().__getitem__(key)

@property
def forbidden_defaults(self) -> List[ForbiddenDefault]:
return [
Expand All @@ -43,8 +37,6 @@ def do_update(self, helper: ConfigUpdateHelper) -> None:
super().do_update(helper)
copy, copy_dict, base = helper

copy("homeserver.asmux")

copy("signal.socket_path")
copy("signal.outgoing_attachment_dir")
copy("signal.avatar_dir")
Expand Down
9 changes: 7 additions & 2 deletions mautrix_signal/example-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ homeserver:
# Whether or not to verify the SSL certificate of the homeserver.
# Only applies if address starts with https://
verify_ssl: true
asmux: false
# What software is the homeserver running?
# Standard Matrix homeservers like Synapse, Dendrite and Conduit should just use "standard" here.
software: standard
# Number of retries for all HTTP requests if the homeserver isn't reachable.
http_retry_count: 4
# The URL to push real-time bridge status to.
Expand Down Expand Up @@ -48,8 +50,9 @@ appservice:
# https://magicstack.github.io/asyncpg/current/api/index.html#asyncpg.pool.create_pool
# https://docs.python.org/3/library/sqlite3.html#sqlite3.connect
# For sqlite, min_size is used as the connection thread pool size and max_size is ignored.
# Additionally, SQLite supports init_commands as an array of SQL queries to run on connect (e.g. to set PRAGMAs).
database_opts:
min_size: 5
min_size: 1
max_size: 10

# The unique ID of this appservice.
Expand Down Expand Up @@ -170,6 +173,8 @@ bridge:
# Default to encryption, force-enable encryption in all portals the bridge creates
# This will cause the bridge bot to be in private chats for the encryption to work properly.
default: false
# Whether to use MSC2409/MSC3202 instead of /sync long polling for receiving encryption-related data.
appservice: false
# Require encryption, drop any unencrypted messages.
require: false
# Enable key sharing? If enabled, key requests for rooms where users are in will be fulfilled.
Expand Down
33 changes: 20 additions & 13 deletions mautrix_signal/portal.py
Original file line number Diff line number Diff line change
Expand Up @@ -863,18 +863,7 @@ async def handle_matrix_invite(self, invited_by: u.User, user: u.User | p.Puppet
except RPCError as e:
raise RejectMatrixInvite(str(e)) from e
if user.mxid == self.config["bridge.relay.relaybot"] != "@relaybot:example.com":
if not self.config["bridge.relay.enabled"]:
await self.main_intent.send_notice(
self.mxid, "Relay mode is not enabled in this instance of the bridge."
)
else:
await self.set_relay_user(user)
await self.main_intent.send_notice(
self.mxid,
"Messages from non-logged-in users in this room will now be bridged "
"through the relaybot's Signal account.",
)

await self._handle_relaybot_invited(user)
power_levels = await self.main_intent.get_power_levels(self.mxid)
invitee_pl = power_levels.get_user_level(user.mxid)
if invitee_pl >= 50:
Expand All @@ -890,6 +879,19 @@ async def handle_matrix_invite(self, invited_by: u.User, user: u.User | p.Puppet
await self.signal.get_group(invited_by.username, self.chat_id)
)

async def _handle_relaybot_invited(self, user: u.User) -> None:
if not self.config["bridge.relay.enabled"]:
await self.main_intent.send_notice(
self.mxid, "Relay mode is not enabled in this instance of the bridge."
)
else:
await self.set_relay_user(user)
await self.main_intent.send_notice(
self.mxid,
"Messages from non-logged-in users in this room will now be bridged "
"through the relaybot's Signal account.",
)

async def handle_matrix_name(self, user: u.User, name: str) -> None:
if self.name == name or self.is_direct or not name:
return
Expand Down Expand Up @@ -1756,10 +1758,14 @@ async def create_signal_group(
self.mxid, (Membership.JOIN, Membership.INVITE)
)
invitee_addresses = []
relaybot_mxid = self.config["bridge.relay.relaybot"]
relaybot = None
for mxid in user_mxids:
mx_user = await u.User.get_by_mxid(mxid, create=False)
if mx_user and mx_user.address and mx_user.username != source.username:
invitee_addresses.append(mx_user.address)
if mxid == relaybot_mxid != "@relaybot:example.com":
relaybot = mx_user
puppet = await p.Puppet.get_by_mxid(mxid, create=False)
if puppet:
invitee_addresses.append(puppet.address)
Expand Down Expand Up @@ -1787,7 +1793,8 @@ async def create_signal_group(
await self.handle_matrix_join_rules(source, join_rule)
await self.update()
await self.update_bridge_info()
await self.main_intent.send_notice(self.mxid, f"Signal group created. ID: {self.chat_id}")
if relaybot:
await self._handle_relaybot_invited(relaybot)

async def bridge_signal_group(
self, source: u.User, levels: PowerLevelStateEventContent
Expand Down
9 changes: 7 additions & 2 deletions mautrix_signal/signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
TypingMessage,
WebsocketConnectionStateChangeEvent,
)
from mautrix.types import EventID, MessageType, TextMessageEventContent
from mautrix.types import EventID, Format, MessageType, TextMessageEventContent
from mautrix.util.logging import TraceLogger

from . import portal as po, puppet as pu, user as u
Expand Down Expand Up @@ -277,7 +277,12 @@ async def handle_call_message(user: u.User, sender: pu.Puppet, msg: IncomingMess
portal.log.debug(f"Unhandled call message. Likely an ICE message. {msg.call_message}")
return

await sender.intent_for(portal).send_text(portal.mxid, html=msg_html, msgtype=msg_type)
await portal._send_message(
intent=sender.intent_for(portal),
content=TextMessageEventContent(
format=Format.HTML, formatted_body=msg_html, msgtype=msg_type
),
)

@staticmethod
async def handle_own_receipts(sender: pu.Puppet, receipts: list[OwnReadReceipt]) -> None:
Expand Down
7 changes: 1 addition & 6 deletions mautrix_signal/web/provisioning_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,15 +201,10 @@ async def _try_shielded_link(
f"Client cancelled link wait request ({session_id}) before it finished"
)
raise
except TimeoutException:
except (TimeoutException, ScanTimeoutError):
raise web.HTTPBadRequest(
text='{"error": "Signal linking timed out"}', headers=self._headers
)
except ScanTimeoutError:
raise web.HTTPBadRequest(
text='{"error": "Signald websocket disconnected before linking finished"}',
headers=self._headers,
)
except InternalError:
raise web.HTTPInternalServerError(
text='{"error": "Fatal error in Signal linking"}', headers=self._headers
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ commonmark>=0.8,<0.10
aiohttp>=3,<4
yarl>=1,<2
attrs>=19.1
mautrix>=0.17.8,<0.18
mautrix>=0.18.1,<0.19
asyncpg>=0.20,<0.27

0 comments on commit 994f483

Please sign in to comment.