aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2016-09-17 18:17:51 -0400
committerTeddy Wing2016-09-17 18:17:51 -0400
commit11b0f2589004d78841f249deaa3a9b0390d91a9f (patch)
tree6152931f9878d5d1946da40a4226e13c7ce3e93a
parent5290854d1dfa9c6750c153574b6dcca40e41121e (diff)
downloadirssi-slack-profile-11b0f2589004d78841f249deaa3a9b0390d91a9f.tar.bz2
complete_profile_field: Correctly get current nick
Previously we tried getting the current nick as `$server->{'nick'}`. This was, however, just a placeholder. Sure, it's how we got the current nick in an `Irssi::command_bind`, but we don't have a `$server` argument passed to us in the `complete word` signal. Instead, we get the current server from the active window passed to the signal, and from that server then obtain the current nick. This allows us to add custom field labels to the completion list. We also wrap all of this in an `if` statement that checks whether there is an active server on the window object. If not, then we don't add custom fields to the completion list. Without this condition, trying to use `$window->{'active_server'}` would prevent _all_ completions from working. Instead, we still want default Slack profile fields to continue working because they don't depend on an API call. We just want to disable completions for custom fields because they depend on a request to the user profile API endpoint.
-rw-r--r--slack_profile.pl8
1 files changed, 5 insertions, 3 deletions
diff --git a/slack_profile.pl b/slack_profile.pl
index 6cfe0d7..1f9f3a7 100644
--- a/slack_profile.pl
+++ b/slack_profile.pl
@@ -174,10 +174,12 @@ sub complete_profile_field {
my @profile_fields = qw(first_name last_name email phone skype title);
- my $user = find_user($server->{'nick'});
+ if ($window->{'active_server'}) {
+ my $user = find_user($window->{'active_server'}->{'nick'});
- for my $custom_field (keys %{$user->{'fields'}}) {
- push @profile_fields, underscorize($user->{'fields'}->{$custom_field}->{'label'});
+ for my $custom_field (keys %{$user->{'fields'}}) {
+ push @profile_fields, underscorize($user->{'fields'}->{$custom_field}->{'label'});
+ }
}
if ($word ne '') {