mirror of https://github.com/zulip/zulip.git
populate_db: Simplify a bunch of message type checking code.
(imported from commit 6eaf857d3eef8d700c5251bdd242b9bbbc8cdb72)
This commit is contained in:
parent
970969fc44
commit
8b15b11cbd
|
@ -283,26 +283,17 @@ def restore_saved_messages():
|
||||||
def fix_email(email):
|
def fix_email(email):
|
||||||
return email.strip().lower()
|
return email.strip().lower()
|
||||||
|
|
||||||
if message_type == "subscription_property":
|
if message_type in ["stream", "huddle", "personal"]:
|
||||||
pass
|
old_message["sender_email"] = fix_email(old_message["sender_email"])
|
||||||
elif message_type.startswith("subscription"):
|
if message_type in ["subscription_added", "subscription_removed"]:
|
||||||
old_message["domain"] = old_message["domain"].lower()
|
old_message["domain"] = old_message["domain"].lower()
|
||||||
old_message["user"] = fix_email(old_message["user"])
|
old_message["user"] = fix_email(old_message["user"])
|
||||||
elif message_type.startswith("user_"):
|
elif message_type.startswith("user_"):
|
||||||
old_message["user"] = fix_email(old_message["user"])
|
old_message["user"] = fix_email(old_message["user"])
|
||||||
elif message_type.startswith("enable_"):
|
elif message_type.startswith("enable_"):
|
||||||
old_message["user"] = fix_email(old_message["user"])
|
old_message["user"] = fix_email(old_message["user"])
|
||||||
elif message_type.startswith("realm_"):
|
|
||||||
pass
|
|
||||||
elif message_type == "default_streams":
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
old_message["sender_email"] = fix_email(old_message["sender_email"])
|
|
||||||
|
|
||||||
|
if message_type == 'personal':
|
||||||
if message_type == 'stream':
|
|
||||||
pass
|
|
||||||
elif message_type == 'personal':
|
|
||||||
old_message["recipient"][0]["email"] = fix_email(old_message["recipient"][0]["email"])
|
old_message["recipient"][0]["email"] = fix_email(old_message["recipient"][0]["email"])
|
||||||
elif message_type == "huddle":
|
elif message_type == "huddle":
|
||||||
for i in xrange(len(old_message["recipient"])):
|
for i in xrange(len(old_message["recipient"])):
|
||||||
|
@ -310,27 +301,20 @@ def restore_saved_messages():
|
||||||
|
|
||||||
old_messages.append(old_message)
|
old_messages.append(old_message)
|
||||||
|
|
||||||
if message_type == "subscription_property":
|
if message_type in ["subscription_added", "subscription_removed"]:
|
||||||
continue
|
|
||||||
elif message_type.startswith("subscription"):
|
|
||||||
stream_name = old_message["name"].strip()
|
stream_name = old_message["name"].strip()
|
||||||
canon_stream_name = stream_name.lower()
|
canon_stream_name = stream_name.lower()
|
||||||
if canon_stream_name not in stream_dict:
|
if canon_stream_name not in stream_dict:
|
||||||
stream_dict[(old_message["domain"], canon_stream_name)] = \
|
stream_dict[(old_message["domain"], canon_stream_name)] = \
|
||||||
(old_message["domain"], stream_name)
|
(old_message["domain"], stream_name)
|
||||||
continue
|
|
||||||
elif message_type == "user_created":
|
elif message_type == "user_created":
|
||||||
user_set.add((old_message["user"], old_message["full_name"], old_message["short_name"], False))
|
user_set.add((old_message["user"], old_message["full_name"], old_message["short_name"], False))
|
||||||
continue
|
|
||||||
elif message_type.startswith("user_"):
|
|
||||||
continue
|
|
||||||
elif message_type.startswith("enable_"):
|
|
||||||
continue
|
|
||||||
elif message_type == "realm_created":
|
elif message_type == "realm_created":
|
||||||
realm_set.add(old_message["domain"])
|
realm_set.add(old_message["domain"])
|
||||||
|
|
||||||
|
if message_type not in ["stream", "huddle", "personal"]:
|
||||||
continue
|
continue
|
||||||
elif message_type == "default_streams":
|
|
||||||
continue
|
|
||||||
sender_email = old_message["sender_email"]
|
sender_email = old_message["sender_email"]
|
||||||
|
|
||||||
domain = sender_email.split('@')[1]
|
domain = sender_email.split('@')[1]
|
||||||
|
@ -431,11 +415,7 @@ def restore_saved_messages():
|
||||||
|
|
||||||
messages_to_create = []
|
messages_to_create = []
|
||||||
for idx, old_message in enumerate(old_messages):
|
for idx, old_message in enumerate(old_messages):
|
||||||
if (old_message["type"].startswith("subscription") or
|
if old_message["type"] not in ["stream", "huddle", "personal"]:
|
||||||
old_message["type"].startswith("user_") or
|
|
||||||
old_message["type"].startswith("enable_") or
|
|
||||||
old_message["type"].startswith("realm_") or
|
|
||||||
old_message["type"] == "default_streams"):
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
message = Message()
|
message = Message()
|
||||||
|
@ -557,6 +537,8 @@ def restore_saved_messages():
|
||||||
continue
|
continue
|
||||||
elif old_message["type"] == "realm_created":
|
elif old_message["type"] == "realm_created":
|
||||||
continue
|
continue
|
||||||
|
if message_type not in ["stream", "huddle", "personal"]:
|
||||||
|
raise RuntimeError("Unexpected message type %s" % (message_type,))
|
||||||
|
|
||||||
message = messages_by_id[current_message_id]
|
message = messages_by_id[current_message_id]
|
||||||
current_message_id += 1
|
current_message_id += 1
|
||||||
|
|
Loading…
Reference in New Issue