long_term_idle_helper: Take timestamp_from_message callable arg.

message["ts"] is slack-specific. For this to be a general util function
it needs to take a callable that will grab a timestamp from the message
dict (which has varying formats depending on what we're importing from).
This commit is contained in:
Mateusz Mandera
2022-05-31 22:13:17 +02:00
committed by Tim Abbott
parent a86aa13e57
commit 9e56e71afe
2 changed files with 7 additions and 1 deletions

View File

@@ -753,6 +753,7 @@ ExternalId = TypeVar("ExternalId")
def long_term_idle_helper(
message_iterator: Iterator[ZerverFieldsT],
user_from_message: Callable[[ZerverFieldsT], Optional[ExternalId]],
timestamp_from_message: Callable[[ZerverFieldsT], float],
zulip_user_id_from_user: Callable[[ExternalId], int],
users: List[ZerverFieldsT],
zerver_userprofile: List[ZerverFieldsT],
@@ -767,7 +768,7 @@ def long_term_idle_helper(
recent_senders: Set[ExternalId] = set()
NOW = float(timezone_now().timestamp())
for message in message_iterator:
timestamp = float(message["ts"])
timestamp = timestamp_from_message(message)
user = user_from_message(message)
if user is None:
continue

View File

@@ -648,6 +648,7 @@ def process_long_term_idle_users(
return long_term_idle_helper(
get_messages_iterator(slack_data_dir, added_channels, added_mpims, dm_members),
get_message_sending_user,
get_timestamp_from_message,
lambda id: slack_user_id_to_zulip_user_id[id],
users,
zerver_userprofile,
@@ -1141,6 +1142,10 @@ def get_message_sending_user(message: ZerverFieldsT) -> Optional[str]:
return None
def get_timestamp_from_message(message: ZerverFieldsT) -> float:
return float(message["ts"])
def fetch_shared_channel_users(
user_list: List[ZerverFieldsT], slack_data_dir: str, token: str
) -> None: