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