fix: hydrate friend channels
This commit is contained in:
parent
414793f5eb
commit
ba5e3c71a6
|
@ -53,10 +53,19 @@ export const channelState = async (req, channel) => {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const userFriendships = async (req) => (req.user ? req.user.friendship() : []);
|
||||||
|
|
||||||
export const channelsToHydrate = async (req) => {
|
export const channelsToHydrate = async (req) => {
|
||||||
|
const {User} = allModels();
|
||||||
const channels = await Promise.all(
|
const channels = await Promise.all(
|
||||||
(req.channel ? [req.channel] : [])
|
(req.channel ? [req.channel] : [])
|
||||||
.concat(req.user ? await req.user.favorites() : []),
|
.concat(req.user ? await req.user.favorites() : [])
|
||||||
|
.concat(await Promise.all((await userFriendships(req)).map(
|
||||||
|
async ({adderId, addeeId}) => ({
|
||||||
|
type: 'u',
|
||||||
|
name: (await User.findByPk(adderId !== req.userId ? adderId : addeeId)).redditUsername,
|
||||||
|
}),
|
||||||
|
))),
|
||||||
);
|
);
|
||||||
const channelStrings = channels.map(joinChannel);
|
const channelStrings = channels.map(joinChannel);
|
||||||
const uniqueChannels = (new Set(channelStrings)).values();
|
const uniqueChannels = (new Set(channelStrings)).values();
|
||||||
|
@ -65,8 +74,6 @@ export const channelsToHydrate = async (req) => {
|
||||||
|
|
||||||
const userBlocks = async (req) => (req.user ? req.user.blocks() : []);
|
const userBlocks = async (req) => (req.user ? req.user.blocks() : []);
|
||||||
|
|
||||||
const userFriendships = async (req) => (req.user ? req.user.friendship() : []);
|
|
||||||
|
|
||||||
const userState = async (req) => {
|
const userState = async (req) => {
|
||||||
const {channel, user} = req;
|
const {channel, user} = req;
|
||||||
if (!user) {
|
if (!user) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user