zephyr_mirror: Reduce code dupliation in process_notice.

(imported from commit f0d371cfcd3f4f5443dea5dc8f96f53df160d179)
This commit is contained in:
Tim Abbott 2012-11-02 17:06:59 -04:00
parent 942a9fd661
commit ad6cc113a3

View file

@ -235,7 +235,6 @@ def process_notice(notice, log):
return return
zephyr_class = notice.cls.lower() zephyr_class = notice.cls.lower()
instance = notice.instance.lower()
if (zephyr_class == "message" and notice.recipient != ""): if (zephyr_class == "message" and notice.recipient != ""):
is_personal = True is_personal = True
@ -247,49 +246,43 @@ def process_notice(notice, log):
if notice.sender not in huddle_recipients_list: if notice.sender not in huddle_recipients_list:
huddle_recipients_list.append(to_humbug_username(notice.sender)) huddle_recipients_list.append(to_humbug_username(notice.sender))
huddle_recipients = ",".join(huddle_recipients_list) huddle_recipients = ",".join(huddle_recipients_list)
if (zephyr_class == "mail" and instance == "inbox"): body = body.split("\n", 1)[1]
if (zephyr_class == "mail" and notice.instance.lower() == "inbox"):
is_personal = True is_personal = True
# Drop messages not to the listed subscriptions # Drop messages not to the listed subscriptions
if (zephyr_class not in current_zephyr_subs) and not \ if (zephyr_class not in current_zephyr_subs) and not \
(is_personal and options.forward_personals): (is_personal and options.forward_personals):
print "%s: zephyr=>humbug: Skipping ... %s/%s/%s" % \ print "%s: zephyr=>humbug: Skipping ... %s/%s/%s" % \
(datetime.datetime.now(), zephyr_class, instance, is_personal) (datetime.datetime.now(), zephyr_class, notice.instance, is_personal)
return return
zeph = { 'time' : str(notice.time),
'sender' : notice.sender,
'zsig' : zsig, # logged here but not used by app
'content' : body }
if is_huddle: if is_huddle:
zeph = { 'type' : 'personal', zeph['type'] = 'personal'
'time' : str(notice.time), zeph['recipient'] = huddle_recipients
'sender' : notice.sender,
'recipient' : huddle_recipients,
'zsig' : zsig, # logged here but not used by app
'content' : body.split("\n", 1)[1] }
elif is_personal: elif is_personal:
zeph = { 'type' : 'personal', zeph['type'] = 'personal'
'time' : str(notice.time), zeph['recipient'] = to_humbug_username(notice.recipient)
'sender' : notice.sender,
'recipient' : to_humbug_username(notice.recipient),
'zsig' : zsig, # logged here but not used by app
'content' : body }
else: else:
zeph = { 'type' : 'stream', zeph['type'] = 'stream'
'time' : str(notice.time), zeph['stream'] = zephyr_class
'sender' : notice.sender, if notice.instance != "":
'stream' : zephyr_class, zeph['subject'] = notice.instance.lower()
'subject' : instance, else:
'zsig' : zsig, # logged here but not used by app
'content' : body }
if zeph["subject"] == "":
zeph["subject"] = "personal" zeph["subject"] = "personal"
# Add instances in for instanced personals # Add instances in for instanced personals
if zeph['type'] == "personal" and instance != "personal": if zeph['type'] == "personal" and notice.instance != "personal":
zeph["content"] = "[-i %s]" % (instance,) + "\n" + zeph["content"] zeph["content"] = "[-i %s]" % (notice.instance,) + "\n" + zeph["content"]
zeph = decode_unicode_byte_strings(zeph) zeph = decode_unicode_byte_strings(zeph)
print "%s: zephyr=>humbug: received a message on %s/%s from %s..." % \ print "%s: zephyr=>humbug: received a message on %s/%s from %s..." % \
(datetime.datetime.now(), zephyr_class, instance, notice.sender) (datetime.datetime.now(), zephyr_class, notice.instance, notice.sender)
log.write(simplejson.dumps(zeph) + '\n') log.write(simplejson.dumps(zeph) + '\n')
log.flush() log.flush()