From d067faed7b4cc05b7c5d312d433ba1d98a935c16 Mon Sep 17 00:00:00 2001 From: Rayan fernandes <37145078+Rayanfer32@users.noreply.github.com> Date: Fri, 11 Jun 2021 23:37:48 +0530 Subject: [PATCH] =?UTF-8?q?=F0=9F=A9=B9=20add=20alias=20duplication=20avoi?= =?UTF-8?q?ding=20logic?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/__init__.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/views/__init__.py b/app/views/__init__.py index 3df6137..538848e 100644 --- a/app/views/__init__.py +++ b/app/views/__init__.py @@ -37,12 +37,14 @@ class Views( def generate_alias_id(self, chat): chat_id = chat.id title = chat.title + while True: - orig_id = f"{title}{chat_id}" # the original id - alias_id = base64.urlsafe_b64encode(hashlib.md5(orig_id.encode()).digest())[:self.url_len].decode() + orig_id = f"{chat_id}" # the original id + unique_hash = hashlib.md5(orig_id.encode()).digest() + alias_id = base64.urlsafe_b64encode(unique_hash).decode()[:self.url_len] if alias_id in self.chat_ids: - self.url_len += 1 # increment url_len just incase the hash is already used. + self.url_len += 1 # increment url_len just incase the hash is already used. continue elif (self.url_len > SHORT_URL_LEN): # reset url_len to initial if hash was unique. self.url_len = SHORT_URL_LEN