return %seen_names;
}
+# 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.)
+sub create_reaction_log {
+ my ($dbh, $invitation_ts, $slack_userid_to_real_name, $slack_userid_to_slack_name) = @_;
+
+ my $q = $dbh->prepare('select userid,event_type,reaction,to_char(event_ts,\'YYYY-mm-dd HH24:MI\') as event_ts from ( select distinct on (channel,ts,userid,reaction) userid,event_type,reaction,timestamptz \'1970-01-01 utc\' + event_ts::float * interval \'1 second\' as event_ts from reaction_log where channel=? and ts=? and reaction in (\'heart\',\'open_mouth\') order by channel,ts,userid,reaction,event_ts desc ) t1 where event_ts > current_timestamp - interval \'8 hours\' order by event_ts desc limit 50');
+ $q->execute($config::invitation_channel, $invitation_ts);
+ my @recent_changes = ();
+ while (my $ref = $q->fetchrow_hashref) {
+ my $msg = $ref->{'event_ts'};
+ if ($ref->{'event_type'} eq 'reaction_added') {
+ $msg .= ' +';
+ } else {
+ $msg .= ' –';
+ }
+ if ($ref->{'reaction'} eq 'open_mouth') {
+ $msg .= '😮';
+ } else {
+ $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)';
+ }
+ push @recent_changes, { values => [{ userEnteredValue => { stringValue => $msg } }] };
+ }
+ while (scalar @recent_changes < 50) {
+ push @recent_changes, { values => [{ userEnteredValue => { stringValue => '' } }] };
+ }
+ return @recent_changes;
+}
skv_log("Siste sync startet: " . POSIX::ctime(time));
}
}
-# 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.)
-$q = $dbh->prepare('select userid,event_type,reaction,to_char(event_ts,\'YYYY-mm-dd HH24:MI\') as event_ts from ( select distinct on (channel,ts,userid,reaction) userid,event_type,reaction,timestamptz \'1970-01-01 utc\' + event_ts::float * interval \'1 second\' as event_ts from reaction_log where channel=? and ts=? and reaction in (\'heart\',\'open_mouth\') order by channel,ts,userid,reaction,event_ts desc ) t1 where event_ts > current_timestamp - interval \'8 hours\' order by event_ts desc limit 50');
-$q->execute($config::invitation_channel, $invitation_ts);
-my @recent_changes = ();
-while (my $ref = $q->fetchrow_hashref) {
- my $msg = $ref->{'event_ts'};
- if ($ref->{'event_type'} eq 'reaction_added') {
- $msg .= ' +';
- } else {
- $msg .= ' –';
- }
- if ($ref->{'reaction'} eq 'open_mouth') {
- $msg .= '😮';
- } else {
- $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)';
- }
- push @recent_changes, { values => [{ userEnteredValue => { stringValue => $msg } }] };
-}
-while (scalar @recent_changes < 50) {
- push @recent_changes, { values => [{ userEnteredValue => { stringValue => '' } }] };
-}
+my @recent_changes = create_reaction_log($dbh, $invitation_ts, \%slack_userid_to_real_name, \%slack_userid_to_slack_name);
push @yellow_updates, {
updateCells => {
rows => \@recent_changes,