Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return new Promise((resolve, reject) => {
const needsNewThread = !thread || thread.threadId !== chatId
if (needsNewThread) {
thread = new Client.Feed.ThreadItems(session, chatId)
}
if (!needsNewThread && !thread.isMoreAvailable()) {
// there aren't any older messages
resolve({thread, messages: []})
}
thread.get().then((messages) => {
if (needsNewThread) {
if (thread.isMoreAvailable()) {
// get the next 20 because the first 20 messages already were fetched with #getChat
return thread.get().then((messages) => resolve({ thread, messages }))
}
// there aren't any older messages
messages = []
}
resolve(unfollowers);
}
const getUsers = (newUsers, allUsers, usersGetter, otherUsersGetter) => {
newUsers.forEach((user) => allUsers.push(user))
// moreAvailable maybe null. We are dodging that.
if (usersGetter.moreAvailable === false && otherUsersGetter.moreAvailable === false){
compare();
} else if (usersGetter.moreAvailable !== false) {
usersGetter.get()
.then((users) => getUsers(users, allUsers, usersGetter, otherUsersGetter))
.catch(reject);
}
}
const followersGetter = new Client.Feed.AccountFollowers(session, accountId);
const followingGetter = new Client.Feed.AccountFollowing(session, accountId)
getUsers([], followers, followersGetter, followingGetter);
getUsers([], following, followingGetter, followersGetter);
})
}
return new Promise((resolve, reject) => {
var feed = new Client.Feed.Inbox(session, 10);
feed.all().then(resolve).catch(reject)
})
}
const getFeed = async (cursor = null) => {
if (user) {
try {
let session = await loadSession(user)
let feed = new api.Feed.Timeline(session)
if (cursor) feed.setCursor(cursor)
let q = await feed.get()
let posts = q.map(el => {
return {
images: el._params.images,
id: el.id,
url: el._params.webLink
}
})
return {
cursor: feed.getCursor(),
posts: posts
.then((users) => {
const userIds = users.map((user) => user.id);
new Client.Feed.UserStory(session, userIds.splice(0, 20)).get()
.then(resolve).catch(reject);
})
.catch(reject)
switch (payloadType) {
case "text":
payloadMessage = `"${threadItem._params.text}"`;
break;
default:
payloadMessage = `[a non-text message of type ${payloadType}]`;
break;
}
return `${senderUsername}: ${chalk.white(payloadMessage)} ${chalk.dim(
`[${moment(payloadCreated).fromNow()}]`
)}`;
};
while (mainLoop) {
const inboxSpinner = ora("Opening inbox").start();
const inbox = await new Client.Feed.Inbox(session);
inboxSpinner.text = "Fetching all threads";
const inboxAll = await inbox.all();
inboxSpinner.succeed();
inboxAll.forEach(m =>
m.accounts.forEach(a => {
if (!instagramAccounts[a.id]) {
instagramAccounts[a.id] = a._params;
}
})
);
const choices = inboxAll.filter(m => m.accounts.length).map(m => ({
name: `${chalk.underline(
`[${m._params.threadTitle}]`
)} - ${parseMessageString(m.items[0])}`,
return new Promise((resolve, reject) => {
new Client.Feed.StoryTray(session).get()
.then((storySets) => {
const userIds = storySets.map((storySet) => `${storySet._params.user.pk}`)
const fullStorySets = {}
const loadFullStories = () => {
new Client.Feed.UserStory(session, userIds.splice(0, 20)).get()
.then((stories) => {
Object.assign(fullStorySets, stories)
userIds.length ? loadFullStories() : resolve(fullStorySets)
})
.catch(reject)
}
loadFullStories()
})
.catch(reject)
})
const refreshInbox = async () => {
ClientInbox = await new Client.Feed.Inbox(session);
inboxBuffer = await getOlder();
};
const fetchOlderToBuffer = async () => {
const loadFullStories = () => {
new Client.Feed.UserStory(session, userIds.splice(0, 20)).get()
.then((stories) => {
Object.assign(fullStorySets, stories)
userIds.length ? loadFullStories() : resolve(fullStorySets)
})
.catch(reject)
}