feat: disable community creation on sites with it disabled
This commit is contained in:
1 parent
8484ff5ed7
commit
8192239dc3
3 files changed
+18
-12
No files matched your search
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "photon-lemmy",
|
"name": "photon-lemmy",
|
||||||
"version": "0.8.0",
|
"version": "0.8.1",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite dev",
|
"dev": "vite dev",
|
||||||
|
|||||||
+15
-10
@@ -1,10 +1,10 @@
|
|||||||
import { amModOfAny } from '$lib/components/lemmy/moderation/moderation.js'
|
import { amModOfAny } from '$lib/components/lemmy/moderation/moderation.js'
|
||||||
import { toast } from '$lib/components/ui/toasts/toasts.js'
|
import { toast } from '$lib/components/ui/toasts/toasts.js'
|
||||||
import { DEFAULT_INSTANCE_URL, instance } from '$lib/instance.js'
|
import { DEFAULT_INSTANCE_URL, instance } from '$lib/instance.js'
|
||||||
import { getClient } from '$lib/lemmy.js'
|
import { getClient, site } from '$lib/lemmy.js'
|
||||||
import { getInbox, getInboxItemPublished } from '$lib/lemmy/inbox.js'
|
import { getInbox, getInboxItemPublished } from '$lib/lemmy/inbox.js'
|
||||||
import { userSettings } from '$lib/settings.js'
|
import { userSettings } from '$lib/settings.js'
|
||||||
import type { MyUserInfo } from 'lemmy-js-client'
|
import type { GetSiteResponse, MyUserInfo } from 'lemmy-js-client'
|
||||||
import { get, writable } from 'svelte/store'
|
import { get, writable } from 'svelte/store'
|
||||||
|
|
||||||
const getDefaultProfile = (): Profile => ({
|
const getDefaultProfile = (): Profile => ({
|
||||||
@@ -81,11 +81,12 @@ profile.subscribe(async (p) => {
|
|||||||
instance.set(p.instance)
|
instance.set(p.instance)
|
||||||
// fetch the user because p.user is undefined
|
// fetch the user because p.user is undefined
|
||||||
const user = await userFromJwt(p.jwt, p.instance)
|
const user = await userFromJwt(p.jwt, p.instance)
|
||||||
|
site.set(user?.site)
|
||||||
|
|
||||||
profile.update(() => ({
|
profile.update(() => ({
|
||||||
...p,
|
...p,
|
||||||
user: user,
|
user: user!.user,
|
||||||
username: user?.local_user_view.person.name,
|
username: user?.user.local_user_view.person.name,
|
||||||
}))
|
}))
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -119,7 +120,7 @@ export async function setUser(jwt: string, inst: string, username: string) {
|
|||||||
|
|
||||||
profile.set({
|
profile.set({
|
||||||
...newProfile,
|
...newProfile,
|
||||||
user: user,
|
user: user!.user,
|
||||||
})
|
})
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -134,14 +135,18 @@ export async function setUser(jwt: string, inst: string, username: string) {
|
|||||||
async function userFromJwt(
|
async function userFromJwt(
|
||||||
jwt: string,
|
jwt: string,
|
||||||
instance: string
|
instance: string
|
||||||
): Promise<PersonData | undefined> {
|
): Promise<{ user: PersonData; site: GetSiteResponse } | undefined> {
|
||||||
const myUser = (await getClient(instance).getSite({ auth: jwt })).my_user
|
const site = await getClient(instance).getSite({ auth: jwt })
|
||||||
|
const myUser = site.my_user
|
||||||
if (!myUser) return undefined
|
if (!myUser) return undefined
|
||||||
|
|
||||||
return {
|
return {
|
||||||
unreads: 0,
|
user: {
|
||||||
reports: 0,
|
unreads: 0,
|
||||||
...myUser,
|
reports: 0,
|
||||||
|
...myUser,
|
||||||
|
},
|
||||||
|
site: site,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -157,7 +157,8 @@
|
|||||||
<MenuButton
|
<MenuButton
|
||||||
link
|
link
|
||||||
href="/create/community"
|
href="/create/community"
|
||||||
disabled={$profile?.jwt == undefined}
|
disabled={$profile?.jwt == undefined ||
|
||||||
|
$site?.site_view.local_site.community_creation_admin_only}
|
||||||
>
|
>
|
||||||
<Icon src={Newspaper} mini width={16} />
|
<Icon src={Newspaper} mini width={16} />
|
||||||
Community
|
Community
|
||||||
|
|||||||
Reference in new issue
Block a user