From fc827b42d333d4f7b4c5014d5decd2e64562fc5b Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Sun, 29 Oct 2023 23:48:49 +0100 Subject: [PATCH] Factor out best_name_for_log. --- bin/sync.pl | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/bin/sync.pl b/bin/sync.pl index 85cfb2c..dba9e46 100644 --- a/bin/sync.pl +++ b/bin/sync.pl @@ -179,6 +179,19 @@ sub find_where_each_name_is { return %seen_names; } +sub best_name_for_log { + my ($userid, $slack_userid_to_real_name, $slack_userid_to_slack_name) = @_; + if (exists($slack_userid_to_real_name->{$userid})) { + return $slack_userid_to_real_name->{$userid}; + } elsif (exists($slack_userid_to_slack_name->{$userid})) { + return $slack_userid_to_slack_name->{$userid} . ' (fant ikke regneark-navn)'; + } else { + # Should only happen if we didn't see the initial reaction_add, only reaction_remove. + # (TODO: Is the comment above true anymore, now that we use this from multiple contexts?) + return $userid . ' (fant ikke Slack-navn)'; + } +} + # Add the reaction log. (This only takes into account the last change # for each user; earlier ones are irrelevant and don't count. But it # doesn't deduplicate across reactions. Meh.) @@ -201,14 +214,7 @@ sub create_reaction_log { $msg .= '❤️'; } $msg .= ' '; - if (exists($slack_userid_to_real_name->{$ref->{'userid'}})) { - $msg .= $slack_userid_to_real_name->{$ref->{'userid'}}; - } elsif (exists($slack_userid_to_slack_name->{$ref->{'userid'}})) { - $msg .= $slack_userid_to_slack_name->{$ref->{'userid'}} . ' (fant ikke regneark-navn)'; - } else { - # Should only happen if we didn't see the initial reaction_add, only reaction_remove. - $msg .= $ref->{'userid'} . ' (fant ikke Slack-navn)'; - } + $msg .= best_name_for_log($ref->{'userid'}, $slack_userid_to_real_name, $slack_userid_to_slack_name); push @recent_changes, { values => [{ userEnteredValue => { stringValue => $msg } }] }; } while (scalar @recent_changes < 50) { -- 2.39.5