]> git.sesse.net Git - skvidarsync/commitdiff
Factor out best_name_for_log.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 29 Oct 2023 22:48:49 +0000 (23:48 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 29 Oct 2023 22:48:49 +0000 (23:48 +0100)
bin/sync.pl

index 85cfb2c985c3e72a2c7007eb508627038e2fc9a8..dba9e46f91bc0aefeb25683eb7a4ea42da9b9654 100644 (file)
@@ -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) {