zephyr_mirror: Reduce code dupliation in process_notice.
(imported from commit f0d371cfcd3f4f5443dea5dc8f96f53df160d179)
This commit is contained in:
parent
942a9fd661
commit
ad6cc113a3
|
@ -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,
|
else:
|
||||||
'recipient' : to_humbug_username(notice.recipient),
|
zeph['type'] = 'stream'
|
||||||
'zsig' : zsig, # logged here but not used by app
|
zeph['stream'] = zephyr_class
|
||||||
'content' : body }
|
if notice.instance != "":
|
||||||
|
zeph['subject'] = notice.instance.lower()
|
||||||
else:
|
else:
|
||||||
zeph = { 'type' : 'stream',
|
|
||||||
'time' : str(notice.time),
|
|
||||||
'sender' : notice.sender,
|
|
||||||
'stream' : zephyr_class,
|
|
||||||
'subject' : instance,
|
|
||||||
'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()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue