mirror of https://github.com/zulip/zulip.git
zephyr-mirror: Add support for syncing huddles.
(imported from commit 0709ca40c5510ed9dbf28c666cff96609e8d41c2)
This commit is contained in:
parent
f9eed538f6
commit
f960c21931
|
@ -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(
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue