Skip to content

Commit

Permalink
Add option to disable displaying the sender app's name
Browse files Browse the repository at this point in the history
  • Loading branch information
immanuelfodor committed Jun 1, 2021
1 parent ae5189a commit 4fda6c0
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
MESSAGE_FORMAT=yaml
USE_MARKDOWN=False
ALLOW_UNICODE=True
DISPLAY_APP_NAME=True

MATRIX_SERVER=https://matrix.example.org
MATRIX_SSLVERIFY=True
Expand Down
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ ENV LOGIN_STORE_PATH=/config
ENV MESSAGE_FORMAT=yaml
ENV USE_MARKDOWN=False
ENV ALLOW_UNICODE=True
ENV DISPLAY_APP_NAME=True

ENV MATRIX_SERVER=https://matrix.example.org
ENV MATRIX_SSLVERIFY=True
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ The gateway tries to join all of the specified rooms in the `.env` file on start
- Message formatting via `MESSAGE_FORMAT`: `raw` | `json` | `yaml` (default)
- Markdown formatting turned on or off via `USE_MARKDOWN`: `True` | `False` (default)
- ASCII (e.g., `\u1234`) or Unicode characters (e.g., `ű`) in JSON or YAML content via `ALLOW_UNICODE`: `True` (default) | `False`
- Include the sender app name in messages via `DISPLAY_APP_NAME`: `True` (default) | `False`

### Matrix connection parameters

Expand Down
8 changes: 6 additions & 2 deletions src/E2EEClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,13 @@ async def send_message(
if sync:
await self.client.sync(timeout=3000, full_state=True)

msg_prefix = ""
if os.environ['DISPLAY_APP_NAME'] == 'True':
msg_prefix = f"**{sender}** says: \n"

content = {
'msgtype': 'm.text',
'body': f"**{sender}** says: \n{message}",
'body': f"{msg_prefix}{message}",
}
if os.environ['USE_MARKDOWN'] == 'True':
# Markdown formatting removes YAML newlines if not padded with spaces,
Expand All @@ -136,7 +140,7 @@ async def send_message(

content['format'] = 'org.matrix.custom.html'
content['formatted_body'] = markdown(
f"**{sender}** says: \n{message}", extensions=['extra'])
f"{msg_prefix}{message}", extensions=['extra'])

await self.client.room_send(
room_id=room,
Expand Down

0 comments on commit 4fda6c0

Please sign in to comment.