aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2016-09-17 17:54:07 -0400
committerTeddy Wing2016-09-17 17:54:07 -0400
commit735ffb157c4201b92ede11edd2fd1461cf8c8e85 (patch)
tree11229504bdf95dd6031f5a0924704cc1597e496a
parentfbcd0dce92f8fb57d85893b68cd85c9c7466ec6a (diff)
downloadirssi-slack-profile-735ffb157c4201b92ede11edd2fd1461cf8c8e85.tar.bz2
complete_profile_field: Add custom fields to completion list
In addition to the Slack defaults, add custom fields as completions to give users an easy way to modify those as well. We move the requests for the custom fields (profile endpoint) and presence information into `find_user` instead of `swhois` because otherwise the custom fields aren't available to `complete_profile_field` or `update_user_profile` unless an `/swhois` has previously been run for the current nick. That was a bug.
-rw-r--r--slack_profile.pl18
1 files changed, 12 insertions, 6 deletions
diff --git a/slack_profile.pl b/slack_profile.pl
index 7962e02..431b37e 100644
--- a/slack_profile.pl
+++ b/slack_profile.pl
@@ -174,6 +174,12 @@ sub complete_profile_field {
my @profile_fields = qw(first_name last_name email phone skype title);
+ my $user = find_user($server->{'nick'});
+
+ for my $custom_field (keys %{$user->{'fields'}}) {
+ push @profile_fields, underscorize($user->{'fields'}->{$custom_field}->{'label'});
+ }
+
if ($word ne '') {
for my $field (@profile_fields) {
if ($field =~ /^\Q${word}\E/i) {
@@ -239,6 +245,12 @@ sub find_user {
for my $user (@users_list) {
if ($user->{'name'} eq $username) {
+ my $profile = fetch_user_profile($user);
+ $user->{'fields'} = $profile->{'fields'};
+
+ my $presence = fetch_user_presence($user);
+ $user->{'presence'} = $presence;
+
return $user;
}
}
@@ -297,12 +309,6 @@ sub swhois {
$username =~ s/^@//;
if (my $user = find_user($username)) {
- my $profile = fetch_user_profile($user);
- $user->{'fields'} = $profile->{'fields'};
-
- my $presence = fetch_user_presence($user);
- $user->{'presence'} = $presence;
-
print_whois($user);
}
}