channels.forEach(channel => { const community = communities.find( community => community.id === channel.communityId ); if (community.deletedAt) return; randomAmount({ max: 10 }, () => { const creator = faker.random.arrayElement(users); const thread = generateThread(channel.communityId, channel.id, creator.id); threads.push(thread); }); });
messages.map(message => { randomAmount({ max: 5 }, () => { const user = faker.random.arrayElement(users); reactions.push(generateReaction(user.id, message.id)); }); });
const generateCommunity = () => { const name = faker.company.companyName(); return { id: uuid(), createdAt: faker.date.past(2), name, description: casual.short_description(), website: faker.internet.url(), profilePhoto: faker.image.business(), coverPhoto: faker.image.image(), slug: slugify(name), }; }
threads.forEach(thread => { const channel = channels.find(channel => channel.id === thread.channelId); const threadMessages = []; randomAmount({ max: 10 }, () => { const sender = faker.random.arrayElement(users); const message = generateMessage(sender.id, thread.id, 'story'); messages.push(message); threadMessages.push(message); }); });
const generateThread = (communityId, channelId, creatorId) => { const content = { title: casual.title(), body: JSON.stringify(toJSON(fromPlainText(casual.text()))), }; const createdAt = faker.date.past(2); return { id: uuid(), createdAt, creatorId, channelId, communityId, isPublished: faker.random.boolean(), content, type: 'DRAFTJS', lastActive: faker.date.between(createdAt, new Date()), edits: [ { timestamp: createdAt, content, }, ], modifiedAt: faker.date.between(createdAt, new Date()), }; }
const generateUsersDirectMessageThreads = (threadId, userId) => { const createdAt = faker.date.past(2); const lastActive = faker.date.between(createdAt, faker.date.recent()); const lastSeen = faker.date.between(createdAt, new Date()); return { id: uuid(), createdAt, threadId, userId, lastActive, lastSeen, receiveNotifications: true, }; }
const generateUsersCommunities = (communityId, userId) => { const isOwner = faker.random.boolean(); // for ease of use, set to false const isModerator = false; // if user is either an admin or moderator, they have to be a member // otherwise random chance const isMember = isOwner || isModerator ? true : faker.random.boolean(); // might be blocked as long as they aren't an admin, mod, or member const isBlocked = isOwner || isModerator || isMember ? false : faker.random.boolean(); return { id: uuid(), createdAt: faker.date.past(2), communityId, userId, isOwner, isModerator, isMember, isBlocked, receiveNotifications: true, reputation: 1, }; }
const generateUser = () => { const createdAt = faker.date.past(2); const name = faker.name.findName(); return { id: uuid(), name, description: casual.short_description(), website: faker.internet.url(), username: faker.internet.userName(name), profilePhoto: faker.internet.avatar(), coverPhoto: faker.image.image(), email: faker.internet.email(name), providerId: uuid(), createdAt, // Make sure lastSeen is > createdAt lastSeen: faker.date.between(createdAt, new Date()), }; }