From 1443082991726385478c19e45a16eb5cf427b31d Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Wed, 24 Jul 2019 02:12:12 +0300 Subject: [PATCH 1/5] Change default port to 29317. Fixes #345 --- example-config.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/example-config.yaml b/example-config.yaml index 1c80967e..a07555e2 100644 --- a/example-config.yaml +++ b/example-config.yaml @@ -12,11 +12,11 @@ homeserver: # Changing these values requires regeneration of the registration. appservice: # The address that the homeserver can use to connect to this appservice. - address: http://localhost:8080 + address: http://localhost:29317 # The hostname and port where this appservice should listen. hostname: 0.0.0.0 - port: 8080 + port: 29317 # The maximum body size of appservice API requests (from the homeserver) in mebibytes # Usually 1 is enough, but on high-traffic bridges you might need to increase this to avoid 413s max_body_size: 1 From 5fc2907392c52c2c1012e7d38ba73361bd8969ca Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Fri, 26 Jul 2019 22:06:55 +0300 Subject: [PATCH 2/5] Add .gitlab-ci.yml and badges to README --- .gitlab-ci.yml | 38 ++++++++++++++++++++++++++++++++++++++ README.md | 6 ++++++ 2 files changed, 44 insertions(+) create mode 100644 .gitlab-ci.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 00000000..bb7888eb --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,38 @@ +image: docker:stable + +stages: +- build +- push + +default: + before_script: + - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY + +build: + stage: build + script: + - docker pull $CI_REGISTRY_IMAGE:latest || true + - docker build --pull --cache-from $CI_REGISTRY_IMAGE:latest --tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA . + - docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA + +push latest: + stage: push + only: + - master + variables: + GIT_STRATEGY: none + script: + - docker pull $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA + - docker tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA $CI_REGISTRY_IMAGE:latest + - docker push $CI_REGISTRY_IMAGE:latest + +push tag: + stage: push + variables: + GIT_STRATEGY: none + only: + - tags + script: + - docker pull $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA + - docker tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME + - docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME diff --git a/README.md b/README.md index d575b2fc..deb960d4 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,10 @@ # mautrix-telegram +![Languages](https://img.shields.io/github/languages/top/tulir/mautrix-telegram.svg) +[![License](https://img.shields.io/github/license/tulir/mautrix-telegram.svg)](LICENSE) +[![Release](https://img.shields.io/github/release/tulir/mautrix-telegram/all.svg)](https://github.com/tulir/mautrix-telegram/releases) +[![GitLab CI](https://mau.dev/tulir/mautrix-telegram/badges/master/pipeline.svg)](https://mau.dev/tulir/mautrix-telegram/container_registry) +[![Maintainability](https://img.shields.io/codeclimate/maintainability/tulir/mautrix-telegram.svg)](https://codeclimate.com/github/tulir/mautrix-telegram) + A Matrix-Telegram hybrid puppeting/relaybot bridge. ### [Wiki](https://github.com/tulir/mautrix-telegram/wiki) From 9a5506d90185f266139369c52a0340454eb1767a Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Fri, 26 Jul 2019 22:13:08 +0300 Subject: [PATCH 3/5] Include non-master branches in docker image tagging --- .gitlab-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index bb7888eb..3afa3d4f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -30,8 +30,8 @@ push tag: stage: push variables: GIT_STRATEGY: none - only: - - tags + except: + - master script: - docker pull $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA - docker tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME From dd683af5f520f9029f2174ce6e01e0fbf051aad2 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Mon, 29 Jul 2019 19:59:34 +0300 Subject: [PATCH 4/5] Add hacky fix for edit reply fallbacks --- mautrix_telegram/formatter/from_matrix/parser.py | 4 +++- mautrix_telegram/portal.py | 1 - 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/mautrix_telegram/formatter/from_matrix/parser.py b/mautrix_telegram/formatter/from_matrix/parser.py index 908be822..ad019098 100644 --- a/mautrix_telegram/formatter/from_matrix/parser.py +++ b/mautrix_telegram/formatter/from_matrix/parser.py @@ -170,7 +170,9 @@ class MatrixParser: @classmethod def node_to_tmessage(cls, node: HTMLNode, ctx: RecursionContext) -> TelegramMessage: - if node.tag == "ol": + if node.tag == "mx-reply": + return TelegramMessage("") + elif node.tag == "ol": return cls.list_to_tmessage(node, ctx) elif node.tag == "ul": return cls.list_to_tmessage(node, ctx.enter_list()) diff --git a/mautrix_telegram/portal.py b/mautrix_telegram/portal.py index 6db414a2..2be1c05f 100644 --- a/mautrix_telegram/portal.py +++ b/mautrix_telegram/portal.py @@ -998,7 +998,6 @@ class Portal: orig_msg = DBMessage.get_by_mxid(relates_to.get("event_id", ""), self.mxid, space) if orig_msg and "m.new_content" in message: message = message["m.new_content"] - formatter.matrix_reply_to_telegram(message, space, room_id=self.mxid) response = await client.edit_message(self.peer, orig_msg.tgid, message, parse_mode=self._matrix_event_to_entities, link_preview=lp) From 281f7203dc6eec8be9e6489a8bf29ad7e850f07d Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Mon, 29 Jul 2019 20:11:35 +0300 Subject: [PATCH 5/5] Filter non-nice whitespace out of displaynames --- mautrix_telegram/puppet.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/mautrix_telegram/puppet.py b/mautrix_telegram/puppet.py index 3f630066..ede800b0 100644 --- a/mautrix_telegram/puppet.py +++ b/mautrix_telegram/puppet.py @@ -316,14 +316,26 @@ class Puppet: return int(round(similarity * 100)) @staticmethod - def get_displayname(info: User, enable_format: bool = True) -> str: + def _filter_name(name: str) -> str: + if not name: + return "" + whitespace = ("\ufeff", "\u3164", "\u2063", "\u200b", "\u180e", "\u034f", "\u2800", + "\u180e", "\u200b", "\u202f", "\u205f", "\u3000") + name = "".join(char for char in name if char not in whitespace) + name = name.strip() + return name + + @classmethod + def get_displayname(cls, info: User, enable_format: bool = True) -> str: + fn = cls._filter_name(info.first_name) + ln = cls._filter_name(info.last_name) data = { "phone number": info.phone if hasattr(info, "phone") else None, "username": info.username, - "full name": " ".join([info.first_name or "", info.last_name or ""]).strip(), - "full name reversed": " ".join([info.first_name or "", info.last_name or ""]).strip(), - "first name": info.first_name, - "last name": info.last_name, + "full name": " ".join([fn, ln]).strip(), + "full name reversed": " ".join([ln, fn]).strip(), + "first name": fn, + "last name": ln, } preferences = config["bridge.displayname_preference"] name = None @@ -335,7 +347,7 @@ class Puppet: if isinstance(info, User) and info.deleted: name = f"Deleted account {info.id}" elif not name: - name = info.id + name = str(info.id) if not enable_format: return name