From f960c21931326d665f999d79810d9064302d4c20 Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Fri, 21 Sep 2012 16:24:16 -0400 Subject: [PATCH] zephyr-mirror: Add support for syncing huddles. (imported from commit 0709ca40c5510ed9dbf28c666cff96609e8d41c2) --- zephyr/views.py | 13 +++++++++++++ zephyr/zephyr_mirror.py | 25 +++++++++++++++++++++---- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/zephyr/views.py b/zephyr/views.py index 1293cf9b2a..dc7f62c067 100644 --- a/zephyr/views.py +++ b/zephyr/views.py @@ -164,6 +164,8 @@ def get_updates_longpoll(request, handler): def zephyr(request): return zephyr_backend(request, request.user) +huddle_dedup = {} + @login_required @require_post def forge_zephyr(request): @@ -178,6 +180,17 @@ def forge_zephyr(request): sanitize_identifier(request.POST['shortname'])) user = User.objects.get(email=email) + if (request.POST['type'] == 'personal' and ',' in request.POST['recipient']): + # Huddle message, need to make sure we're not syncing it twice! + huddle_val = hashlib.md5(request.POST['sender'] + "|" + + request.POST['new_zephyr'] + "|" + + request.POST['time']).hexdigest() + if huddle_val in huddle_dedup: + # This is a duplicate huddle message, deduplicate! + return json_success() + else: + huddle_dedup[huddle_val] = True + return zephyr_backend(request, user) md_engine = markdown.Markdown( diff --git a/zephyr/zephyr_mirror.py b/zephyr/zephyr_mirror.py index cd8b1a773c..3fbaf2c030 100644 --- a/zephyr/zephyr_mirror.py +++ b/zephyr/zephyr_mirror.py @@ -113,10 +113,23 @@ with open('zephyrs', 'a') as log: try: notice = zephyr.receive(block=True) zsig, body = notice.message.split("\x00", 1) + is_personal = False + is_huddle = False + + sender = notice.sender.lower().replace("athena.mit.edu", "mit.edu") + recipient = notice.recipient.lower().replace("athena.mit.edu", "mit.edu") if (notice.cls == "message" and notice.instance == "personal"): is_personal = True + if body.startswith("CC:"): + is_huddle = True + # Map "CC: sipbtest espuser" => "starnine@mit.edu,espuser@mit.edu" + huddle_recipients_list = [x + "@mit.edu" for x in + body.split("\n")[0][4:].split()] + if sender not in huddle_recipients_list: + huddle_recipients_list.append(sender) + huddle_recipients = ",".join(huddle_recipients_list) if notice.opcode != "": # skip PING messages @@ -128,10 +141,14 @@ with open('zephyrs', 'a') as log: print "Skipping ...", notice.cls, notice.instance, is_personal continue - sender = notice.sender.replace("ATHENA.MIT.EDU", "mit.edu")[:30] - recipient = notice.recipient.replace("ATHENA.MIT.EDU", "mit.edu") - - if is_personal: + if is_huddle: + zeph = { 'type' : 'personal', + 'time' : str(notice.time), + 'sender' : sender, + 'recipient' : huddle_recipients, + 'zsig' : zsig, # logged here but not used by app + 'new_zephyr': body.split("\n", 1)[1] } + elif is_personal: zeph = { 'type' : 'personal', 'time' : str(notice.time), 'sender' : sender,