Skip to content
This repository was archived by the owner on Apr 29, 2024. It is now read-only.

Commit

Permalink
Merge pull request #8 from alex-exe/main
Browse files Browse the repository at this point in the history
Pagination support, Emoji fixed
  • Loading branch information
renatomoor authored Feb 19, 2024
2 parents 7bcb234 + 397283d commit f907684
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 11 deletions.
27 changes: 22 additions & 5 deletions scripts/updateChannels.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,33 @@
import {slack} from "../services/slack.js";
import channels from "../stores/channels.js";

export async function updateChannels() {
try {
const channelsList = await slack.client.conversations.list({
types: "public_channel,private_channel,mpim,im",
});
await channels.actions.setChannels(channelsList.channels)
let channelsList = [];
let cursor = undefined;

while (true) {
const result = await slack.client.conversations.list({
types: "public_channel,private_channel,mpim,im",
cursor: cursor,
limit: 1000 // maximum allowed by Slack API
});

channelsList = channelsList.concat(result.channels);

if (!result.response_metadata || !result.response_metadata.next_cursor) {
break;
}

cursor = result.response_metadata.next_cursor;
}

await channels.actions.setChannels(channelsList)
}
catch (error) {
console.error(error);
console.log(error)
}
}

await updateChannels()
await updateChannels()
24 changes: 21 additions & 3 deletions scripts/updateUsers.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
import {slack} from "../services/slack.js";
import users from "../stores/users.js";

export async function updateUsers() {
try {
const usersList = await slack.client.users.list();
await users.actions.setUsers(usersList.members)
let usersList = [];
let cursor = undefined;

while (true) {
const result = await slack.client.users.list({
cursor: cursor,
limit: 1000 // maximum allowed by Slack API
});

usersList = usersList.concat(result.members);

if (!result.response_metadata || !result.response_metadata.next_cursor) {
break;
}

cursor = result.response_metadata.next_cursor;
}

await users.actions.setUsers(usersList)
}
catch (error) {
console.error(error);
}
}

await updateUsers()
await updateUsers()
8 changes: 5 additions & 3 deletions stores/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ const getUserSubtitle = (user) => {
subtitle += user.real_name
}



if (user.profile.status_text !== '') {
subtitle += ' - '
if (user.profile.status_emoji_display_info.length > 0) {
if (user.profile.status_emoji_display_info &&
user.profile.status_emoji_display_info.length > 0 &&
user.profile.status_emoji_display_info[0].unicode) {
subtitle += `${getEmoji(user.profile.status_emoji_display_info[0].unicode)}`
}
subtitle += ' ' + user.profile.status_text
Expand All @@ -51,13 +51,15 @@ const actions = {
user.match = user.profile.real_name_normalized + ' ' + user.profile.display_name
user.autocomplete = user.profile.display_name
user.arg = `slack://user?team=${user.profile.team}&id=${user.id}`

if (user.profile.image_original) {
user.icon = {
path: downloadAndSaveImage(user.profile.image_192, './profile_images/')
}
}
items.push(user)
});

store.data.items = items;
await store.write()
}
Expand Down

0 comments on commit f907684

Please sign in to comment.