Fix own profile error
Problem: A `null` relationship represents when it's your profile, which isn't very intuitive. It causes an error when we try to check for the `blocking` and `following` properties, which don't exist on `null`. Solution: Instead of `null`, set a `me` property to tell whether this relationship is our own profile.
This commit is contained in:
parent
e7bd3ed305
commit
7e22829578
@ -353,7 +353,7 @@ router
|
||||
name,
|
||||
description,
|
||||
avatarUrl,
|
||||
relationship: null,
|
||||
relationship: { me: true },
|
||||
});
|
||||
})
|
||||
.get("/profile/edit", async (ctx) => {
|
||||
|
@ -203,12 +203,16 @@ module.exports = ({ cooler, isPublic }) => {
|
||||
blocking: false,
|
||||
following: false,
|
||||
}),
|
||||
/**
|
||||
* @param feedId {string}
|
||||
* @returns {Promise<{me: boolean, following: boolean, blocking: boolean }>}
|
||||
*/
|
||||
getRelationship: async (feedId) => {
|
||||
const ssb = await cooler.open();
|
||||
const { id } = ssb;
|
||||
|
||||
if (feedId === id) {
|
||||
return null;
|
||||
return { me: true, following: false, blocking: false };
|
||||
}
|
||||
|
||||
const isFollowing = await ssb.friends.isFollowing({
|
||||
@ -222,6 +226,7 @@ module.exports = ({ cooler, isPublic }) => {
|
||||
});
|
||||
|
||||
return {
|
||||
me: false,
|
||||
following: isFollowing,
|
||||
blocking: isBlocking,
|
||||
};
|
||||
|
@ -618,6 +618,9 @@ exports.editProfileView = ({ name, description }) =>
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* @param {{avatarUrl: string, description: string, feedId: string, messages: any[], name: string, relationship: object}} input
|
||||
*/
|
||||
exports.authorView = ({
|
||||
avatarUrl,
|
||||
description,
|
||||
@ -647,7 +650,7 @@ exports.authorView = ({
|
||||
)
|
||||
);
|
||||
|
||||
if (relationship !== null) {
|
||||
if (relationship.me === false) {
|
||||
if (relationship.following) {
|
||||
addForm({ action: "unfollow" });
|
||||
} else if (relationship.blocking) {
|
||||
@ -659,7 +662,7 @@ exports.authorView = ({
|
||||
}
|
||||
|
||||
const relationshipText = (() => {
|
||||
if (relationship === null) {
|
||||
if (relationship.me === true) {
|
||||
return i18n.relationshipYou;
|
||||
} else if (
|
||||
relationship.following === true &&
|
||||
@ -703,7 +706,7 @@ exports.authorView = ({
|
||||
a({ href: `/likes/${encodeURIComponent(feedId)}` }, i18n.viewLikes),
|
||||
span(nbsp, relationshipText),
|
||||
...contactForms,
|
||||
relationship === null
|
||||
relationship.me
|
||||
? a({ href: `/profile/edit` }, nbsp, i18n.editProfile)
|
||||
: null
|
||||
),
|
||||
|
Loading…
Reference in New Issue
Block a user