diff options
| author | Teddy Wing | 2016-09-17 05:47:22 -0400 |
|---|---|---|
| committer | Teddy Wing | 2016-09-17 05:47:22 -0400 |
| commit | 1ede306ed047fa8f7e5219a63570a9c11adeeb72 (patch) | |
| tree | c97b152db236348c3c294458671ff8751fe92204 | |
| parent | 32fbfb50693c7301d6f04c7a139cc49d2d1fb28f (diff) | |
| download | irssi-slack-profile-1ede306ed047fa8f7e5219a63570a9c11adeeb72.tar.bz2 | |
Fix users list bug after running 'sync' command
After running the `/slack_profile_sync` command, you would get an error
trying to get the data from `@users_list` in the loop in `find_user`.
This had to do with retrieving the data from the serialised `Storable`
cache file.
I'm not sure why there's a difference between the `retrieve`d cache
version and the version downloaded and JSON decoded directly from the
API, but that discrepancy caused the error.
Now only refresh the `@users_list` with the `Storable` data if we
haven't already fetched. Otherwise doing this is redundant because
`fetch_users_list` sets `@users_list`.
When we do `retrieve`, do the array trick, because that's the only time
when we need to reach inside an outer array. In the loop, just want to
use the plain `@users_list` so that we can have a consistent interface
for both the API-fetched and cache-fetched versions.
| -rw-r--r-- | slack_profile.pl | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/slack_profile.pl b/slack_profile.pl index 15ce828..14e96dd 100644 --- a/slack_profile.pl +++ b/slack_profile.pl @@ -207,11 +207,13 @@ sub find_user { if (!-s users_list_cache) { fetch_users_list(); } - - @users_list = retrieve(users_list_cache); + else { + @users_list = retrieve(users_list_cache); + @users_list = @{@users_list[0]}; + } } - for my $user (@{@users_list[0]}) { + for my $user (@users_list) { if ($user->{'name'} eq $username) { return $user; } |
