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) =>
Promise.all(
messages.map(async (msg) => {
@ -767,11 +787,9 @@ module.exports = ({ cooler, isPublic }) => {
);
const voterNames = await Promise.all(pendingVoterNames);
const pendingName = models.about.name(msg.value.author);
const pendingAvatarMsg = models.about.image(msg.value.author);
const pending = [pendingName, pendingAvatarMsg];
const [name, avatarMsg] = await Promise.all(pending);
const { name, avatarId, avatarUrl } = await getUserInfo(
msg.value.author
);
if (isPublic) {
const publicOptIn = await models.about.publicWebHosting(
@ -797,13 +815,6 @@ module.exports = ({ cooler, isPublic }) => {
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);
let isoTs;
@ -840,6 +851,14 @@ module.exports = ({ cooler, isPublic }) => {
lodash.set(msg, "value.meta.votes", voterNames);
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;
})
);

View File

@ -393,8 +393,22 @@ const post = ({ msg, aside = false }) => {
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) {
messageClasses.push("private");
addRecps(msg.value.meta.recpsInfo);
}
if (isThreadTarget) {
@ -449,6 +463,7 @@ const post = ({ msg, aside = false }) => {
title: timeAbsolute,
},
isPrivate ? "🔒" : null,
isPrivate ? recps : null,
a({ href: url.link }, nbsp, timeAgo)
)
)