Issue 126: Show recipients of private messages

This commit is contained in:
Cecilia Lindskog 2021-01-26 10:33:29 +01:00
parent afb50b6b09
commit 3c771da8ff
2 changed files with 46 additions and 12 deletions

View File

@ -691,6 +691,26 @@ module.exports = ({ cooler, isPublic }) => {
} }
}); });
}; };
const getUserInfo = async (feedId) => {
const id = feedId;
const pendingName = models.about.name(feedId);
const pendingAvatarMsg = models.about.image(feedId);
const pending = [pendingName, pendingAvatarMsg];
const [name, avatarMsg] = await Promise.all(pending);
const avatarId =
avatarMsg != null && typeof avatarMsg.link === "string"
? avatarMsg.link || nullImage
: avatarMsg || nullImage;
const avatarUrl = `/image/64/${encodeURIComponent(avatarId)}`;
return { name, id, avatarId, avatarUrl };
};
const transform = (ssb, messages, myFeedId) => const transform = (ssb, messages, myFeedId) =>
Promise.all( Promise.all(
messages.map(async (msg) => { messages.map(async (msg) => {
@ -767,11 +787,9 @@ module.exports = ({ cooler, isPublic }) => {
); );
const voterNames = await Promise.all(pendingVoterNames); const voterNames = await Promise.all(pendingVoterNames);
const pendingName = models.about.name(msg.value.author); const { name, avatarId, avatarUrl } = await getUserInfo(
const pendingAvatarMsg = models.about.image(msg.value.author); msg.value.author
);
const pending = [pendingName, pendingAvatarMsg];
const [name, avatarMsg] = await Promise.all(pending);
if (isPublic) { if (isPublic) {
const publicOptIn = await models.about.publicWebHosting( const publicOptIn = await models.about.publicWebHosting(
@ -797,13 +815,6 @@ module.exports = ({ cooler, isPublic }) => {
msg.value.content.text += `\n\n#${channel}`; msg.value.content.text += `\n\n#${channel}`;
} }
const avatarId =
avatarMsg != null && typeof avatarMsg.link === "string"
? avatarMsg.link || nullImage
: avatarMsg || nullImage;
const avatarUrl = `/image/64/${encodeURIComponent(avatarId)}`;
const ts = new Date(msg.value.timestamp); const ts = new Date(msg.value.timestamp);
let isoTs; let isoTs;
@ -840,6 +851,14 @@ module.exports = ({ cooler, isPublic }) => {
lodash.set(msg, "value.meta.votes", voterNames); lodash.set(msg, "value.meta.votes", voterNames);
lodash.set(msg, "value.meta.voted", voters.includes(myFeedId)); lodash.set(msg, "value.meta.voted", voters.includes(myFeedId));
if (isPrivate(msg)) {
msg.value.meta.recpsInfo = await Promise.all(
msg.value.content.recps.map((feedId) => {
return getUserInfo(feedId);
})
);
}
return msg; return msg;
}) })
); );

View File

@ -393,8 +393,22 @@ const post = ({ msg, aside = false }) => {
const messageClasses = ["post"]; const messageClasses = ["post"];
const recps = [];
const addRecps = (recpsInfo) => {
recpsInfo.forEach(function (recp) {
recps.push(
a(
{ href: `/author/${encodeURIComponent(recp.id)}` },
img({ class: "avatar", src: recp.avatarUrl, alt: "" })
)
);
});
};
if (isPrivate) { if (isPrivate) {
messageClasses.push("private"); messageClasses.push("private");
addRecps(msg.value.meta.recpsInfo);
} }
if (isThreadTarget) { if (isThreadTarget) {
@ -449,6 +463,7 @@ const post = ({ msg, aside = false }) => {
title: timeAbsolute, title: timeAbsolute,
}, },
isPrivate ? "🔒" : null, isPrivate ? "🔒" : null,
isPrivate ? recps : null,
a({ href: url.link }, nbsp, timeAgo) a({ href: url.link }, nbsp, timeAgo)
) )
) )