refactor: Extract get_user_info_for_message_updates.

We'll want to expand this to get users that were mentioned in
the prior message, but this commit is just a refactoring.
This commit is contained in:
Steve Howell
2017-09-27 06:06:03 -07:00
committed by Tim Abbott
parent 5abf52de71
commit 646abb57b7
3 changed files with 43 additions and 13 deletions

View File

@@ -3001,6 +3001,28 @@ def truncate_topic(topic):
# type: (Text) -> Text
return truncate_content(topic, MAX_SUBJECT_LENGTH, "...")
MessageUpdateUserInfoResult = TypedDict('MessageUpdateUserInfoResult', {
'message_user_ids': Set[int],
})
def get_user_info_for_message_updates(message_id):
# type: (int) -> MessageUpdateUserInfoResult
# We exclude UserMessage.flags.historical rows since those
# users did not receive the message originally, and thus
# probably are not relevant for reprocessed alert_words,
# mentions and similar rendering features. This may be a
# decision we change in the future.
query = UserMessage.objects.filter(
message=message_id,
flags=~UserMessage.flags.historical
)
message_user_ids = set(query.values_list('user_profile_id', flat=True))
return dict(
message_user_ids=message_user_ids,
)
def update_user_message_flags(message, ums):
# type: (Message, Iterable[UserMessage]) -> None