Skip to content

Commit

Permalink
Add utils.py
Browse files Browse the repository at this point in the history
  • Loading branch information
learnforpractice committed Dec 26, 2022
1 parent 5322c56 commit 562cb2c
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions pysrc/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import hashlib

def unique_conversation_id(user_id: str, recipient_id: str) -> str:
md5 = hashlib.md5()
if user_id < recipient_id:
md5.update(user_id.encode())
md5.update(recipient_id.encode())
else:
md5.update(recipient_id.encode())
md5.update(user_id.encode())
digest = bytearray(md5.digest())
digest[6] = (digest[6] & 0x0f) | 0x30
digest[8] = (digest[8] & 0x3f) | 0x80
return f'{digest[0:4].hex()}-{digest[4:6].hex()}-{digest[6:8].hex()}-{digest[8:10].hex()}-{digest[10:].hex()}'

0 comments on commit 562cb2c

Please sign in to comment.