Merge pull request #584 from lindskog/issue126

Issue 126: Show recipients of private messages
This commit is contained in:
Christian Bundy 2021-01-27 07:48:41 -08:00 committed by GitHub
commit 0d93578d52
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 52 additions and 12 deletions

View File

@ -691,6 +691,32 @@ module.exports = ({ cooler, isPublic }) => {
}
});
};
const getUserInfo = async (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, feedId, avatarId, avatarUrl };
};
function getRecipientFeedId(recipient) {
if (typeof recipient === "string") {
return recipient;
} else {
return recipient.link;
}
}
const transform = (ssb, messages, myFeedId) =>
Promise.all(
messages.map(async (msg) => {
@ -767,11 +793,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 +821,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 +857,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((recipient) => {
return getUserInfo(getRecipientFeedId(recipient));
})
);
}
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.feedId)}` },
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)
)
)