mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-12-02 01:01:20 +00:00
replace getSite().my_user with getMyUser()
This commit is contained in:
parent
1dc544107a
commit
0583505320
10 changed files with 50 additions and 45 deletions
|
@ -28,7 +28,7 @@
|
||||||
"eslint": "^9.14.0",
|
"eslint": "^9.14.0",
|
||||||
"eslint-plugin-prettier": "^5.1.3",
|
"eslint-plugin-prettier": "^5.1.3",
|
||||||
"jest": "^29.5.0",
|
"jest": "^29.5.0",
|
||||||
"lemmy-js-client": "0.20.0-api-v4.0",
|
"lemmy-js-client": "0.20.0-api-v4.5",
|
||||||
"prettier": "^3.2.5",
|
"prettier": "^3.2.5",
|
||||||
"ts-jest": "^29.1.0",
|
"ts-jest": "^29.1.0",
|
||||||
"typescript": "^5.5.4",
|
"typescript": "^5.5.4",
|
||||||
|
|
|
@ -30,8 +30,8 @@ importers:
|
||||||
specifier: ^29.5.0
|
specifier: ^29.5.0
|
||||||
version: 29.7.0(@types/node@22.9.0)
|
version: 29.7.0(@types/node@22.9.0)
|
||||||
lemmy-js-client:
|
lemmy-js-client:
|
||||||
specifier: 0.20.0-api-v4.0
|
specifier: 0.20.0-api-v4.5
|
||||||
version: 0.20.0-api-v4.0
|
version: 0.20.0-api-v4.5
|
||||||
prettier:
|
prettier:
|
||||||
specifier: ^3.2.5
|
specifier: ^3.2.5
|
||||||
version: 3.3.3
|
version: 3.3.3
|
||||||
|
@ -1167,8 +1167,8 @@ packages:
|
||||||
resolution: {integrity: sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==}
|
resolution: {integrity: sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==}
|
||||||
engines: {node: '>=6'}
|
engines: {node: '>=6'}
|
||||||
|
|
||||||
lemmy-js-client@0.20.0-api-v4.0:
|
lemmy-js-client@0.20.0-api-v4.5:
|
||||||
resolution: {integrity: sha512-oS02mNzLYWcDIk3FJj1YvBmgpZJQWr34uuxharPd5jQyU8/Yub4XNHrQnjPX5wrXEC6am5ebR8iQmRuQsPQDmw==}
|
resolution: {integrity: sha512-8Zdjb+oIYMUa5/hvS2zeGoIPLdjM+BODUCvP3/jAA/ipqEiSerJ9BdfIB61cnDE9gXnmjYvEtxnfqRZLlwdLfQ==}
|
||||||
|
|
||||||
leven@3.1.0:
|
leven@3.1.0:
|
||||||
resolution: {integrity: sha512-qsda+H8jTaUaN/x5vzW2rzc+8Rw4TAQ/4KjB46IwK5VH+IlVeeeje/EoZRpiXvIqjFgK84QffqPztGI3VBLG1A==}
|
resolution: {integrity: sha512-qsda+H8jTaUaN/x5vzW2rzc+8Rw4TAQ/4KjB46IwK5VH+IlVeeeje/EoZRpiXvIqjFgK84QffqPztGI3VBLG1A==}
|
||||||
|
@ -3077,7 +3077,7 @@ snapshots:
|
||||||
|
|
||||||
kleur@3.0.3: {}
|
kleur@3.0.3: {}
|
||||||
|
|
||||||
lemmy-js-client@0.20.0-api-v4.0: {}
|
lemmy-js-client@0.20.0-api-v4.5: {}
|
||||||
|
|
||||||
leven@3.1.0: {}
|
leven@3.1.0: {}
|
||||||
|
|
||||||
|
|
|
@ -702,9 +702,9 @@ test("Check that activity from another instance is sent to third instance", asyn
|
||||||
|
|
||||||
test("Fetch in_reply_tos: A is unsubbed from B, B makes a post, and some embedded comments, A subs to B, B updates the lowest level comment, A fetches both the post and all the inreplyto comments for that post.", async () => {
|
test("Fetch in_reply_tos: A is unsubbed from B, B makes a post, and some embedded comments, A subs to B, B updates the lowest level comment, A fetches both the post and all the inreplyto comments for that post.", async () => {
|
||||||
// Unfollow all remote communities
|
// Unfollow all remote communities
|
||||||
let site = await unfollowRemotes(alpha);
|
let my_user = await unfollowRemotes(alpha);
|
||||||
expect(
|
expect(
|
||||||
site.my_user?.follows.filter(c => c.community.local == false).length,
|
my_user.follows.filter(c => c.community.local == false).length,
|
||||||
).toBe(0);
|
).toBe(0);
|
||||||
|
|
||||||
// B creates a post, and two comments, should be invisible to A
|
// B creates a post, and two comments, should be invisible to A
|
||||||
|
|
|
@ -34,6 +34,7 @@ import {
|
||||||
longDelay,
|
longDelay,
|
||||||
editCommunity,
|
editCommunity,
|
||||||
unfollows,
|
unfollows,
|
||||||
|
getMyUser,
|
||||||
} from "./shared";
|
} from "./shared";
|
||||||
import { EditCommunity, EditSite } from "lemmy-js-client";
|
import { EditCommunity, EditSite } from "lemmy-js-client";
|
||||||
|
|
||||||
|
@ -226,7 +227,7 @@ test("Admin actions in remote community are not federated to origin", async () =
|
||||||
if (!betaCommunity) {
|
if (!betaCommunity) {
|
||||||
throw "Missing beta community";
|
throw "Missing beta community";
|
||||||
}
|
}
|
||||||
let bannedUserInfo1 = (await getSite(gamma)).my_user?.local_user_view.person;
|
let bannedUserInfo1 = (await getMyUser(gamma)).local_user_view.person;
|
||||||
if (!bannedUserInfo1) {
|
if (!bannedUserInfo1) {
|
||||||
throw "Missing banned user 1";
|
throw "Missing banned user 1";
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@ import {
|
||||||
registerUser,
|
registerUser,
|
||||||
unfollows,
|
unfollows,
|
||||||
delay,
|
delay,
|
||||||
|
getMyUser,
|
||||||
} from "./shared";
|
} from "./shared";
|
||||||
|
|
||||||
beforeAll(setupLogins);
|
beforeAll(setupLogins);
|
||||||
|
@ -85,8 +86,8 @@ test("Follow federated community", async () => {
|
||||||
);
|
);
|
||||||
|
|
||||||
// Check it from local
|
// Check it from local
|
||||||
let site = await getSite(alpha);
|
let my_user = await getMyUser(alpha);
|
||||||
let remoteCommunityId = site.my_user?.follows.find(
|
let remoteCommunityId = my_user?.follows.find(
|
||||||
c =>
|
c =>
|
||||||
c.community.local == false &&
|
c.community.local == false &&
|
||||||
c.community.id === betaCommunityInitial.community.id,
|
c.community.id === betaCommunityInitial.community.id,
|
||||||
|
@ -102,9 +103,9 @@ test("Follow federated community", async () => {
|
||||||
expect(unfollow.community_view.subscribed).toBe("NotSubscribed");
|
expect(unfollow.community_view.subscribed).toBe("NotSubscribed");
|
||||||
|
|
||||||
// Make sure you are unsubbed locally
|
// Make sure you are unsubbed locally
|
||||||
let siteUnfollowCheck = await getSite(alpha);
|
let siteUnfollowCheck = await getMyUser(alpha);
|
||||||
expect(
|
expect(
|
||||||
siteUnfollowCheck.my_user?.follows.find(
|
siteUnfollowCheck.follows.find(
|
||||||
c => c.community.id === betaCommunityInitial.community.id,
|
c => c.community.id === betaCommunityInitial.community.id,
|
||||||
),
|
),
|
||||||
).toBe(undefined);
|
).toBe(undefined);
|
||||||
|
|
|
@ -32,6 +32,7 @@ import {
|
||||||
createPostWithThumbnail,
|
createPostWithThumbnail,
|
||||||
sampleImage,
|
sampleImage,
|
||||||
sampleSite,
|
sampleSite,
|
||||||
|
getMyUser,
|
||||||
} from "./shared";
|
} from "./shared";
|
||||||
|
|
||||||
beforeAll(setupLogins);
|
beforeAll(setupLogins);
|
||||||
|
@ -129,9 +130,9 @@ test("Purge user, uploaded image removed", async () => {
|
||||||
expect(content.length).toBeGreaterThan(0);
|
expect(content.length).toBeGreaterThan(0);
|
||||||
|
|
||||||
// purge user
|
// purge user
|
||||||
let site = await getSite(user);
|
let my_user = await getMyUser(user);
|
||||||
const purgeForm: PurgePerson = {
|
const purgeForm: PurgePerson = {
|
||||||
person_id: site.my_user!.local_user_view.person.id,
|
person_id: my_user.local_user_view.person.id,
|
||||||
};
|
};
|
||||||
const delete_ = await alphaImage.purgePerson(purgeForm);
|
const delete_ = await alphaImage.purgePerson(purgeForm);
|
||||||
expect(delete_.success).toBe(true);
|
expect(delete_.success).toBe(true);
|
||||||
|
|
|
@ -38,6 +38,7 @@ import {
|
||||||
alphaUrl,
|
alphaUrl,
|
||||||
loginUser,
|
loginUser,
|
||||||
createCommunity,
|
createCommunity,
|
||||||
|
getMyUser,
|
||||||
} from "./shared";
|
} from "./shared";
|
||||||
import { PostView } from "lemmy-js-client/dist/types/PostView";
|
import { PostView } from "lemmy-js-client/dist/types/PostView";
|
||||||
import { EditSite, ResolveObject } from "lemmy-js-client";
|
import { EditSite, ResolveObject } from "lemmy-js-client";
|
||||||
|
@ -452,7 +453,7 @@ test("Enforce site ban federation for local user", async () => {
|
||||||
|
|
||||||
// create a test user
|
// create a test user
|
||||||
let alphaUserHttp = await registerUser(alpha, alphaUrl);
|
let alphaUserHttp = await registerUser(alpha, alphaUrl);
|
||||||
let alphaUserPerson = (await getSite(alphaUserHttp)).my_user?.local_user_view
|
let alphaUserPerson = (await getMyUser(alphaUserHttp)).local_user_view
|
||||||
.person;
|
.person;
|
||||||
let alphaUserActorId = alphaUserPerson?.actor_id;
|
let alphaUserActorId = alphaUserPerson?.actor_id;
|
||||||
if (!alphaUserActorId) {
|
if (!alphaUserActorId) {
|
||||||
|
@ -533,7 +534,7 @@ test("Enforce site ban federation for federated user", async () => {
|
||||||
|
|
||||||
// create a test user
|
// create a test user
|
||||||
let alphaUserHttp = await registerUser(alpha, alphaUrl);
|
let alphaUserHttp = await registerUser(alpha, alphaUrl);
|
||||||
let alphaUserPerson = (await getSite(alphaUserHttp)).my_user?.local_user_view
|
let alphaUserPerson = (await getMyUser(alphaUserHttp)).local_user_view
|
||||||
.person;
|
.person;
|
||||||
let alphaUserActorId = alphaUserPerson?.actor_id;
|
let alphaUserActorId = alphaUserPerson?.actor_id;
|
||||||
if (!alphaUserActorId) {
|
if (!alphaUserActorId) {
|
||||||
|
@ -564,7 +565,7 @@ test("Enforce site ban federation for federated user", async () => {
|
||||||
expect(banAlphaOnBeta.banned).toBe(true);
|
expect(banAlphaOnBeta.banned).toBe(true);
|
||||||
|
|
||||||
// The beta site ban should NOT be federated to alpha
|
// The beta site ban should NOT be federated to alpha
|
||||||
let alphaPerson2 = (await getSite(alphaUserHttp)).my_user!.local_user_view
|
let alphaPerson2 = (await getMyUser(alphaUserHttp)).local_user_view
|
||||||
.person;
|
.person;
|
||||||
expect(alphaPerson2.banned).toBe(false);
|
expect(alphaPerson2.banned).toBe(false);
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@ import {
|
||||||
LemmyHttp,
|
LemmyHttp,
|
||||||
ListCommunityPendingFollows,
|
ListCommunityPendingFollows,
|
||||||
ListCommunityPendingFollowsResponse,
|
ListCommunityPendingFollowsResponse,
|
||||||
|
MyUserInfo,
|
||||||
PersonId,
|
PersonId,
|
||||||
PostView,
|
PostView,
|
||||||
PrivateMessageReportResponse,
|
PrivateMessageReportResponse,
|
||||||
|
@ -757,6 +758,10 @@ export async function getSite(api: LemmyHttp): Promise<GetSiteResponse> {
|
||||||
return api.getSite();
|
return api.getSite();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getMyUser(api: LemmyHttp): Promise<MyUserInfo> {
|
||||||
|
return api.getMyUser();
|
||||||
|
}
|
||||||
|
|
||||||
export async function listPrivateMessages(
|
export async function listPrivateMessages(
|
||||||
api: LemmyHttp,
|
api: LemmyHttp,
|
||||||
): Promise<PrivateMessagesResponse> {
|
): Promise<PrivateMessagesResponse> {
|
||||||
|
@ -768,17 +773,16 @@ export async function listPrivateMessages(
|
||||||
|
|
||||||
export async function unfollowRemotes(
|
export async function unfollowRemotes(
|
||||||
api: LemmyHttp,
|
api: LemmyHttp,
|
||||||
): Promise<GetSiteResponse> {
|
): Promise<MyUserInfo> {
|
||||||
// Unfollow all remote communities
|
// Unfollow all remote communities
|
||||||
let site = await getSite(api);
|
let my_user = await getMyUser(api);
|
||||||
let remoteFollowed =
|
let remoteFollowed =
|
||||||
site.my_user?.follows.filter(c => c.community.local == false) ?? [];
|
my_user.follows.filter(c => c.community.local == false) ?? [];
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
remoteFollowed.map(cu => followCommunity(api, false, cu.community.id)),
|
remoteFollowed.map(cu => followCommunity(api, false, cu.community.id)),
|
||||||
);
|
);
|
||||||
|
|
||||||
let siteRes = await getSite(api);
|
return await getMyUser(api);
|
||||||
return siteRes;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function followBeta(api: LemmyHttp): Promise<CommunityResponse> {
|
export async function followBeta(api: LemmyHttp): Promise<CommunityResponse> {
|
||||||
|
|
|
@ -22,6 +22,7 @@ import {
|
||||||
alphaImage,
|
alphaImage,
|
||||||
unfollows,
|
unfollows,
|
||||||
saveUserSettingsBio,
|
saveUserSettingsBio,
|
||||||
|
getMyUser,
|
||||||
} from "./shared";
|
} from "./shared";
|
||||||
import { LemmyHttp, SaveUserSettings, UploadImage } from "lemmy-js-client";
|
import { LemmyHttp, SaveUserSettings, UploadImage } from "lemmy-js-client";
|
||||||
import { GetPosts } from "lemmy-js-client/dist/types/GetPosts";
|
import { GetPosts } from "lemmy-js-client/dist/types/GetPosts";
|
||||||
|
@ -44,12 +45,9 @@ function assertUserFederation(userOne?: PersonView, userTwo?: PersonView) {
|
||||||
test("Create user", async () => {
|
test("Create user", async () => {
|
||||||
let user = await registerUser(alpha, alphaUrl);
|
let user = await registerUser(alpha, alphaUrl);
|
||||||
|
|
||||||
let site = await getSite(user);
|
let my_user = await getMyUser(user);
|
||||||
expect(site.my_user).toBeDefined();
|
expect(my_user).toBeDefined();
|
||||||
if (!site.my_user) {
|
apShortname = `${my_user.local_user_view.person.name}@lemmy-alpha:8541`;
|
||||||
throw "Missing site user";
|
|
||||||
}
|
|
||||||
apShortname = `${site.my_user.local_user_view.person.name}@lemmy-alpha:8541`;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Set some user settings, check that they are federated", async () => {
|
test("Set some user settings, check that they are federated", async () => {
|
||||||
|
@ -64,8 +62,8 @@ test("Set some user settings, check that they are federated", async () => {
|
||||||
};
|
};
|
||||||
await saveUserSettings(beta, form);
|
await saveUserSettings(beta, form);
|
||||||
|
|
||||||
let site = await getSite(beta);
|
let my_user = await getMyUser(beta);
|
||||||
expect(site.my_user?.local_user_view.local_user.theme).toBe("test");
|
expect(my_user.local_user_view.local_user.theme).toBe("test");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Delete user", async () => {
|
test("Delete user", async () => {
|
||||||
|
@ -121,8 +119,9 @@ test("Requests with invalid auth should be treated as unauthenticated", async ()
|
||||||
headers: { Authorization: "Bearer foobar" },
|
headers: { Authorization: "Bearer foobar" },
|
||||||
fetchFunction,
|
fetchFunction,
|
||||||
});
|
});
|
||||||
|
let my_user = await getMyUser(invalid_auth);
|
||||||
|
expect(my_user).toBeUndefined();
|
||||||
let site = await getSite(invalid_auth);
|
let site = await getSite(invalid_auth);
|
||||||
expect(site.my_user).toBeUndefined();
|
|
||||||
expect(site.site_view).toBeDefined();
|
expect(site.site_view).toBeDefined();
|
||||||
|
|
||||||
let form: GetPosts = {};
|
let form: GetPosts = {};
|
||||||
|
@ -137,12 +136,9 @@ test("Create user with Arabic name", async () => {
|
||||||
"تجريب" + Math.random().toString().slice(2, 10), // less than actor_name_max_length
|
"تجريب" + Math.random().toString().slice(2, 10), // less than actor_name_max_length
|
||||||
);
|
);
|
||||||
|
|
||||||
let site = await getSite(user);
|
let my_user = await getMyUser(user);
|
||||||
expect(site.my_user).toBeDefined();
|
expect(my_user).toBeDefined();
|
||||||
if (!site.my_user) {
|
apShortname = `${my_user.local_user_view.person.name}@lemmy-alpha:8541`;
|
||||||
throw "Missing site user";
|
|
||||||
}
|
|
||||||
apShortname = `${site.my_user.local_user_view.person.name}@lemmy-alpha:8541`;
|
|
||||||
|
|
||||||
let alphaPerson = (await resolvePerson(alpha, apShortname)).person;
|
let alphaPerson = (await resolvePerson(alpha, apShortname)).person;
|
||||||
expect(alphaPerson).toBeDefined();
|
expect(alphaPerson).toBeDefined();
|
||||||
|
@ -155,13 +151,14 @@ test("Create user with accept-language", async () => {
|
||||||
});
|
});
|
||||||
let user = await registerUser(lemmy_http, alphaUrl);
|
let user = await registerUser(lemmy_http, alphaUrl);
|
||||||
|
|
||||||
let site = await getSite(user);
|
let my_user = await getMyUser(user);
|
||||||
expect(site.my_user).toBeDefined();
|
expect(my_user).toBeDefined();
|
||||||
expect(site.my_user?.local_user_view.local_user.interface_language).toBe(
|
expect(my_user?.local_user_view.local_user.interface_language).toBe(
|
||||||
"fr",
|
"fr",
|
||||||
);
|
);
|
||||||
|
let site = await getSite(user);
|
||||||
let langs = site.all_languages
|
let langs = site.all_languages
|
||||||
.filter(a => site.my_user?.discussion_languages.includes(a.id))
|
.filter(a => my_user.discussion_languages.includes(a.id))
|
||||||
.map(l => l.code);
|
.map(l => l.code);
|
||||||
// should have languages from accept header, as well as "undetermined"
|
// should have languages from accept header, as well as "undetermined"
|
||||||
// which is automatically enabled by backend
|
// which is automatically enabled by backend
|
||||||
|
@ -207,8 +204,8 @@ test("Set a new avatar, old avatar is deleted", async () => {
|
||||||
// Now try to save a user settings, with the icon missing,
|
// Now try to save a user settings, with the icon missing,
|
||||||
// and make sure it doesn't clear the data, or delete the image
|
// and make sure it doesn't clear the data, or delete the image
|
||||||
await saveUserSettingsBio(alpha);
|
await saveUserSettingsBio(alpha);
|
||||||
let site = await getSite(alpha);
|
let my_user = await getMyUser(alpha);
|
||||||
expect(site.my_user?.local_user_view.person.avatar).toBe(upload2.url);
|
expect(my_user.local_user_view.person.avatar).toBe(upload2.url);
|
||||||
|
|
||||||
// make sure only the new avatar is kept
|
// make sure only the new avatar is kept
|
||||||
const listMediaRes4 = await alphaImage.listMedia();
|
const listMediaRes4 = await alphaImage.listMedia();
|
||||||
|
|
|
@ -448,7 +448,7 @@ pub struct GetSiteResponse {
|
||||||
pub site_view: SiteView,
|
pub site_view: SiteView,
|
||||||
pub admins: Vec<PersonView>,
|
pub admins: Vec<PersonView>,
|
||||||
pub version: String,
|
pub version: String,
|
||||||
#[cfg_attr(feature = "full", ts(optional))]
|
#[cfg_attr(feature = "full", ts(skip))]
|
||||||
pub my_user: Option<MyUserInfo>,
|
pub my_user: Option<MyUserInfo>,
|
||||||
pub all_languages: Vec<Language>,
|
pub all_languages: Vec<Language>,
|
||||||
pub discussion_languages: Vec<LanguageId>,
|
pub discussion_languages: Vec<LanguageId>,
|
||||||
|
|
Loading…
Reference in a new issue