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-plugin-prettier": "^5.1.3",
|
||||
"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",
|
||||
"ts-jest": "^29.1.0",
|
||||
"typescript": "^5.5.4",
|
||||
|
|
|
@ -30,8 +30,8 @@ importers:
|
|||
specifier: ^29.5.0
|
||||
version: 29.7.0(@types/node@22.9.0)
|
||||
lemmy-js-client:
|
||||
specifier: 0.20.0-api-v4.0
|
||||
version: 0.20.0-api-v4.0
|
||||
specifier: 0.20.0-api-v4.5
|
||||
version: 0.20.0-api-v4.5
|
||||
prettier:
|
||||
specifier: ^3.2.5
|
||||
version: 3.3.3
|
||||
|
@ -1167,8 +1167,8 @@ packages:
|
|||
resolution: {integrity: sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==}
|
||||
engines: {node: '>=6'}
|
||||
|
||||
lemmy-js-client@0.20.0-api-v4.0:
|
||||
resolution: {integrity: sha512-oS02mNzLYWcDIk3FJj1YvBmgpZJQWr34uuxharPd5jQyU8/Yub4XNHrQnjPX5wrXEC6am5ebR8iQmRuQsPQDmw==}
|
||||
lemmy-js-client@0.20.0-api-v4.5:
|
||||
resolution: {integrity: sha512-8Zdjb+oIYMUa5/hvS2zeGoIPLdjM+BODUCvP3/jAA/ipqEiSerJ9BdfIB61cnDE9gXnmjYvEtxnfqRZLlwdLfQ==}
|
||||
|
||||
leven@3.1.0:
|
||||
resolution: {integrity: sha512-qsda+H8jTaUaN/x5vzW2rzc+8Rw4TAQ/4KjB46IwK5VH+IlVeeeje/EoZRpiXvIqjFgK84QffqPztGI3VBLG1A==}
|
||||
|
@ -3077,7 +3077,7 @@ snapshots:
|
|||
|
||||
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: {}
|
||||
|
||||
|
|
|
@ -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 () => {
|
||||
// Unfollow all remote communities
|
||||
let site = await unfollowRemotes(alpha);
|
||||
let my_user = await unfollowRemotes(alpha);
|
||||
expect(
|
||||
site.my_user?.follows.filter(c => c.community.local == false).length,
|
||||
my_user.follows.filter(c => c.community.local == false).length,
|
||||
).toBe(0);
|
||||
|
||||
// B creates a post, and two comments, should be invisible to A
|
||||
|
|
|
@ -34,6 +34,7 @@ import {
|
|||
longDelay,
|
||||
editCommunity,
|
||||
unfollows,
|
||||
getMyUser,
|
||||
} from "./shared";
|
||||
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) {
|
||||
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) {
|
||||
throw "Missing banned user 1";
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ import {
|
|||
registerUser,
|
||||
unfollows,
|
||||
delay,
|
||||
getMyUser,
|
||||
} from "./shared";
|
||||
|
||||
beforeAll(setupLogins);
|
||||
|
@ -85,8 +86,8 @@ test("Follow federated community", async () => {
|
|||
);
|
||||
|
||||
// Check it from local
|
||||
let site = await getSite(alpha);
|
||||
let remoteCommunityId = site.my_user?.follows.find(
|
||||
let my_user = await getMyUser(alpha);
|
||||
let remoteCommunityId = my_user?.follows.find(
|
||||
c =>
|
||||
c.community.local == false &&
|
||||
c.community.id === betaCommunityInitial.community.id,
|
||||
|
@ -102,9 +103,9 @@ test("Follow federated community", async () => {
|
|||
expect(unfollow.community_view.subscribed).toBe("NotSubscribed");
|
||||
|
||||
// Make sure you are unsubbed locally
|
||||
let siteUnfollowCheck = await getSite(alpha);
|
||||
let siteUnfollowCheck = await getMyUser(alpha);
|
||||
expect(
|
||||
siteUnfollowCheck.my_user?.follows.find(
|
||||
siteUnfollowCheck.follows.find(
|
||||
c => c.community.id === betaCommunityInitial.community.id,
|
||||
),
|
||||
).toBe(undefined);
|
||||
|
|
|
@ -32,6 +32,7 @@ import {
|
|||
createPostWithThumbnail,
|
||||
sampleImage,
|
||||
sampleSite,
|
||||
getMyUser,
|
||||
} from "./shared";
|
||||
|
||||
beforeAll(setupLogins);
|
||||
|
@ -129,9 +130,9 @@ test("Purge user, uploaded image removed", async () => {
|
|||
expect(content.length).toBeGreaterThan(0);
|
||||
|
||||
// purge user
|
||||
let site = await getSite(user);
|
||||
let my_user = await getMyUser(user);
|
||||
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);
|
||||
expect(delete_.success).toBe(true);
|
||||
|
|
|
@ -38,6 +38,7 @@ import {
|
|||
alphaUrl,
|
||||
loginUser,
|
||||
createCommunity,
|
||||
getMyUser,
|
||||
} from "./shared";
|
||||
import { PostView } from "lemmy-js-client/dist/types/PostView";
|
||||
import { EditSite, ResolveObject } from "lemmy-js-client";
|
||||
|
@ -452,7 +453,7 @@ test("Enforce site ban federation for local user", async () => {
|
|||
|
||||
// create a test user
|
||||
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;
|
||||
let alphaUserActorId = alphaUserPerson?.actor_id;
|
||||
if (!alphaUserActorId) {
|
||||
|
@ -533,7 +534,7 @@ test("Enforce site ban federation for federated user", async () => {
|
|||
|
||||
// create a test user
|
||||
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;
|
||||
let alphaUserActorId = alphaUserPerson?.actor_id;
|
||||
if (!alphaUserActorId) {
|
||||
|
@ -564,7 +565,7 @@ test("Enforce site ban federation for federated user", async () => {
|
|||
expect(banAlphaOnBeta.banned).toBe(true);
|
||||
|
||||
// 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;
|
||||
expect(alphaPerson2.banned).toBe(false);
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ import {
|
|||
LemmyHttp,
|
||||
ListCommunityPendingFollows,
|
||||
ListCommunityPendingFollowsResponse,
|
||||
MyUserInfo,
|
||||
PersonId,
|
||||
PostView,
|
||||
PrivateMessageReportResponse,
|
||||
|
@ -757,6 +758,10 @@ export async function getSite(api: LemmyHttp): Promise<GetSiteResponse> {
|
|||
return api.getSite();
|
||||
}
|
||||
|
||||
export async function getMyUser(api: LemmyHttp): Promise<MyUserInfo> {
|
||||
return api.getMyUser();
|
||||
}
|
||||
|
||||
export async function listPrivateMessages(
|
||||
api: LemmyHttp,
|
||||
): Promise<PrivateMessagesResponse> {
|
||||
|
@ -768,17 +773,16 @@ export async function listPrivateMessages(
|
|||
|
||||
export async function unfollowRemotes(
|
||||
api: LemmyHttp,
|
||||
): Promise<GetSiteResponse> {
|
||||
): Promise<MyUserInfo> {
|
||||
// Unfollow all remote communities
|
||||
let site = await getSite(api);
|
||||
let my_user = await getMyUser(api);
|
||||
let remoteFollowed =
|
||||
site.my_user?.follows.filter(c => c.community.local == false) ?? [];
|
||||
my_user.follows.filter(c => c.community.local == false) ?? [];
|
||||
await Promise.all(
|
||||
remoteFollowed.map(cu => followCommunity(api, false, cu.community.id)),
|
||||
);
|
||||
|
||||
let siteRes = await getSite(api);
|
||||
return siteRes;
|
||||
return await getMyUser(api);
|
||||
}
|
||||
|
||||
export async function followBeta(api: LemmyHttp): Promise<CommunityResponse> {
|
||||
|
|
|
@ -22,6 +22,7 @@ import {
|
|||
alphaImage,
|
||||
unfollows,
|
||||
saveUserSettingsBio,
|
||||
getMyUser,
|
||||
} from "./shared";
|
||||
import { LemmyHttp, SaveUserSettings, UploadImage } from "lemmy-js-client";
|
||||
import { GetPosts } from "lemmy-js-client/dist/types/GetPosts";
|
||||
|
@ -44,12 +45,9 @@ function assertUserFederation(userOne?: PersonView, userTwo?: PersonView) {
|
|||
test("Create user", async () => {
|
||||
let user = await registerUser(alpha, alphaUrl);
|
||||
|
||||
let site = await getSite(user);
|
||||
expect(site.my_user).toBeDefined();
|
||||
if (!site.my_user) {
|
||||
throw "Missing site user";
|
||||
}
|
||||
apShortname = `${site.my_user.local_user_view.person.name}@lemmy-alpha:8541`;
|
||||
let my_user = await getMyUser(user);
|
||||
expect(my_user).toBeDefined();
|
||||
apShortname = `${my_user.local_user_view.person.name}@lemmy-alpha:8541`;
|
||||
});
|
||||
|
||||
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);
|
||||
|
||||
let site = await getSite(beta);
|
||||
expect(site.my_user?.local_user_view.local_user.theme).toBe("test");
|
||||
let my_user = await getMyUser(beta);
|
||||
expect(my_user.local_user_view.local_user.theme).toBe("test");
|
||||
});
|
||||
|
||||
test("Delete user", async () => {
|
||||
|
@ -121,8 +119,9 @@ test("Requests with invalid auth should be treated as unauthenticated", async ()
|
|||
headers: { Authorization: "Bearer foobar" },
|
||||
fetchFunction,
|
||||
});
|
||||
let my_user = await getMyUser(invalid_auth);
|
||||
expect(my_user).toBeUndefined();
|
||||
let site = await getSite(invalid_auth);
|
||||
expect(site.my_user).toBeUndefined();
|
||||
expect(site.site_view).toBeDefined();
|
||||
|
||||
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
|
||||
);
|
||||
|
||||
let site = await getSite(user);
|
||||
expect(site.my_user).toBeDefined();
|
||||
if (!site.my_user) {
|
||||
throw "Missing site user";
|
||||
}
|
||||
apShortname = `${site.my_user.local_user_view.person.name}@lemmy-alpha:8541`;
|
||||
let my_user = await getMyUser(user);
|
||||
expect(my_user).toBeDefined();
|
||||
apShortname = `${my_user.local_user_view.person.name}@lemmy-alpha:8541`;
|
||||
|
||||
let alphaPerson = (await resolvePerson(alpha, apShortname)).person;
|
||||
expect(alphaPerson).toBeDefined();
|
||||
|
@ -155,13 +151,14 @@ test("Create user with accept-language", async () => {
|
|||
});
|
||||
let user = await registerUser(lemmy_http, alphaUrl);
|
||||
|
||||
let site = await getSite(user);
|
||||
expect(site.my_user).toBeDefined();
|
||||
expect(site.my_user?.local_user_view.local_user.interface_language).toBe(
|
||||
let my_user = await getMyUser(user);
|
||||
expect(my_user).toBeDefined();
|
||||
expect(my_user?.local_user_view.local_user.interface_language).toBe(
|
||||
"fr",
|
||||
);
|
||||
let site = await getSite(user);
|
||||
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);
|
||||
// should have languages from accept header, as well as "undetermined"
|
||||
// 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,
|
||||
// and make sure it doesn't clear the data, or delete the image
|
||||
await saveUserSettingsBio(alpha);
|
||||
let site = await getSite(alpha);
|
||||
expect(site.my_user?.local_user_view.person.avatar).toBe(upload2.url);
|
||||
let my_user = await getMyUser(alpha);
|
||||
expect(my_user.local_user_view.person.avatar).toBe(upload2.url);
|
||||
|
||||
// make sure only the new avatar is kept
|
||||
const listMediaRes4 = await alphaImage.listMedia();
|
||||
|
|
|
@ -448,7 +448,7 @@ pub struct GetSiteResponse {
|
|||
pub site_view: SiteView,
|
||||
pub admins: Vec<PersonView>,
|
||||
pub version: String,
|
||||
#[cfg_attr(feature = "full", ts(optional))]
|
||||
#[cfg_attr(feature = "full", ts(skip))]
|
||||
pub my_user: Option<MyUserInfo>,
|
||||
pub all_languages: Vec<Language>,
|
||||
pub discussion_languages: Vec<LanguageId>,
|
||||
|
|
Loading…
Reference in a new issue