Merge pull request #609 from Xyphyn/auth-impr
impr: improve authentication code
This commit is contained in:
81 files changed
+461
-479
No files matched your search
+194
-212
@@ -20,11 +20,6 @@ import { site } from './lemmy.svelte'
|
||||
import { errorMessage } from './lemmy/error'
|
||||
import { publishedToDate } from './components/util/date'
|
||||
|
||||
const getDefaultProfile = (): Profile => ({
|
||||
id: -1,
|
||||
instance: profileData.defaultInstance ?? DEFAULT_INSTANCE_URL,
|
||||
})
|
||||
|
||||
function getFromStorage<T>(key: string): T | undefined {
|
||||
if (typeof localStorage == 'undefined') return undefined
|
||||
const lc = localStorage.getItem(key)
|
||||
@@ -39,7 +34,7 @@ function setFromStorage(key: string, item: any, stringify: boolean = true) {
|
||||
return localStorage.setItem(key, stringify ? JSON.stringify(item) : item)
|
||||
}
|
||||
|
||||
export interface Profile {
|
||||
export interface ProfileInfo {
|
||||
id: number
|
||||
instance: string
|
||||
jwt?: string
|
||||
@@ -54,9 +49,9 @@ export interface Profile {
|
||||
* What gets stored in localstorage.
|
||||
*/
|
||||
interface ProfileData {
|
||||
profiles: Profile[]
|
||||
profiles: ProfileInfo[]
|
||||
// should be named currentId
|
||||
profile: number
|
||||
defaultInstance?: string
|
||||
}
|
||||
|
||||
interface Notifications {
|
||||
@@ -68,8 +63,6 @@ interface Notifications {
|
||||
const getCookie = (key: string): string | undefined => {
|
||||
if (!browser) return undefined
|
||||
|
||||
// sorry i was dying when i wrote this line
|
||||
// ask chatgpt or something to explain this for you
|
||||
return document?.cookie
|
||||
?.split(';')
|
||||
.map(c => c.trim())
|
||||
@@ -77,42 +70,110 @@ const getCookie = (key: string): string | undefined => {
|
||||
?.split('=')?.[1]
|
||||
}
|
||||
|
||||
export const profileData = $state<ProfileData>(
|
||||
getFromStorage<ProfileData>('profileData') ?? {
|
||||
profiles: [
|
||||
{
|
||||
id: 1,
|
||||
instance: DEFAULT_INSTANCE_URL,
|
||||
username: 'Guest',
|
||||
color: '#505050',
|
||||
},
|
||||
],
|
||||
profile: 1,
|
||||
},
|
||||
)
|
||||
|
||||
class CurrentProfile {
|
||||
#data = $derived(
|
||||
profileData.profiles.find(i => i.id == profileData.profile) ??
|
||||
getDefaultProfile(),
|
||||
class Profile {
|
||||
meta = $state<ProfileData>(
|
||||
getFromStorage<ProfileData>('profileData') ?? {
|
||||
profiles: [
|
||||
{
|
||||
id: 1,
|
||||
instance: DEFAULT_INSTANCE_URL,
|
||||
username: 'Guest',
|
||||
color: '#505050',
|
||||
},
|
||||
],
|
||||
profile: 1,
|
||||
},
|
||||
)
|
||||
#current = $derived(
|
||||
this.meta.profiles.find(i => i.id == this.meta.profile) ??
|
||||
this.getDefaultProfile(),
|
||||
)
|
||||
|
||||
get data() {
|
||||
return this.#data
|
||||
getDefaultProfile(): ProfileInfo {
|
||||
return {
|
||||
id: -1,
|
||||
instance: DEFAULT_INSTANCE_URL,
|
||||
}
|
||||
}
|
||||
set data(value) {
|
||||
|
||||
constructor() {
|
||||
// cookie migration code
|
||||
if (
|
||||
env.PUBLIC_MIGRATE_COOKIE &&
|
||||
this.meta.profiles.length == 0 &&
|
||||
env.PUBLIC_INSTANCE_URL
|
||||
) {
|
||||
const jwt = getCookie('jwt')
|
||||
if (jwt) {
|
||||
;(async () => {
|
||||
const result = await this.add(jwt, env.PUBLIC_INSTANCE_URL ?? '')
|
||||
|
||||
if (result)
|
||||
toast({
|
||||
content:
|
||||
'Your instance migrated to Photon, and your account was transferred.',
|
||||
type: 'success',
|
||||
})
|
||||
})()
|
||||
}
|
||||
}
|
||||
|
||||
setInterval(
|
||||
() => {
|
||||
if (profile.current.jwt)
|
||||
this.checkInbox().then(res => notifications.update(() => res))
|
||||
},
|
||||
4 * 60 * 1000,
|
||||
)
|
||||
|
||||
// hacky way to check donation status
|
||||
setTimeout(() => {
|
||||
if (
|
||||
profile.current.user?.local_user_view.local_user
|
||||
.last_donation_notification
|
||||
) {
|
||||
const donationDate = publishedToDate(
|
||||
profile.current.user?.local_user_view.local_user
|
||||
.last_donation_notification,
|
||||
)
|
||||
if (Date.now() - donationDate.getTime() > 365 * 24 * 60 * 60 * 1000) {
|
||||
toast({
|
||||
content: t.get('toast.lemmyDonate'),
|
||||
duration: 3600 * 1000,
|
||||
long: true,
|
||||
})
|
||||
|
||||
// lemmy js client donation dialog is broken
|
||||
fetch(
|
||||
`${instanceToURL(profile.current.instance)}/api/v3/user/donation_dialog_shown`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: {
|
||||
authorization: `Bearer ${profile.current.jwt}`,
|
||||
},
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
}, 3 * 1000)
|
||||
}
|
||||
|
||||
get current() {
|
||||
return this.#current
|
||||
}
|
||||
set current(value) {
|
||||
if (!value) return
|
||||
const index = profileData.profiles.findIndex(i => i.id == value?.id)
|
||||
profileData.profiles[index] = value
|
||||
const index = this.meta.profiles.findIndex(i => i.id == value?.id)
|
||||
this.meta.profiles[index] = value
|
||||
}
|
||||
|
||||
async fetchUserData() {
|
||||
const startId = this.#data.id
|
||||
if (this.#data.jwt) {
|
||||
const startId = this.#current.id
|
||||
if (this.#current.jwt) {
|
||||
site.data = undefined
|
||||
notifications.set({ applications: 0, inbox: 0, reports: 0 })
|
||||
|
||||
const res = await userFromJwt(this.#data.jwt, this.#data.instance)
|
||||
const res = await userFromJwt(this.#current.jwt, this.#current.instance)
|
||||
if (!res?.user)
|
||||
toast({
|
||||
content:
|
||||
@@ -121,21 +182,21 @@ class CurrentProfile {
|
||||
})
|
||||
|
||||
// TODO update authentication handling to not be this dynamic
|
||||
if (this.#data.id != startId) {
|
||||
if (this.#current.id != startId) {
|
||||
console.error('profile was switched too fast, ID mismatch')
|
||||
return
|
||||
}
|
||||
|
||||
site.data = res?.site
|
||||
this.#data.user = res?.user
|
||||
if (profile.data.user) {
|
||||
this.#data.avatar = res?.user?.local_user_view.person.avatar
|
||||
this.#data.username = res?.user?.local_user_view.person.name
|
||||
this.#current.user = res?.user
|
||||
if (profile.current.user) {
|
||||
this.#current.avatar = res?.user?.local_user_view.person.avatar
|
||||
this.#current.username = res?.user?.local_user_view.person.name
|
||||
}
|
||||
} else {
|
||||
if (browser) {
|
||||
site.data = undefined
|
||||
client({ instanceURL: this.#data.instance })
|
||||
client({ instanceURL: this.#current.instance })
|
||||
.getSite()
|
||||
.then(res => (site.data = res))
|
||||
}
|
||||
@@ -143,9 +204,98 @@ class CurrentProfile {
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
async checkInbox() {
|
||||
const { user, jwt } = profile.current
|
||||
if (!user || !jwt) throw new Error('checkInbox() called with invalid user')
|
||||
|
||||
const notifs = await getNotificationCount(
|
||||
jwt,
|
||||
amModOfAny(user) ?? false,
|
||||
user ? isAdmin(user) : false,
|
||||
)
|
||||
|
||||
return {
|
||||
inbox: notifs.unreads,
|
||||
applications: notifs.applications,
|
||||
reports: notifs.reports,
|
||||
}
|
||||
}
|
||||
|
||||
async add(jwt: string, instance: string) {
|
||||
const user = await userFromJwt(jwt, instance)
|
||||
.then(u => u)
|
||||
.catch(err => {
|
||||
toast({ content: errorMessage(err as string), type: 'error' })
|
||||
})
|
||||
if (!user?.user) {
|
||||
toast({
|
||||
content: "Your instance's API did not return your user data.",
|
||||
type: 'error',
|
||||
})
|
||||
}
|
||||
|
||||
const id = Math.max(...this.meta.profiles.map(p => p.id)) + 1
|
||||
this.meta.profile = id
|
||||
this.meta.profiles.push({
|
||||
id: id,
|
||||
instance: instance,
|
||||
jwt: jwt,
|
||||
username: user?.user?.local_user_view.person.name,
|
||||
avatar: user?.user?.local_user_view.person.avatar,
|
||||
})
|
||||
|
||||
return user
|
||||
}
|
||||
|
||||
remove(id: number) {
|
||||
this.meta.profiles.splice(
|
||||
this.meta.profiles.findIndex(p => p.id == id),
|
||||
1,
|
||||
)
|
||||
if (id == this.meta.profile) this.meta.profile = -1
|
||||
}
|
||||
|
||||
move(id: number, up: boolean) {
|
||||
try {
|
||||
const index = this.meta.profiles.findIndex(i => i.id == id)
|
||||
this.meta.profiles = moveItem(
|
||||
this.meta.profiles,
|
||||
index,
|
||||
index + (up ? -1 : 1),
|
||||
)
|
||||
} catch {
|
||||
/* empty */
|
||||
}
|
||||
}
|
||||
|
||||
mainEffect = $effect.root(() => {
|
||||
// Sync with localStorage
|
||||
$effect(() => {
|
||||
const serialized = {
|
||||
...this.meta,
|
||||
profiles: this.meta.profiles.map(p => serializeUser(p)),
|
||||
}
|
||||
|
||||
setFromStorage('profileData', serialized)
|
||||
|
||||
// no more profiles left
|
||||
if (serialized.profiles.length == 0) {
|
||||
this.meta.profiles = [this.getDefaultProfile()]
|
||||
this.meta.profile = 1
|
||||
}
|
||||
})
|
||||
|
||||
$effect(() => {
|
||||
if (this.current.jwt)
|
||||
this.fetchUserData().then(() => {
|
||||
this.checkInbox().then(res => notifications.update(() => res))
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
export const profile = new CurrentProfile()
|
||||
export const profile = new Profile()
|
||||
|
||||
export const notifications = writable<Notifications>({
|
||||
applications: 0,
|
||||
@@ -153,90 +303,6 @@ export const notifications = writable<Notifications>({
|
||||
reports: 0,
|
||||
})
|
||||
|
||||
$effect.root(() => {
|
||||
$effect(() => {
|
||||
const serialized = {
|
||||
...profileData,
|
||||
profiles: profileData.profiles.map(p => serializeUser(p)),
|
||||
}
|
||||
|
||||
setFromStorage('profileData', serialized)
|
||||
if (serialized.profiles.length == 0) {
|
||||
profileData.profiles = [
|
||||
{
|
||||
id: 1,
|
||||
instance: DEFAULT_INSTANCE_URL,
|
||||
username: t.get('account.guest') || 'Guest',
|
||||
},
|
||||
]
|
||||
profileData.profile = 1
|
||||
}
|
||||
})
|
||||
|
||||
$effect(() => {
|
||||
if (profile.data.id || profileData)
|
||||
profile.fetchUserData().then(() => {
|
||||
checkInbox()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
// cookie migration code
|
||||
if (
|
||||
env.PUBLIC_MIGRATE_COOKIE &&
|
||||
profileData.profiles.length == 0 &&
|
||||
env.PUBLIC_INSTANCE_URL
|
||||
) {
|
||||
const jwt = getCookie('jwt')
|
||||
if (jwt) {
|
||||
;(async () => {
|
||||
const user = await userFromJwt(jwt, env.PUBLIC_INSTANCE_URL ?? '')
|
||||
if (!user) return
|
||||
|
||||
const result = await setUser(jwt, env.PUBLIC_INSTANCE_URL ?? '')
|
||||
|
||||
if (result)
|
||||
toast({
|
||||
content:
|
||||
'Your instance migrated to Photon, and you were logged in using a leftover cookie.',
|
||||
type: 'success',
|
||||
})
|
||||
})()
|
||||
}
|
||||
}
|
||||
|
||||
export async function setUser(jwt: string, inst: string) {
|
||||
try {
|
||||
new URL(instanceToURL(inst))
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
|
||||
const user = await userFromJwt(jwt, inst)
|
||||
.then(u => u)
|
||||
.catch(err => {
|
||||
toast({ content: errorMessage(err as string), type: 'error' })
|
||||
})
|
||||
if (!user?.user) {
|
||||
toast({
|
||||
content: "Your instance's API did not return your user data.",
|
||||
type: 'error',
|
||||
})
|
||||
}
|
||||
|
||||
const id = Math.max(...profileData.profiles.map(p => p.id)) + 1
|
||||
profileData.profile = id
|
||||
profileData.profiles.push({
|
||||
id: id,
|
||||
instance: inst,
|
||||
jwt: jwt,
|
||||
username: user?.user?.local_user_view.person.name,
|
||||
avatar: user?.user?.local_user_view.person.avatar,
|
||||
})
|
||||
|
||||
return user
|
||||
}
|
||||
|
||||
async function userFromJwt(
|
||||
jwt: string,
|
||||
instance: string,
|
||||
@@ -281,44 +347,13 @@ async function userFromJwt(
|
||||
}
|
||||
}
|
||||
|
||||
export function resetProfile() {
|
||||
profileData.profile = -1
|
||||
}
|
||||
|
||||
export function deleteProfile(id: number) {
|
||||
profileData.profiles.splice(
|
||||
profileData.profiles.findIndex(p => p.id == id),
|
||||
1,
|
||||
)
|
||||
if (id == profileData.profile) resetProfile()
|
||||
}
|
||||
|
||||
function serializeUser(user: Profile): Profile {
|
||||
function serializeUser(user: ProfileInfo): ProfileInfo {
|
||||
return {
|
||||
...user,
|
||||
user: undefined,
|
||||
}
|
||||
}
|
||||
|
||||
export async function setUserID(id: number) {
|
||||
if (!profileData.profiles.find(p => p.id == id)) return -1
|
||||
profileData.profile = id
|
||||
return profile
|
||||
}
|
||||
|
||||
export function moveProfile(id: number, up: boolean) {
|
||||
try {
|
||||
const index = profileData.profiles.findIndex(i => i.id == id)
|
||||
profileData.profiles = moveItem(
|
||||
profileData.profiles,
|
||||
index,
|
||||
index + (up ? -1 : 1),
|
||||
)
|
||||
} catch {
|
||||
/* empty */
|
||||
}
|
||||
}
|
||||
|
||||
async function getNotificationCount(jwt: string, mod: boolean, admin: boolean) {
|
||||
const unreadsPromise = getClient()
|
||||
.getUnreadCount()
|
||||
@@ -356,56 +391,3 @@ async function getNotificationCount(jwt: string, mod: boolean, admin: boolean) {
|
||||
applications: applications,
|
||||
}
|
||||
}
|
||||
|
||||
async function checkInbox() {
|
||||
const { user, jwt } = profile.data
|
||||
if (!jwt || !user) return
|
||||
|
||||
const notifs = await getNotificationCount(
|
||||
jwt,
|
||||
amModOfAny(user) ?? false,
|
||||
user ? isAdmin(user) : false,
|
||||
)
|
||||
|
||||
notifications.set({
|
||||
inbox: notifs.unreads,
|
||||
applications: notifs.applications,
|
||||
reports: notifs.reports,
|
||||
})
|
||||
}
|
||||
|
||||
async function init() {
|
||||
setInterval(checkInbox, 4 * 60 * 1000)
|
||||
|
||||
// hacky way to check donation status
|
||||
setTimeout(() => {
|
||||
if (
|
||||
profile.data.user?.local_user_view.local_user.last_donation_notification
|
||||
) {
|
||||
const donationDate = publishedToDate(
|
||||
profile.data.user?.local_user_view.local_user
|
||||
.last_donation_notification,
|
||||
)
|
||||
if (Date.now() - donationDate.getTime() > 365 * 24 * 60 * 60 * 1000) {
|
||||
toast({
|
||||
content: t.get('toast.lemmyDonate'),
|
||||
duration: 3600 * 1000,
|
||||
long: true,
|
||||
})
|
||||
|
||||
// lemmy js client donation dialog is broken
|
||||
fetch(
|
||||
`${instanceToURL(profile.data.instance)}/api/v3/user/donation_dialog_shown`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: {
|
||||
authorization: `Bearer ${profile.data.jwt}`,
|
||||
},
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
}, 3 * 1000)
|
||||
}
|
||||
|
||||
init()
|
||||
@@ -14,7 +14,7 @@
|
||||
let loading = $state(false)
|
||||
|
||||
async function deleteImage(image: LocalImage) {
|
||||
if (!profile.data?.jwt) return
|
||||
if (!profile.current?.jwt) return
|
||||
|
||||
try {
|
||||
loading = true
|
||||
|
||||
@@ -50,7 +50,7 @@
|
||||
let editingLoad = $state(false)
|
||||
|
||||
async function save(type: 'reply' | 'edit') {
|
||||
if (!profile.data?.jwt || newComment.length <= 0) return
|
||||
if (!profile.current?.jwt || newComment.length <= 0) return
|
||||
|
||||
editingLoad = true
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@
|
||||
<Icon src={ChatBubbleOvalLeft} size="14" micro />
|
||||
<span class="text-xs">{$t('comment.reply')}</span>
|
||||
</Button>
|
||||
{#if profile.data?.user && (amMod(profile.data?.user, comment.community) || isAdmin(profile.data.user))}
|
||||
{#if profile.current?.user && (amMod(profile.current?.user, comment.community) || isAdmin(profile.current.user))}
|
||||
<CommentModerationMenu bind:item={comment} />
|
||||
{/if}
|
||||
<Menu placement="bottom">
|
||||
@@ -90,8 +90,8 @@
|
||||
<Icon src={Square2Stack} mini size="16" />
|
||||
<div>{$t('post.actions.more.share')}</div>
|
||||
</MenuButton>
|
||||
{#if profile.data?.jwt}
|
||||
{#if comment.creator.id == profile.data.user?.local_user_view.person.id}
|
||||
{#if profile.current?.jwt}
|
||||
{#if comment.creator.id == profile.current.user?.local_user_view.person.id}
|
||||
<MenuButton onclick={() => onedit?.(comment)}>
|
||||
<Icon src={PencilSquare} mini size="16" />
|
||||
<span>{$t('post.actions.more.edit')}</span>
|
||||
@@ -99,7 +99,7 @@
|
||||
{/if}
|
||||
<MenuButton
|
||||
onclick={async () => {
|
||||
if (profile.data?.jwt)
|
||||
if (profile.current?.jwt)
|
||||
comment.saved = await save(comment, !comment.saved)
|
||||
}}
|
||||
>
|
||||
@@ -108,11 +108,11 @@
|
||||
{comment.saved ? $t('post.actions.unsave') : $t('post.actions.save')}
|
||||
</span>
|
||||
</MenuButton>
|
||||
{#if profile.data?.user && profile.data.jwt && profile.data.user.local_user_view.person.id == comment.creator.id}
|
||||
{#if profile.current?.user && profile.current.jwt && profile.current.user.local_user_view.person.id == comment.creator.id}
|
||||
<MenuButton
|
||||
color="danger-subtle"
|
||||
onclick={async () => {
|
||||
if (profile.data?.jwt)
|
||||
if (profile.current?.jwt)
|
||||
comment.comment.deleted = await deleteItem(
|
||||
comment,
|
||||
!comment.comment.deleted,
|
||||
@@ -127,7 +127,7 @@
|
||||
</span>
|
||||
</MenuButton>
|
||||
{/if}
|
||||
{#if profile.data.jwt && profile.data.user?.local_user_view.person.id != comment.creator.id}
|
||||
{#if profile.current.jwt && profile.current.user?.local_user_view.person.id != comment.creator.id}
|
||||
<MenuButton onclick={() => report(comment)} color="danger-subtle">
|
||||
<Icon src={Flag} mini size="16" />
|
||||
<span>{$t('moderation.report')}</span>
|
||||
|
||||
@@ -51,7 +51,7 @@
|
||||
let language: number | undefined = $state()
|
||||
|
||||
async function submit() {
|
||||
if (!profile.data?.user || !profile.data?.jwt || value == '') return
|
||||
if (!profile.current?.user || !profile.current?.jwt || value == '') return
|
||||
|
||||
loading = true
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
}: Props = $props()
|
||||
|
||||
const castVote = async (newVote: number) => {
|
||||
if (!profile.data?.jwt) {
|
||||
if (!profile.current?.jwt) {
|
||||
toast({ content: $t('toast.loginVoteGate'), type: 'warning' })
|
||||
return
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@
|
||||
})
|
||||
|
||||
async function subscribe() {
|
||||
if (!profile.data?.jwt) return
|
||||
if (!profile.current?.jwt) return
|
||||
loading.subscribing = true
|
||||
const subscribed =
|
||||
community_view.subscribed == 'Subscribed' ||
|
||||
@@ -227,7 +227,7 @@
|
||||
{/if}
|
||||
</div>
|
||||
<div class="flex flex-row items-center gap-1 sticky bottom-0 w-full">
|
||||
{#if profile.data?.jwt}
|
||||
{#if profile.current?.jwt}
|
||||
<Button
|
||||
disabled={loading.subscribing}
|
||||
loading={loading.subscribing}
|
||||
@@ -252,7 +252,7 @@
|
||||
: $t('cards.community.subscribe')}
|
||||
</Button>
|
||||
{/if}
|
||||
{#if profile.data?.user && amMod(profile.data.user, community_view.community)}
|
||||
{#if profile.current?.user && amMod(profile.current.user, community_view.community)}
|
||||
<Button
|
||||
href="/c/{fullCommunityName(
|
||||
community_view.community.name,
|
||||
@@ -278,7 +278,7 @@
|
||||
<Icon src={Newspaper} size="16" mini />
|
||||
{$t('cards.community.modlog')}
|
||||
</MenuButton>
|
||||
{#if profile.data?.jwt}
|
||||
{#if profile.current?.jwt}
|
||||
<MenuButton
|
||||
color="danger-subtle"
|
||||
size="lg"
|
||||
@@ -292,7 +292,7 @@
|
||||
? $t('cards.community.unblock')
|
||||
: $t('cards.community.block')}
|
||||
</MenuButton>
|
||||
{#if profile.data?.user}
|
||||
{#if profile.current?.user}
|
||||
<MenuButton
|
||||
color="danger-subtle"
|
||||
size="lg"
|
||||
@@ -304,7 +304,7 @@
|
||||
{$t('cards.community.blockInstance')}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
{#if profile.data?.user && isAdmin(profile.data.user)}
|
||||
{#if profile.current?.user && isAdmin(profile.current.user)}
|
||||
<MenuButton
|
||||
color="danger-subtle"
|
||||
onclick={() =>
|
||||
|
||||
@@ -64,7 +64,7 @@
|
||||
let formData = $state(passedFormData)
|
||||
|
||||
async function submit() {
|
||||
if (!profile.data?.jwt) return
|
||||
if (!profile.current?.jwt) return
|
||||
if ((!edit && formData.name == '') || formData.displayName == '') return
|
||||
|
||||
formData.submitting = true
|
||||
@@ -99,23 +99,23 @@
|
||||
type: 'success',
|
||||
})
|
||||
|
||||
if (profile.data.user) {
|
||||
const c = profile.data.user.moderates
|
||||
if (profile.current.user) {
|
||||
const c = profile.current.user.moderates
|
||||
.map(m => m.community.id)
|
||||
.indexOf(res.community_view.community.id)
|
||||
if (c != -1) {
|
||||
profile.data.user.moderates[c] = {
|
||||
profile.current.user.moderates[c] = {
|
||||
community: res.community_view.community,
|
||||
moderator: profile.data.user.local_user_view.person,
|
||||
moderator: profile.current.user.local_user_view.person,
|
||||
}
|
||||
} else {
|
||||
profile.data.user = {
|
||||
...profile.data.user,
|
||||
profile.current.user = {
|
||||
...profile.current.user,
|
||||
moderates: [
|
||||
...profile.data.user.moderates,
|
||||
...profile.current.user.moderates,
|
||||
{
|
||||
community: res.community_view.community,
|
||||
moderator: profile.data.user.local_user_view.person,
|
||||
moderator: profile.current.user.local_user_view.person,
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@
|
||||
</Expandable>
|
||||
{/if}
|
||||
<div class="flex items-center gap-2 h-max w-max">
|
||||
{#if profile.data?.jwt}
|
||||
{#if profile.current?.jwt}
|
||||
<Subscribe
|
||||
community={{
|
||||
community: community,
|
||||
@@ -153,7 +153,7 @@
|
||||
</Subscribe>
|
||||
{/if}
|
||||
|
||||
{#if profile.data?.user && profile.data.user.moderates
|
||||
{#if profile.current?.user && profile.current.user.moderates
|
||||
.map(c => c.community.id)
|
||||
.includes(community.id)}
|
||||
<Button
|
||||
@@ -181,7 +181,7 @@
|
||||
<Icon src={Newspaper} size="16" mini />
|
||||
{$t('cards.community.modlog')}
|
||||
</MenuButton>
|
||||
{#if profile.data.user && amMod(profile.data.user, community)}
|
||||
{#if profile.current.user && amMod(profile.current.user, community)}
|
||||
<MenuButton
|
||||
color="success-subtle"
|
||||
href="/moderation?community={community.id}"
|
||||
@@ -190,7 +190,7 @@
|
||||
{$t('routes.moderation.feed')}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
{#if profile.data?.jwt}
|
||||
{#if profile.current?.jwt}
|
||||
<MenuButton
|
||||
color="danger-subtle"
|
||||
size="lg"
|
||||
@@ -203,7 +203,7 @@
|
||||
? $t('cards.community.unblock')
|
||||
: $t('cards.community.block')}
|
||||
</MenuButton>
|
||||
{#if profile.data?.user}
|
||||
{#if profile.current?.user}
|
||||
<MenuButton
|
||||
color="danger-subtle"
|
||||
size="lg"
|
||||
@@ -215,7 +215,7 @@
|
||||
{$t('cards.community.blockInstance')}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
{#if profile.data?.user && isAdmin(profile.data.user)}
|
||||
{#if profile.current?.user && isAdmin(profile.current.user)}
|
||||
<MenuButton
|
||||
color="danger-subtle"
|
||||
onclick={() =>
|
||||
|
||||
@@ -155,7 +155,7 @@
|
||||
<Subscribe {community}>
|
||||
{#snippet children({ subscribe, subscribing })}
|
||||
<Button
|
||||
disabled={subscribing || !profile.data?.jwt}
|
||||
disabled={subscribing || !profile.current?.jwt}
|
||||
loading={subscribing}
|
||||
onclick={async () => {
|
||||
const res = await subscribe()
|
||||
|
||||
@@ -51,14 +51,14 @@
|
||||
<Option value="Local" icon={MapPin}>{$t('filter.location.local')}</Option>
|
||||
<Option
|
||||
value="Subscribed"
|
||||
disabled={profile.data?.jwt == undefined}
|
||||
disabled={profile.current?.jwt == undefined}
|
||||
icon={Newspaper}
|
||||
>
|
||||
{$t('filter.location.subscribed')}
|
||||
</Option>
|
||||
<Option
|
||||
value="ModeratorView"
|
||||
disabled={!profile.data?.jwt || !amModOfAny(profile.data?.user)}
|
||||
disabled={!profile.current?.jwt || !amModOfAny(profile.current?.user)}
|
||||
icon={ShieldCheck}
|
||||
>
|
||||
{$t('filter.location.moderator')}
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
avatar
|
||||
avatarSize={20}
|
||||
/>
|
||||
{#if profile.data?.user?.local_user_view.person.id != message.recipient.id}
|
||||
{#if profile.current?.user?.local_user_view.person.id != message.recipient.id}
|
||||
to
|
||||
<UserLink
|
||||
showInstance={false}
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
)
|
||||
|
||||
async function upload() {
|
||||
if (!profile.data?.jwt || image == null) return
|
||||
if (!profile.current?.jwt || image == null) return
|
||||
|
||||
progress = 0
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
const uploaded = (
|
||||
await Promise.all(
|
||||
Array.from(image).map(i =>
|
||||
uploadImage(i, profile.data.instance, profile.data.jwt!)
|
||||
uploadImage(i, profile.current.instance, profile.current.jwt!)
|
||||
.then(uploaded => {
|
||||
progress += 1 / (image?.length ?? 0)
|
||||
return uploaded
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
let loading = $state(false)
|
||||
|
||||
async function sendMessage() {
|
||||
if (!profile.data?.jwt || message == '') return
|
||||
if (!profile.current?.jwt || message == '') return
|
||||
|
||||
loading = true
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@
|
||||
})
|
||||
|
||||
async function submit() {
|
||||
if (!item || !profile.data?.user || !profile.data?.jwt) return
|
||||
if (!item || !profile.current?.user || !profile.current?.jwt) return
|
||||
|
||||
loading = true
|
||||
|
||||
|
||||
@@ -34,9 +34,9 @@
|
||||
<ShieldIcon filled width={14} />
|
||||
</Button>
|
||||
{/snippet}
|
||||
{#if (profile.data?.user && amMod(profile.data.user, item.community)) || (profile.data?.user && isAdmin(profile.data.user))}
|
||||
{#if (profile.current?.user && amMod(profile.current.user, item.community)) || (profile.current?.user && isAdmin(profile.current.user))}
|
||||
<MenuDivider>
|
||||
{#if !item.community.local && !amMod(profile.data.user, item.community)}
|
||||
{#if !item.community.local && !amMod(profile.current.user, item.community)}
|
||||
{$t('moderation.labelInstanceOnly')}
|
||||
{:else}
|
||||
{$t('moderation.label')}
|
||||
@@ -52,7 +52,7 @@
|
||||
: $t('moderation.remove')}
|
||||
{/if}
|
||||
</MenuButton>
|
||||
{#if profile.data?.user && profile.data.user?.local_user_view.person.id != item.creator.id}
|
||||
{#if profile.current?.user && profile.current.user?.local_user_view.person.id != item.creator.id}
|
||||
<!--Comment made by someone else-->
|
||||
<MenuButton
|
||||
color="danger-subtle"
|
||||
@@ -71,12 +71,12 @@
|
||||
<MenuButton
|
||||
color="success-subtle"
|
||||
onclick={async () => {
|
||||
if (!profile.data.jwt) return
|
||||
if (!profile.current.jwt) return
|
||||
item.comment = (
|
||||
await feature(
|
||||
!item.comment.distinguished,
|
||||
item.comment,
|
||||
profile.data.jwt,
|
||||
profile.current.jwt,
|
||||
)
|
||||
).comment_view.comment
|
||||
}}
|
||||
@@ -104,7 +104,7 @@
|
||||
</MenuButton>
|
||||
{/if}
|
||||
|
||||
{#if profile.data?.user && isAdmin(profile.data.user)}
|
||||
{#if profile.current?.user && isAdmin(profile.current.user)}
|
||||
<MenuDivider>{$t('admin.label')}</MenuDivider>
|
||||
<MenuButton color="danger-subtle" onclick={() => remove(item, true)}>
|
||||
{#snippet prefix()}
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
let acting = $derived(locking || pinning)
|
||||
|
||||
async function lock(lock: boolean) {
|
||||
if (!profile.data?.jwt || !isPostView(item)) return
|
||||
if (!profile.current?.jwt || !isPostView(item)) return
|
||||
locking = true
|
||||
|
||||
try {
|
||||
@@ -53,7 +53,7 @@
|
||||
}
|
||||
|
||||
async function pin(pinned: boolean, toInstance: boolean = false) {
|
||||
if (!profile.data?.jwt || !isPostView(item)) return
|
||||
if (!profile.current?.jwt || !isPostView(item)) return
|
||||
|
||||
pinning = true
|
||||
|
||||
@@ -88,9 +88,9 @@
|
||||
<ShieldIcon filled width={16} />
|
||||
</Button>
|
||||
{/snippet}
|
||||
{#if (profile.data?.user && amMod(profile.data.user, item.community)) || (profile.data?.user && isAdmin(profile.data.user))}
|
||||
{#if (profile.current?.user && amMod(profile.current.user, item.community)) || (profile.current?.user && isAdmin(profile.current.user))}
|
||||
<MenuDivider>
|
||||
{#if !item.community.local && !amMod(profile.data.user, item.community)}
|
||||
{#if !item.community.local && !amMod(profile.current.user, item.community)}
|
||||
{$t('moderation.labelInstanceOnly')}
|
||||
{:else}
|
||||
{$t('moderation.label')}
|
||||
@@ -124,7 +124,7 @@
|
||||
? $t('moderation.unfeature')
|
||||
: $t('moderation.feature')}
|
||||
</span>
|
||||
{#if isAdmin(profile.data.user)}
|
||||
{#if isAdmin(profile.current.user)}
|
||||
<span class="text-xs opacity-80">{$t('form.post.community')}</span>
|
||||
{/if}
|
||||
</div>
|
||||
@@ -139,7 +139,7 @@
|
||||
{item.post.removed ? $t('moderation.restore') : $t('moderation.remove')}
|
||||
{/if}
|
||||
</MenuButton>
|
||||
{#if profile.data?.user && profile.data.user.local_user_view.person.id != item.creator.id}
|
||||
{#if profile.current?.user && profile.current.user.local_user_view.person.id != item.creator.id}
|
||||
<MenuButton
|
||||
color="danger-subtle"
|
||||
onclick={() =>
|
||||
@@ -164,7 +164,7 @@
|
||||
{$t('moderation.votes')}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
{#if profile.data?.user && isAdmin(profile.data.user)}
|
||||
{#if profile.current?.user && isAdmin(profile.current.user)}
|
||||
<MenuDivider>{$t('admin.label')}</MenuDivider>
|
||||
<MenuButton
|
||||
color="success-subtle"
|
||||
|
||||
@@ -76,7 +76,7 @@
|
||||
|
||||
async function remove() {
|
||||
if (!item) return
|
||||
if (!profile.data?.jwt) throw new Error('Unauthenticated')
|
||||
if (!profile.current?.jwt) throw new Error('Unauthenticated')
|
||||
|
||||
loading = true
|
||||
|
||||
@@ -216,7 +216,7 @@
|
||||
bind:value={reason}
|
||||
/>
|
||||
|
||||
{#if !removed && profile.data?.user && (amMod(profile.data.user, item.community) || (isAdmin(profile.data.user) && item.community.local))}
|
||||
{#if !removed && profile.current?.user && (amMod(profile.current.user, item.community) || (isAdmin(profile.current.user) && item.community.local))}
|
||||
<Switch bind:checked={commentReason}>
|
||||
{$t('moderation.removeSubmission.withReason')}
|
||||
</Switch>
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
let reason = $state('')
|
||||
|
||||
async function report() {
|
||||
if (!item || !profile.data?.jwt || reason == '') return
|
||||
if (!item || !profile.current?.jwt || reason == '') return
|
||||
loading = true
|
||||
|
||||
try {
|
||||
|
||||
@@ -112,7 +112,7 @@
|
||||
user={post.creator}
|
||||
published={publishedToDate(post.post.published)}
|
||||
{badges}
|
||||
subscribed={profile.data?.user?.follows
|
||||
subscribed={profile.current?.user?.follows
|
||||
.map(c => c.community.id)
|
||||
.includes(post.community.id)
|
||||
? 'Subscribed'
|
||||
|
||||
@@ -117,8 +117,8 @@
|
||||
bind:score={post.counts.score}
|
||||
bind:upvotes={post.counts.upvotes}
|
||||
bind:downvotes={post.counts.downvotes}
|
||||
showCounts={profile.data?.user?.local_user_view?.local_user?.show_scores ??
|
||||
true}
|
||||
showCounts={profile.current?.user?.local_user_view?.local_user
|
||||
?.show_scores ?? true}
|
||||
/>
|
||||
|
||||
<Button
|
||||
@@ -160,7 +160,7 @@
|
||||
{/snippet}
|
||||
</Button>
|
||||
{/if}
|
||||
{#if profile.data?.user && (amMod(profile.data.user, post.community) || isAdmin(profile.data.user))}
|
||||
{#if profile.current?.user && (amMod(profile.current.user, post.community) || isAdmin(profile.current.user))}
|
||||
<ModerationMenu
|
||||
size="custom"
|
||||
color="ghost"
|
||||
@@ -171,10 +171,10 @@
|
||||
/>
|
||||
{/if}
|
||||
|
||||
{#if profile.data?.jwt}
|
||||
{#if profile.current?.jwt}
|
||||
<Button
|
||||
onclick={async () => {
|
||||
if (!profile.data?.jwt) return
|
||||
if (!profile.current?.jwt) return
|
||||
saving = true
|
||||
post.saved = await save(post, !post.saved)
|
||||
saving = false
|
||||
@@ -228,7 +228,7 @@
|
||||
<MenuDivider>
|
||||
{$t('post.actions.more.actions')}
|
||||
</MenuDivider>
|
||||
{#if profile.data?.user && profile.data?.jwt && profile.data.user.local_user_view.person.id == post.creator.id}
|
||||
{#if profile.current?.user && profile.current?.jwt && profile.current.user.local_user_view.person.id == post.creator.id}
|
||||
<MenuButton onclick={() => (editing = true)}>
|
||||
{#snippet prefix()}
|
||||
<Icon src={PencilSquare} size="16" micro />
|
||||
@@ -236,10 +236,10 @@
|
||||
{$t('post.actions.more.edit')}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
{#if profile.data?.jwt}
|
||||
{#if profile.current?.jwt}
|
||||
<MenuButton
|
||||
onclick={async () => {
|
||||
if (profile.data?.jwt)
|
||||
if (profile.current?.jwt)
|
||||
post.read = await markAsRead(post.post, !post.read)
|
||||
}}
|
||||
>
|
||||
@@ -297,7 +297,7 @@
|
||||
</div>
|
||||
{/if}
|
||||
</MenuButton>
|
||||
{#if profile.data?.jwt}
|
||||
{#if profile.current?.jwt}
|
||||
<MenuButton
|
||||
onclick={() => {
|
||||
setSessionStorage('postDraft', {
|
||||
@@ -326,10 +326,10 @@
|
||||
{/snippet}
|
||||
{$t('post.actions.more.crosspost')}
|
||||
</MenuButton>
|
||||
{#if profile.data.user && post.creator.id == profile.data.user.local_user_view.person.id}
|
||||
{#if profile.current.user && post.creator.id == profile.current.user.local_user_view.person.id}
|
||||
<MenuButton
|
||||
onclick={async () => {
|
||||
if (profile.data?.jwt)
|
||||
if (profile.current?.jwt)
|
||||
post.post.deleted = await deleteItem(post, !post.post.deleted)
|
||||
}}
|
||||
color="danger-subtle"
|
||||
@@ -342,15 +342,15 @@
|
||||
: $t('post.actions.more.delete')}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
{#if profile.data.user?.local_user_view.person.id != post.creator.id}
|
||||
{#if profile.current.user?.local_user_view.person.id != post.creator.id}
|
||||
{#if feature('hidePosts', site.data?.version)}
|
||||
<MenuButton
|
||||
onclick={async () => {
|
||||
if (!profile.data?.jwt) return
|
||||
if (!profile.current?.jwt) return
|
||||
const hidden = await hidePost(
|
||||
post.post.id,
|
||||
!post.hidden,
|
||||
profile.data?.jwt,
|
||||
profile.current?.jwt,
|
||||
)
|
||||
post.hidden = hidden
|
||||
if (hidden) onhide?.(hidden)
|
||||
|
||||
@@ -51,7 +51,7 @@
|
||||
let loading = $state(false)
|
||||
|
||||
const castVote = async (newVote: number) => {
|
||||
if (!profile.data?.jwt) {
|
||||
if (!profile.current?.jwt) {
|
||||
toast({ content: $t('toast.loginVoteGate'), type: 'warning' })
|
||||
return
|
||||
}
|
||||
|
||||
@@ -134,7 +134,7 @@
|
||||
})
|
||||
return
|
||||
}
|
||||
if (!data.title || !profile.data?.jwt) return
|
||||
if (!data.title || !profile.current?.jwt) return
|
||||
if (data.url && data.url != '') {
|
||||
try {
|
||||
new URL(data.url)
|
||||
@@ -275,7 +275,7 @@
|
||||
<ObjectAutocomplete
|
||||
bind:q={communitySearch}
|
||||
items={communities}
|
||||
jwt={profile.data?.jwt}
|
||||
jwt={profile.current?.jwt}
|
||||
listing_type="All"
|
||||
label={$t('form.post.community')}
|
||||
required
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
).users.map(c => c.person)
|
||||
|
||||
if (hideOwnUser) {
|
||||
const myself = profile.data.user?.local_user_view.person.id
|
||||
const myself = profile.current.user?.local_user_view.person.id
|
||||
return users.filter(c => c.id != myself)
|
||||
}
|
||||
return users
|
||||
|
||||
@@ -86,7 +86,7 @@
|
||||
style="border-radius: inherit;"
|
||||
>
|
||||
<div class="ml-auto"></div>
|
||||
{#if profile.data?.user && isAdmin(profile.data.user)}
|
||||
{#if profile.current?.user && isAdmin(profile.current.user)}
|
||||
<NavButton
|
||||
href="/admin"
|
||||
label={$t('nav.admin')}
|
||||
@@ -95,7 +95,7 @@
|
||||
isSelectedFilter={path => path.startsWith('/admin')}
|
||||
/>
|
||||
{/if}
|
||||
{#if amModOfAny(profile.data?.user)}
|
||||
{#if amModOfAny(profile.current?.user)}
|
||||
<NavButton
|
||||
href="/moderation"
|
||||
label={$t('nav.moderation')}
|
||||
@@ -109,10 +109,10 @@
|
||||
icon={GlobeAlt}
|
||||
/>
|
||||
<NavButton href="/search" label={$t('nav.search')} icon={MagnifyingGlass} />
|
||||
{#if profile.data.jwt}
|
||||
{#if profile.current.jwt}
|
||||
{@const linkOnly =
|
||||
!profile.data.user ||
|
||||
!(isAdmin(profile.data.user) || amModOfAny(profile.data.user))}
|
||||
!profile.current.user ||
|
||||
!(isAdmin(profile.current.user) || amModOfAny(profile.current.user))}
|
||||
<Menu manual={linkOnly} placement="top">
|
||||
{#snippet target()}
|
||||
<NavButton
|
||||
@@ -136,7 +136,7 @@
|
||||
{@render notifBadge($notifications.inbox)}
|
||||
{/snippet}
|
||||
</MenuButton>
|
||||
{#if amModOfAny(profile.data.user)}
|
||||
{#if amModOfAny(profile.current.user)}
|
||||
<MenuButton href="/moderation" icon={ShieldCheck}>
|
||||
{$t('routes.moderation.feed')}
|
||||
{#snippet suffix()}
|
||||
@@ -144,7 +144,7 @@
|
||||
{/snippet}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
{#if profile.data.user && isAdmin(profile.data.user)}
|
||||
{#if profile.current.user && isAdmin(profile.current.user)}
|
||||
<MenuButton href="/admin/applications" icon={ServerStack}>
|
||||
{$t('routes.admin.applications.title')}
|
||||
{#snippet suffix()}
|
||||
@@ -156,7 +156,7 @@
|
||||
{/if}
|
||||
<Menu
|
||||
manual={site.data?.site_view.local_site.community_creation_admin_only &&
|
||||
!(profile.data.user && isAdmin(profile.data.user))}
|
||||
!(profile.current.user && isAdmin(profile.current.user))}
|
||||
placement="top"
|
||||
>
|
||||
{#snippet target()}
|
||||
@@ -166,13 +166,13 @@
|
||||
icon={Plus}
|
||||
adaptive={false}
|
||||
href={site.data?.site_view.local_site.community_creation_admin_only &&
|
||||
!(profile.data.user && isAdmin(profile.data.user))
|
||||
!(profile.current.user && isAdmin(profile.current.user))
|
||||
? '/create/post'
|
||||
: undefined}
|
||||
/>
|
||||
{/snippet}
|
||||
<MenuDivider>{$t('nav.create.label')}</MenuDivider>
|
||||
<MenuButton link href="/create/post" disabled={!profile.data?.jwt}>
|
||||
<MenuButton link href="/create/post" disabled={!profile.current?.jwt}>
|
||||
{#snippet prefix()}
|
||||
<Icon src={PencilSquare} size="16" micro />
|
||||
{/snippet}
|
||||
@@ -181,17 +181,17 @@
|
||||
<MenuButton
|
||||
link
|
||||
href="/create/community"
|
||||
disabled={!profile.data?.jwt ||
|
||||
!profile.data?.user ||
|
||||
disabled={!profile.current?.jwt ||
|
||||
!profile.current?.user ||
|
||||
(site.data?.site_view.local_site.community_creation_admin_only &&
|
||||
!isAdmin(profile.data.user))}
|
||||
!isAdmin(profile.current.user))}
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<Icon src={Newspaper} size="16" micro />
|
||||
{/snippet}
|
||||
{$t('nav.create.community')}
|
||||
</MenuButton>
|
||||
{#if !profile.data?.jwt}
|
||||
{#if !profile.current?.jwt}
|
||||
<span class="text-sm mx-4 my-1 py-1">
|
||||
{$t('nav.create.logingate')}
|
||||
</span>
|
||||
|
||||
@@ -72,14 +72,14 @@
|
||||
hover:bg-slate-200 dark:hover:bg-zinc-700 group cursor-pointer {buttonClass}"
|
||||
title={$t('profile.profile')}
|
||||
>
|
||||
{#if profile.data?.user}
|
||||
{#if profile.current?.user}
|
||||
<div
|
||||
class="w-full h-full aspect-square object-cover rounded-full grid place-items-center group-hover:scale-90 transition-transform group-active:scale-[85%]"
|
||||
>
|
||||
<Avatar
|
||||
url={profile.data.user.local_user_view.person.avatar}
|
||||
url={profile.current.user.local_user_view.person.avatar}
|
||||
width={36}
|
||||
alt={profile.data.user.local_user_view.person.name}
|
||||
alt={profile.current.user.local_user_view.person.name}
|
||||
/>
|
||||
</div>
|
||||
{:else}
|
||||
@@ -90,7 +90,7 @@
|
||||
</button>
|
||||
{/snippet}
|
||||
<MenuDivider>{$t('nav.menu.label')}</MenuDivider>
|
||||
{#if profile.data?.jwt}
|
||||
{#if profile.current?.jwt}
|
||||
<MenuButton href="/profile">
|
||||
{#snippet prefix()}
|
||||
<Icon src={UserCircle} micro size="16" />
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
import { browser } from '$app/environment'
|
||||
import { goto } from '$app/navigation'
|
||||
import { page } from '$app/state'
|
||||
import { profile, profileData } from '$lib/auth.svelte'
|
||||
import { profile } from '$lib/auth.svelte'
|
||||
import { t } from '$lib/i18n/translations'
|
||||
import { resumables } from '$lib/lemmy/item'
|
||||
import { theme } from '$lib/ui/colors.svelte'
|
||||
@@ -23,8 +23,8 @@
|
||||
$effect(() => {
|
||||
groups = getGroups(
|
||||
$resumables,
|
||||
profile.data,
|
||||
profileData.profiles,
|
||||
profile.current,
|
||||
profile.meta.profiles,
|
||||
theme.data,
|
||||
page.data.contextual?.actions,
|
||||
)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { goto } from '$app/navigation'
|
||||
import { page } from '$app/state'
|
||||
import { setUserID, type Profile } from '$lib/auth.svelte'
|
||||
import { profile as currentProfile, type ProfileInfo } from '$lib/auth.svelte'
|
||||
import {
|
||||
amModOfAny,
|
||||
isAdmin,
|
||||
@@ -64,8 +64,8 @@ export interface Action {
|
||||
|
||||
export function getGroups(
|
||||
resumables: ResumableItem[],
|
||||
profile: Profile,
|
||||
profiles: Profile[],
|
||||
profile: ProfileInfo,
|
||||
profiles: ProfileInfo[],
|
||||
td: ThemeData,
|
||||
contextual?: Action[],
|
||||
) {
|
||||
@@ -311,7 +311,7 @@ export function getGroups(
|
||||
detail: p.instance,
|
||||
handle: async () => {
|
||||
if (profile.id != p.id) {
|
||||
await setUserID(p.id)
|
||||
currentProfile.meta.profile = p.id
|
||||
}
|
||||
|
||||
await goto(page.url, {
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
animate:flip={{ duration: 500, easing: expoOut }}
|
||||
>
|
||||
<div class="flex-none grid group">
|
||||
{#if profile && !hasFavorite(profile.data, follow.id)}
|
||||
{#if profile && !hasFavorite(profile.current, follow.id)}
|
||||
<Button
|
||||
rounding="pill"
|
||||
size="custom"
|
||||
@@ -36,7 +36,7 @@
|
||||
>
|
||||
<Icon src={Star} size="16" mini />
|
||||
</Button>
|
||||
{:else if isFavorites && profile && hasFavorite(profile.data, follow.id)}
|
||||
{:else if isFavorites && profile && hasFavorite(profile.current, follow.id)}
|
||||
<Button
|
||||
rounding="pill"
|
||||
size="custom"
|
||||
@@ -53,7 +53,9 @@
|
||||
alt={follow.name}
|
||||
title={follow.title}
|
||||
width={28}
|
||||
class={!isFavorites && profile && hasFavorite(profile.data, follow.id)
|
||||
class={!isFavorites &&
|
||||
profile &&
|
||||
hasFavorite(profile.current, follow.id)
|
||||
? ''
|
||||
: 'group-hover:hidden'}
|
||||
/>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<script lang="ts">
|
||||
import { goto } from '$app/navigation'
|
||||
import { page } from '$app/state'
|
||||
import { profile, setUserID, type Profile } from '$lib/auth.svelte.js'
|
||||
import { profile, type ProfileInfo } from '$lib/auth.svelte'
|
||||
import SidebarButton from '$lib/components/ui/sidebar/SidebarButton.svelte'
|
||||
import { LINKED_INSTANCE_URL } from '$lib/instance.svelte'
|
||||
import ProfileAvatar from '$lib/lemmy/ProfileAvatar.svelte'
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
let switching: boolean = $state(false)
|
||||
interface Props {
|
||||
prof: Profile
|
||||
prof: ProfileInfo
|
||||
index: number
|
||||
guest?: boolean
|
||||
}
|
||||
@@ -23,12 +23,12 @@
|
||||
loading={switching}
|
||||
rounding="lg"
|
||||
loaderWidth={22}
|
||||
selected={profile.data?.id == prof.id}
|
||||
selected={profile.current?.id == prof.id}
|
||||
onclick={async () => {
|
||||
switching = true
|
||||
|
||||
if (profile.data?.id != prof.id) {
|
||||
await setUserID(prof.id)
|
||||
if (profile.current?.id != prof.id) {
|
||||
profile.meta.profile = prof.id
|
||||
}
|
||||
|
||||
await goto(page.url, {
|
||||
@@ -37,7 +37,7 @@
|
||||
|
||||
switching = false
|
||||
}}
|
||||
class="w-full font-normal {profile.data?.id == prof.id
|
||||
class="w-full font-normal {profile.current?.id == prof.id
|
||||
? 'bg-slate-100! dark:bg-zinc-900!'
|
||||
: ''}"
|
||||
>
|
||||
@@ -46,11 +46,11 @@
|
||||
profile={prof}
|
||||
{index}
|
||||
{guest}
|
||||
selected={profile.data?.id == prof.id}
|
||||
selected={profile.current?.id == prof.id}
|
||||
/>
|
||||
{/snippet}
|
||||
<span
|
||||
class="inline-flex flex-col gap-0 {profile.data?.id == prof.id
|
||||
class="inline-flex flex-col gap-0 {profile.current?.id == prof.id
|
||||
? 'font-semibold'
|
||||
: ''}"
|
||||
>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { notifications, profile, profileData } from '$lib/auth.svelte.js'
|
||||
import { notifications, profile } from '$lib/auth.svelte.js'
|
||||
import Expandable from '$lib/components/ui/Expandable.svelte'
|
||||
import CommunityList from '$lib/components/ui/sidebar/CommunityList.svelte'
|
||||
import ProfileButton from '$lib/components/ui/sidebar/ProfileButton.svelte'
|
||||
@@ -31,7 +31,7 @@
|
||||
class={['flex flex-col p-4 overflow-auto gap-1 h-fit max-h-screen', clazz]}
|
||||
{style}
|
||||
>
|
||||
{#if profile.data?.jwt}
|
||||
{#if profile.current?.jwt}
|
||||
<SidebarButton icon={UserCircle} href="/profile">
|
||||
{#snippet label()}
|
||||
<span>
|
||||
@@ -88,7 +88,7 @@
|
||||
{/snippet}
|
||||
</SidebarButton>
|
||||
{/if}
|
||||
{#if profileData.profiles.length >= 1}
|
||||
{#if profile.meta.profiles.length >= 1}
|
||||
<hr class="border-slate-200 dark:border-zinc-900 my-1" />
|
||||
|
||||
<Expandable
|
||||
@@ -101,14 +101,14 @@
|
||||
{$t('account.accounts')}
|
||||
{#snippet action()}
|
||||
<span class="dark:text-white text-black">
|
||||
{profileData.profiles.length}
|
||||
{profile.meta.profiles.length}
|
||||
</span>
|
||||
{/snippet}
|
||||
</EndPlaceholder>
|
||||
</span>
|
||||
{/snippet}
|
||||
<div class="w-full flex gap-px flex-col">
|
||||
{#each [...profileData.profiles] as prof, index}
|
||||
{#each [...profile.meta.profiles] as prof, index}
|
||||
<div class="w-full">
|
||||
<ProfileButton {index} {prof} />
|
||||
</div>
|
||||
@@ -120,7 +120,7 @@
|
||||
</Expandable>
|
||||
{/if}
|
||||
<hr class="border-slate-200 dark:border-zinc-900 my-1" />
|
||||
{#if profile.data?.favorites && profile.data?.favorites.length > 0}
|
||||
{#if profile.current?.favorites && profile.current?.favorites.length > 0}
|
||||
<Expandable
|
||||
class="max-w-full min-w-0 w-full"
|
||||
bind:open={settings.expand.favorites}
|
||||
@@ -131,18 +131,18 @@
|
||||
{$t('routes.profile.favorites')}
|
||||
{#snippet action()}
|
||||
<span class="dark:text-white text-black">
|
||||
{profile.data.favorites?.length}
|
||||
{profile.current.favorites?.length}
|
||||
</span>
|
||||
{/snippet}
|
||||
</EndPlaceholder>
|
||||
</span>
|
||||
{/snippet}
|
||||
<CommunityList isFavorites items={profile.data.favorites} />
|
||||
<CommunityList isFavorites items={profile.current.favorites} />
|
||||
</Expandable>
|
||||
<hr class="border-slate-200 dark:border-zinc-900 my-1" />
|
||||
{/if}
|
||||
{#if profile.data?.user}
|
||||
{#if profile.data?.user.moderates.length > 0}
|
||||
{#if profile.current?.user}
|
||||
{#if profile.current?.user.moderates.length > 0}
|
||||
<Expandable
|
||||
class="max-w-full min-w-0 w-full"
|
||||
bind:open={settings.expand.moderates}
|
||||
@@ -153,14 +153,14 @@
|
||||
{$t('routes.profile.moderates')}
|
||||
{#snippet action()}
|
||||
<span class="dark:text-white text-black">
|
||||
{profile.data.user?.moderates.length}
|
||||
{profile.current.user?.moderates.length}
|
||||
</span>
|
||||
{/snippet}
|
||||
</EndPlaceholder>
|
||||
</span>
|
||||
{/snippet}
|
||||
<CommunityList
|
||||
items={profile.data.user.moderates.map(i => i.community)}
|
||||
items={profile.current.user.moderates.map(i => i.community)}
|
||||
/>
|
||||
</Expandable>
|
||||
<hr class="border-slate-200 dark:border-zinc-900 my-1" />
|
||||
@@ -176,13 +176,15 @@
|
||||
{$t('profile.subscribed')}
|
||||
{#snippet action()}
|
||||
<span class="dark:text-white text-black">
|
||||
{profile.data.user?.follows.length}
|
||||
{profile.current.user?.follows.length}
|
||||
</span>
|
||||
{/snippet}
|
||||
</EndPlaceholder>
|
||||
</span>
|
||||
{/snippet}
|
||||
<CommunityList items={profile.data.user.follows.map(i => i.community)} />
|
||||
<CommunityList
|
||||
items={profile.current.user.follows.map(i => i.community)}
|
||||
/>
|
||||
</Expandable>
|
||||
{/if}
|
||||
</nav>
|
||||
@@ -3,7 +3,7 @@ import { env } from '$env/dynamic/public'
|
||||
import { profile } from './auth.svelte'
|
||||
|
||||
class InstanceData {
|
||||
#instance = $derived(profile.data.instance)
|
||||
#instance = $derived(profile.current.instance)
|
||||
|
||||
get data() {
|
||||
return this.#instance ?? DEFAULT_INSTANCE_URL
|
||||
|
||||
@@ -59,9 +59,10 @@ export function client({
|
||||
) => Promise<Response>
|
||||
auth?: string
|
||||
} = {}) {
|
||||
if (!instanceURL) instanceURL = profile.data.instance || DEFAULT_INSTANCE_URL
|
||||
if (!instanceURL)
|
||||
instanceURL = profile.current.instance || DEFAULT_INSTANCE_URL
|
||||
|
||||
const jwt = auth ? auth : profile.data?.jwt
|
||||
const jwt = auth ? auth : profile.current?.jwt
|
||||
|
||||
const headers = jwt ? { authorization: `Bearer ${jwt}` } : {}
|
||||
|
||||
|
||||
@@ -106,12 +106,12 @@ function resumableStore(limit: number = 10) {
|
||||
export const resumables = resumableStore()
|
||||
|
||||
export function addFavorite(item: Community, add: boolean = true) {
|
||||
const favs = profile.data.favorites ?? []
|
||||
const favs = profile.current.favorites ?? []
|
||||
if (favs.map(fav => fav.id).includes(item.id)) if (add) return
|
||||
if (!add) {
|
||||
favs.splice(favs.map(c => c.id).indexOf(item.id), 1)
|
||||
} else {
|
||||
favs.unshift(item)
|
||||
}
|
||||
profile.data.favorites = favs
|
||||
profile.current.favorites = favs
|
||||
}
|
||||
@@ -6,7 +6,7 @@ import type { Community, MyUserInfo } from 'lemmy-js-client'
|
||||
// TODO obliterate this file
|
||||
|
||||
export const blockUser = async (block: boolean, id: number) => {
|
||||
const auth = profile.data?.jwt
|
||||
const auth = profile.current?.jwt
|
||||
|
||||
if (!auth) throw new Error('Unauthorized')
|
||||
|
||||
@@ -23,17 +23,17 @@ export const addSubscription = (
|
||||
community: Community,
|
||||
subscribe: boolean = true,
|
||||
) => {
|
||||
const index = profile.data.user?.follows
|
||||
const index = profile.current.user?.follows
|
||||
.map(f => f.community.id)
|
||||
.indexOf(community.id)
|
||||
|
||||
if (subscribe && index == -1) {
|
||||
profile.data.user?.follows.push({
|
||||
follower: profile.data.user.follows[0]?.follower,
|
||||
profile.current.user?.follows.push({
|
||||
follower: profile.current.user.follows[0]?.follower,
|
||||
community: community,
|
||||
})
|
||||
} else {
|
||||
profile.data.user?.follows.splice(index ?? 0, 1)
|
||||
profile.current.user?.follows.splice(index ?? 0, 1)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +1,5 @@
|
||||
<script lang="ts">
|
||||
import {
|
||||
profile as currentProfile,
|
||||
deleteProfile,
|
||||
moveProfile,
|
||||
type Profile,
|
||||
profile,
|
||||
profileData,
|
||||
setUserID,
|
||||
} from '$lib/auth.svelte.js'
|
||||
import { profile, type ProfileInfo } from '$lib/auth.svelte.js'
|
||||
import Header from '$lib/components/ui/layout/pages/Header.svelte'
|
||||
import DebugObject from '$lib/components/util/debug/DebugObject.svelte'
|
||||
import { t } from '$lib/i18n/translations'
|
||||
@@ -29,23 +21,23 @@
|
||||
} from 'svelte-hero-icons'
|
||||
|
||||
let debugging = $state(false)
|
||||
let debugProfile: Profile | undefined = $state(undefined)
|
||||
let debugProfile: ProfileInfo | undefined = $state(undefined)
|
||||
|
||||
let removing = $state({
|
||||
shown: false,
|
||||
account: undefined as Profile | undefined,
|
||||
account: undefined as ProfileInfo | undefined,
|
||||
})
|
||||
|
||||
let switching = $state(-1)
|
||||
|
||||
let radioSelected = $state(profile.data.id)
|
||||
let radioSelected = $state(profile.current.id)
|
||||
$effect(() => {
|
||||
switching = radioSelected
|
||||
setUserID(radioSelected)
|
||||
profile.meta.profile = radioSelected
|
||||
})
|
||||
|
||||
$effect(() => {
|
||||
if (profile.data.user) switching = -1
|
||||
if (profile.current.user) switching = -1
|
||||
})
|
||||
</script>
|
||||
|
||||
@@ -55,7 +47,9 @@
|
||||
|
||||
{#if debugging}
|
||||
<DebugObject
|
||||
object={debugProfile?.id == profile.data?.id ? profile.data : debugProfile}
|
||||
object={debugProfile?.id == profile.current?.id
|
||||
? profile.current
|
||||
: debugProfile}
|
||||
bind:open={debugging}
|
||||
>
|
||||
{#snippet title()}
|
||||
@@ -92,7 +86,7 @@
|
||||
<Button
|
||||
onclick={() => {
|
||||
removing.shown = false
|
||||
if (removing.account) deleteProfile(removing.account.id)
|
||||
if (removing.account) profile.remove(removing.account.id)
|
||||
}}
|
||||
size="lg"
|
||||
class="flex-1"
|
||||
@@ -139,13 +133,13 @@
|
||||
{/snippet}
|
||||
</Header>
|
||||
<form class="accounts-grid mt-4 sm:mt-6 gap-4">
|
||||
{#each profileData.profiles as profile, index (profile.id)}
|
||||
{#each profile.meta.profiles as p, index (p.id)}
|
||||
<label>
|
||||
<input
|
||||
type="radio"
|
||||
id={profile.id.toString()}
|
||||
id={p.id.toString()}
|
||||
name="profile"
|
||||
value={profile.id}
|
||||
value={p.id}
|
||||
class="hidden peer"
|
||||
bind:group={radioSelected}
|
||||
/>
|
||||
@@ -156,26 +150,26 @@
|
||||
class={[
|
||||
'flex flex-row items-center px-3 py-3 gap-2 transition-all duration-75 cursor-pointer relative',
|
||||
'peer-checked:ring-2',
|
||||
switching == profile.id && 'ring-slate-400 dark:ring-zinc-600',
|
||||
switching == p.id && 'ring-slate-400 dark:ring-zinc-600',
|
||||
]}
|
||||
>
|
||||
<ProfileAvatar
|
||||
{profile}
|
||||
profile={p}
|
||||
{index}
|
||||
selected={currentProfile?.data.id == profile.id}
|
||||
selected={profile?.current.id == p.id}
|
||||
size={40}
|
||||
/>
|
||||
<div class="flex flex-col overflow-hidden">
|
||||
<span class="break-words font-medium text-base">
|
||||
{profile.username}
|
||||
{#if !profile.jwt}
|
||||
{p.username}
|
||||
{#if !p.jwt}
|
||||
<Badge class="inline-grid w-6 h-6 p-0! place-items-center">
|
||||
<Icon src={QuestionMarkCircle} size="16" micro />
|
||||
</Badge>
|
||||
{/if}
|
||||
</span>
|
||||
<span class="text-sm text-slate-600 dark:text-zinc-400">
|
||||
{profile.instance}
|
||||
{p.instance}
|
||||
</span>
|
||||
</div>
|
||||
<Menu placement="bottom-end">
|
||||
@@ -201,7 +195,7 @@
|
||||
size="square-md"
|
||||
color="secondary"
|
||||
title={$t('account.moveUp')}
|
||||
onclick={() => moveProfile(profile.id, true)}
|
||||
onclick={() => profile.move(p.id, true)}
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<Icon src={ChevronUp} size="16" mini />
|
||||
@@ -211,7 +205,7 @@
|
||||
size="square-md"
|
||||
color="secondary"
|
||||
title={$t('account.moveDown')}
|
||||
onclick={() => moveProfile(profile.id, false)}
|
||||
onclick={() => profile.move(p.id, false)}
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<Icon src={ChevronDown} size="16" mini />
|
||||
@@ -221,7 +215,7 @@
|
||||
{#if settings.debugInfo}
|
||||
<MenuButton
|
||||
onclick={() => {
|
||||
debugProfile = profile
|
||||
debugProfile = p
|
||||
debugging = !debugging
|
||||
}}
|
||||
>
|
||||
@@ -231,10 +225,10 @@
|
||||
{$t('common.debug')}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
{#if !LINKED_INSTANCE_URL || profile.user}
|
||||
{#if !LINKED_INSTANCE_URL || p.user}
|
||||
<MenuButton
|
||||
onclick={() => {
|
||||
removing.account = profile
|
||||
removing.account = p
|
||||
removing.shown = !removing.shown
|
||||
}}
|
||||
color="danger-subtle"
|
||||
|
||||
@@ -8,7 +8,7 @@ export async function load({ fetch, url }) {
|
||||
const uri = url.searchParams.get('uri')
|
||||
if (!uri) error(404)
|
||||
|
||||
if (!profile.data.jwt)
|
||||
if (!profile.current.jwt)
|
||||
redirect(302, `/login?ref=${encodeURIComponent(url.toString())}`)
|
||||
|
||||
return {
|
||||
|
||||
@@ -5,7 +5,7 @@ import { ReactiveState } from '$lib/promise.svelte.js'
|
||||
export async function load({ fetch, url }) {
|
||||
if (!profile) return
|
||||
|
||||
const { jwt } = profile.data!
|
||||
const { jwt } = profile.current!
|
||||
if (!jwt) return
|
||||
|
||||
const page = Number(url.searchParams.get('page')) || 1
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
let reviewing = $state(false)
|
||||
|
||||
async function review(approve: boolean) {
|
||||
if (!profile.data?.jwt) return
|
||||
if (!profile.current?.jwt) return
|
||||
|
||||
let registrationApplicationAnswer: ApproveRegistrationApplication = {
|
||||
approve: approve,
|
||||
@@ -67,7 +67,7 @@
|
||||
type: 'success',
|
||||
})
|
||||
application.creator_local_user.accepted_application = approve
|
||||
application.admin = profile.data.user!.local_user_view.person
|
||||
application.admin = profile.current.user!.local_user_view.person
|
||||
application.registration_application.deny_reason = denyReason
|
||||
|
||||
$notifications.applications -= 1
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
)
|
||||
|
||||
async function save() {
|
||||
if (!profile.data?.jwt) return
|
||||
if (!profile.current?.jwt) return
|
||||
|
||||
saving = true
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@
|
||||
if (instance == '') return
|
||||
await trycatch(async () => {
|
||||
if (
|
||||
!profile.data?.jwt ||
|
||||
!profile.current?.jwt ||
|
||||
!data.federated_instances?.federated_instances?.blocked ||
|
||||
!data.federated_instances?.federated_instances?.allowed
|
||||
)
|
||||
@@ -81,7 +81,7 @@
|
||||
const save = async () => {
|
||||
const res = await trycatch(async () => {
|
||||
if (
|
||||
!profile.data?.jwt ||
|
||||
!profile.current?.jwt ||
|
||||
!data.federated_instances?.federated_instances?.blocked
|
||||
)
|
||||
return
|
||||
|
||||
@@ -3,7 +3,7 @@ import { client } from '$lib/lemmy.svelte.js'
|
||||
import { ReactiveState } from '$lib/promise.svelte.js'
|
||||
|
||||
export async function load({ fetch, url }) {
|
||||
const { jwt } = profile.data
|
||||
const { jwt } = profile.current
|
||||
|
||||
const page = Number(url.searchParams.get('page')) || 1
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
let saving = $state(false)
|
||||
|
||||
async function save() {
|
||||
if (!profile.data?.jwt) return
|
||||
if (!profile.current?.jwt) return
|
||||
|
||||
saving = true
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
action: () => removeAdmin(id, true),
|
||||
})
|
||||
|
||||
if (!profile.data?.jwt) return
|
||||
if (!profile.current?.jwt) return
|
||||
|
||||
const result = await trycatch(() =>
|
||||
getClient().addAdmin({
|
||||
@@ -77,7 +77,7 @@
|
||||
class="flex flex-row items-center gap-2 mt-auto w-full"
|
||||
onsubmit={preventDefault(() => {
|
||||
trycatch(async () => {
|
||||
if (!profile.data?.jwt || newAdmin == '') return
|
||||
if (!profile.current?.jwt || newAdmin == '') return
|
||||
adding = true
|
||||
|
||||
const r = await addAdmin(`${newAdmin}@${instance.data}`, true)
|
||||
|
||||
@@ -81,10 +81,10 @@
|
||||
{/snippet}
|
||||
</Header>
|
||||
|
||||
{#if profile.data.user}
|
||||
{#if !data.community.value.discussion_languages.every( l => profile.data.user?.discussion_languages.includes(l), ) && profile.data.user.discussion_languages.length > 0}
|
||||
{#if profile.current.user}
|
||||
{#if !data.community.value.discussion_languages.every( l => profile.current.user?.discussion_languages.includes(l), ) && profile.current.user.discussion_languages.length > 0}
|
||||
{@const missing = data.community.value.discussion_languages.filter(
|
||||
i => !profile.data.user?.discussion_languages.includes(i),
|
||||
i => !profile.current.user?.discussion_languages.includes(i),
|
||||
)}
|
||||
<Note class="p-1! pl-3! flex-col md:flex-row">
|
||||
<div>{$t('routes.community.languageWarning')}</div>
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
})
|
||||
|
||||
async function addModerator() {
|
||||
if (!profile.data?.jwt) return
|
||||
if (!profile.current?.jwt) return
|
||||
|
||||
formData.addingModerator = true
|
||||
|
||||
@@ -80,7 +80,7 @@
|
||||
}
|
||||
|
||||
async function removeMod(id: number) {
|
||||
if (!profile.data?.jwt) return
|
||||
if (!profile.current?.jwt) return
|
||||
|
||||
try {
|
||||
const res = await getClient().addModToCommunity({
|
||||
|
||||
@@ -4,11 +4,11 @@ import { client } from '$lib/lemmy.svelte.js'
|
||||
import { redirect } from '@sveltejs/kit'
|
||||
|
||||
export async function load({ params, fetch }) {
|
||||
if (profile.data.instance != params.instance)
|
||||
if (profile.current.instance != params.instance)
|
||||
redirect(302, resolveRoute('/comment/[instance]/[id]/confirm', params))
|
||||
|
||||
const comment = await client({
|
||||
instanceURL: profile.data.instance,
|
||||
instanceURL: profile.current.instance,
|
||||
func: fetch,
|
||||
}).getComment({
|
||||
id: Number(params.id),
|
||||
@@ -16,6 +16,6 @@ export async function load({ params, fetch }) {
|
||||
|
||||
redirect(
|
||||
302,
|
||||
`/post/${profile.data.instance}/${comment.comment_view.post.id}?thread=${comment.comment_view.comment.path}#${comment.comment_view.comment.id}`,
|
||||
`/post/${profile.current.instance}/${comment.comment_view.post.id}?thread=${comment.comment_view.comment.path}#${comment.comment_view.comment.id}`,
|
||||
)
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
import { goto } from '$app/navigation'
|
||||
import { resolveRoute } from '$app/paths'
|
||||
import { page } from '$app/state'
|
||||
import { profile, profileData } from '$lib/auth.svelte'
|
||||
import { profile } from '$lib/auth.svelte'
|
||||
import Header from '$lib/components/ui/layout/pages/Header.svelte'
|
||||
import ProfileButton from '$lib/components/ui/sidebar/ProfileButton.svelte'
|
||||
import SidebarButton from '$lib/components/ui/sidebar/SidebarButton.svelte'
|
||||
@@ -15,7 +15,7 @@
|
||||
import { Plus } from 'svelte-hero-icons'
|
||||
|
||||
let loading = $state(false)
|
||||
const fetched = $state.snapshot(profile.data.instance)
|
||||
const fetched = $state.snapshot(profile.current.instance)
|
||||
|
||||
async function fetchOnHome() {
|
||||
loading = true
|
||||
@@ -27,7 +27,7 @@
|
||||
if (res.comment) {
|
||||
goto(
|
||||
resolveRoute(`/comment/[instance]/[id]`, {
|
||||
instance: profile.data.instance,
|
||||
instance: profile.current.instance,
|
||||
id: res.comment.comment.id.toString(),
|
||||
}),
|
||||
)
|
||||
@@ -56,7 +56,7 @@
|
||||
</p>
|
||||
</header>
|
||||
<div class="flex flex-row items-center gap-2 flex-wrap">
|
||||
{#if profile.data.jwt}
|
||||
{#if profile.current.jwt}
|
||||
<Button
|
||||
{loading}
|
||||
disabled={loading}
|
||||
@@ -74,8 +74,8 @@
|
||||
{$t('routes.postRedirect.actions.back')}
|
||||
</Button>
|
||||
</div>
|
||||
{#if profileData.profiles}
|
||||
{@const filtered = profileData.profiles.filter(
|
||||
{#if profile.meta.profiles}
|
||||
{@const filtered = profile.meta.profiles.filter(
|
||||
i => i.instance == page.params.instance,
|
||||
)}
|
||||
<div class="space-y-1">
|
||||
|
||||
@@ -2,6 +2,6 @@ import { profile } from '$lib/auth.svelte.js'
|
||||
import { redirect } from '@sveltejs/kit'
|
||||
|
||||
export async function load({ params }) {
|
||||
if (profile.data.instance == params.instance)
|
||||
if (profile.current.instance == params.instance)
|
||||
redirect(302, `/comment/${params.instance}/${params.id}`)
|
||||
}
|
||||
@@ -32,7 +32,7 @@
|
||||
id: number | undefined = community?.community.id,
|
||||
subscribed: SubscribedType | undefined = community?.subscribed,
|
||||
) {
|
||||
if (!profile.data?.jwt) return
|
||||
if (!profile.current?.jwt) return
|
||||
if (!id || !subscribed) return
|
||||
|
||||
subscribing = true
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
let { data } = $props()
|
||||
|
||||
onMount(() => {
|
||||
if (!profile.data?.jwt) {
|
||||
if (!profile.current?.jwt) {
|
||||
goto('/login')
|
||||
}
|
||||
})
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
let markingAsRead = $state(false)
|
||||
|
||||
async function markAllAsRead() {
|
||||
if (!profile.data?.user) {
|
||||
if (!profile.current?.user) {
|
||||
goto('/login')
|
||||
return
|
||||
}
|
||||
@@ -156,7 +156,7 @@ items-center px-2 w-max top-6 lg:top-22"
|
||||
/>
|
||||
{:else}
|
||||
{#each data.inbox.value as item, index}
|
||||
{#if item.creator.id != profile.data.user?.local_user_view.person.id}
|
||||
{#if item.creator.id != profile.current.user?.local_user_view.person.id}
|
||||
<div
|
||||
class="-mx-4 sm:-mx-6 px-4 sm:px-6
|
||||
{item.read ? '' : 'bg-blue-50/50 dark:bg-blue-500/5'}"
|
||||
|
||||
@@ -12,7 +12,7 @@ import { error } from '@sveltejs/kit'
|
||||
type InboxFeedType = 'replies' | 'mentions' | 'messages' | 'all'
|
||||
|
||||
export async function load({ url, fetch }) {
|
||||
if (!profile.data.jwt) error(401)
|
||||
if (!profile.current.jwt) error(401)
|
||||
|
||||
const type: InboxFeedType =
|
||||
(url.searchParams.get('type') as InboxFeedType) || 'all'
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
let loading = $state(false)
|
||||
|
||||
async function markAsRead(isRead: boolean) {
|
||||
if (!profile.data?.jwt) return
|
||||
if (!profile.current?.jwt) return
|
||||
|
||||
loading = true
|
||||
|
||||
@@ -52,7 +52,7 @@
|
||||
}
|
||||
|
||||
item.read = isRead
|
||||
if (profile.data.user) $notifications.inbox += isRead ? -1 : 1
|
||||
if (profile.current.user) $notifications.inbox += isRead ? -1 : 1
|
||||
|
||||
loading = false
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
}
|
||||
|
||||
function getOtherPartyId(message: PrivateMessageView): number {
|
||||
return message.creator.id == profile.data.user?.local_user_view.person.id
|
||||
return message.creator.id == profile.current.user?.local_user_view.person.id
|
||||
? message.recipient.id
|
||||
: message.creator.id
|
||||
}
|
||||
@@ -56,7 +56,7 @@
|
||||
.filter(c => c.creator.id != c.recipient.id) // you messaged yourself
|
||||
.map(i => ({
|
||||
user:
|
||||
i.creator.id != profile.data.user?.local_user_view.person.id
|
||||
i.creator.id != profile.current.user?.local_user_view.person.id
|
||||
? i.creator
|
||||
: i.recipient,
|
||||
message: {
|
||||
@@ -153,8 +153,8 @@
|
||||
bg-linear-to-r from-slate-700 via-slate-700 to-slate-700/0 dark:from-zinc-300 dark:via-zinc-300 dark:to-zinc-300/0
|
||||
text-transparent bg-clip-text flex-1 overflow-hidden"
|
||||
>
|
||||
{#if preview.message.last_sender == profile.data.user?.local_user_view.person.id}
|
||||
{profile.data.user?.local_user_view.person.name}:
|
||||
{#if preview.message.last_sender == profile.current.user?.local_user_view.person.id}
|
||||
{profile.current.user?.local_user_view.person.name}:
|
||||
{/if}
|
||||
{preview.message.content}
|
||||
</div>
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
|
||||
import { goto } from '$app/navigation'
|
||||
import { page } from '$app/state'
|
||||
import { setUser } from '$lib/auth.svelte.js'
|
||||
import ErrorContainer, {
|
||||
clearErrorScope,
|
||||
pushError,
|
||||
@@ -25,6 +24,7 @@
|
||||
QuestionMarkCircle,
|
||||
UserCircle,
|
||||
} from 'svelte-hero-icons'
|
||||
import { profile } from '$lib/auth.svelte'
|
||||
|
||||
interface Props {
|
||||
ref?: string
|
||||
@@ -57,7 +57,7 @@
|
||||
})
|
||||
|
||||
if (response?.jwt) {
|
||||
const result = await setUser(response.jwt, data.instance, data.username)
|
||||
const result = await profile.add(response.jwt, data.instance)
|
||||
|
||||
if (result) {
|
||||
toast({ content: $t('toast.logIn'), type: 'success' })
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
|
||||
import { goto } from '$app/navigation'
|
||||
import { page } from '$app/state'
|
||||
import { profileData } from '$lib/auth.svelte'
|
||||
import Header from '$lib/components/ui/layout/pages/Header.svelte'
|
||||
import { t } from '$lib/i18n/translations'
|
||||
import { LINKED_INSTANCE_URL } from '$lib/instance.svelte'
|
||||
@@ -12,6 +11,7 @@
|
||||
import { DOMAIN_REGEX_FORMS } from '$lib/util.svelte'
|
||||
import { MINIMUM_VERSION } from '$lib/version'
|
||||
import { Button, Note, TextInput, toast } from 'mono-svelte'
|
||||
import { profile } from '$lib/auth.svelte'
|
||||
|
||||
interface Props {
|
||||
ref?: string
|
||||
@@ -23,7 +23,7 @@
|
||||
|
||||
let form = $state({
|
||||
instance: '',
|
||||
username: `${$t('account.guest')} ${profileData.profiles.filter(p => p.jwt == undefined).length + 1}`,
|
||||
username: `${$t('account.guest')} ${profile.meta.profiles.filter(p => p.jwt == undefined).length + 1}`,
|
||||
loading: false,
|
||||
})
|
||||
|
||||
@@ -35,13 +35,13 @@
|
||||
return
|
||||
}
|
||||
|
||||
const id = Math.max(...profileData.profiles.map(i => i.id)) + 1
|
||||
profileData.profiles.push({
|
||||
const id = Math.max(...profile.meta.profiles.map(i => i.id)) + 1
|
||||
profile.meta.profiles.push({
|
||||
id: id,
|
||||
instance: form.instance,
|
||||
username: form.username,
|
||||
})
|
||||
profileData.profile = id
|
||||
profile.meta.profile = id
|
||||
|
||||
toast({ content: $t('toast.addAccount'), type: 'success' })
|
||||
|
||||
|
||||
@@ -2,5 +2,5 @@ import { profile } from '$lib/auth.svelte'
|
||||
import { error } from '@sveltejs/kit'
|
||||
|
||||
export function load() {
|
||||
if (!profile.data.jwt) error(401)
|
||||
if (!profile.current.jwt) error(401)
|
||||
}
|
||||
@@ -14,7 +14,7 @@ import { error } from '@sveltejs/kit'
|
||||
type ReportListType = 'unread' | 'all'
|
||||
|
||||
export async function load({ url, fetch }) {
|
||||
if (!profile.data.jwt) error(401)
|
||||
if (!profile.current.jwt) error(401)
|
||||
|
||||
const page = Number(url.searchParams.get('page')) || 1
|
||||
const type: ReportListType =
|
||||
@@ -30,7 +30,7 @@ export async function load({ url, fetch }) {
|
||||
community_id: community,
|
||||
}
|
||||
|
||||
const admin = profile.data?.user ? isAdmin(profile!.data.user!) : false
|
||||
const admin = profile.current?.user ? isAdmin(profile!.data.user!) : false
|
||||
|
||||
const [posts, comments, messages] = await Promise.all([
|
||||
client.listPostReports({
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
let resolving = $state(false)
|
||||
async function resolve() {
|
||||
if (!profile.data?.jwt || !profile.data.user) return
|
||||
if (!profile.current?.jwt || !profile.current.user) return
|
||||
resolving = true
|
||||
|
||||
try {
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
{$t('nav.communities')}
|
||||
</Header>
|
||||
<div class="w-full h-full flex flex-col mt-4">
|
||||
{#if !profile.data.user}
|
||||
{#if !profile.current.user}
|
||||
<div class="mx-auto my-auto">
|
||||
<Spinner width={24} />
|
||||
</div>
|
||||
@@ -20,7 +20,7 @@
|
||||
rounding="2xl"
|
||||
class="flex flex-col dark:bg-zinc-950 max-h-[32rem] overflow-auto"
|
||||
>
|
||||
{#each profile.data.user.moderates as moderate}
|
||||
{#each profile.current.user.moderates as moderate}
|
||||
{@const community = moderate.community}
|
||||
<div
|
||||
class="-mx-4 px-4 hover:bg-slate-100 hover:dark:bg-zinc-900 transition-colors duration-75"
|
||||
|
||||
@@ -206,7 +206,7 @@
|
||||
<UserAutocomplete
|
||||
instance={page.url.searchParams.get('instance') || undefined}
|
||||
placeholder="Filter by user"
|
||||
jwt={profile.data?.jwt}
|
||||
jwt={profile.current?.jwt}
|
||||
listing_type="All"
|
||||
showWhenEmpty={true}
|
||||
class="flex-1"
|
||||
@@ -217,10 +217,10 @@
|
||||
onselect={e =>
|
||||
searchParam(page.url, 'user', e?.id.toString() ?? '', 'page')}
|
||||
/>
|
||||
{#if profile.data?.user && isAdmin(profile.data?.user)}
|
||||
{#if profile.current?.user && isAdmin(profile.current?.user)}
|
||||
<UserAutocomplete
|
||||
placeholder="Filter by moderator"
|
||||
jwt={profile.data?.jwt}
|
||||
jwt={profile.current?.jwt}
|
||||
listing_type="All"
|
||||
showWhenEmpty={true}
|
||||
class="flex-1"
|
||||
|
||||
@@ -7,7 +7,7 @@ export function load({ params }) {
|
||||
redirect(
|
||||
302,
|
||||
resolveRoute(`/post/[instance]/[id]`, {
|
||||
instance: profile.data.instance.toLowerCase(),
|
||||
instance: profile.current.instance.toLowerCase(),
|
||||
id: params.instance,
|
||||
}),
|
||||
)
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
onMount(async () => {
|
||||
if (
|
||||
!(data.post.value.post_view.read && settings.markPostsAsRead) &&
|
||||
profile.data?.jwt
|
||||
profile.current?.jwt
|
||||
) {
|
||||
getClient().markPostAsRead({
|
||||
read: settings.markPostsAsRead,
|
||||
|
||||
@@ -28,7 +28,7 @@ function buildContext(thread?: string) {
|
||||
}
|
||||
|
||||
export async function load({ params, url, fetch }) {
|
||||
if (profile.data.instance != params.instance)
|
||||
if (profile.current.instance != params.instance)
|
||||
redirect(302, resolveRoute('/post/[instance]/[id]/confirm', params))
|
||||
|
||||
// TODO use Lemmy profile default settings
|
||||
|
||||
@@ -51,7 +51,7 @@
|
||||
})
|
||||
</script>
|
||||
|
||||
{#if profile.data?.jwt}
|
||||
{#if profile.current?.jwt}
|
||||
{#if !commenting}
|
||||
<EndPlaceholder>
|
||||
<Button
|
||||
@@ -60,8 +60,8 @@
|
||||
disabled={(post.post_view.post.locked ||
|
||||
post.post_view.banned_from_community) &&
|
||||
!(
|
||||
profile.data?.user?.local_user_view.local_user.admin ||
|
||||
profile.data?.user?.moderates
|
||||
profile.current?.user?.local_user_view.local_user.admin ||
|
||||
profile.current?.user?.moderates
|
||||
.map(c => c.community.id)
|
||||
.includes(post.community_view.community.id)
|
||||
)}
|
||||
@@ -119,7 +119,7 @@
|
||||
{/if}
|
||||
{/if}
|
||||
|
||||
{#if commenting || !profile.data.jwt}
|
||||
{#if commenting || !profile.current.jwt}
|
||||
<div class="gap-2 flex items-center">
|
||||
<Select
|
||||
size="md"
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
import { goto } from '$app/navigation'
|
||||
import { resolveRoute } from '$app/paths'
|
||||
import { page } from '$app/state'
|
||||
import { profile, profileData } from '$lib/auth.svelte'
|
||||
import { profile } from '$lib/auth.svelte'
|
||||
import Header from '$lib/components/ui/layout/pages/Header.svelte'
|
||||
import ProfileButton from '$lib/components/ui/sidebar/ProfileButton.svelte'
|
||||
import SidebarButton from '$lib/components/ui/sidebar/SidebarButton.svelte'
|
||||
@@ -15,7 +15,7 @@
|
||||
import { Plus } from 'svelte-hero-icons'
|
||||
|
||||
let loading = $state(false)
|
||||
const fetched = $state.snapshot(profile.data.instance)
|
||||
const fetched = $state.snapshot(profile.current.instance)
|
||||
|
||||
async function fetchOnHome() {
|
||||
loading = true
|
||||
@@ -27,7 +27,7 @@
|
||||
if (res.post) {
|
||||
goto(
|
||||
resolveRoute(`/post/[instance]/[id]`, {
|
||||
instance: profile.data.instance,
|
||||
instance: profile.current.instance,
|
||||
id: res.post.post.id.toString(),
|
||||
}),
|
||||
)
|
||||
@@ -56,7 +56,7 @@
|
||||
</p>
|
||||
</header>
|
||||
<div class="flex flex-row items-center gap-2 flex-wrap">
|
||||
{#if profile.data.jwt}
|
||||
{#if profile.current.jwt}
|
||||
<Button
|
||||
{loading}
|
||||
disabled={loading}
|
||||
@@ -74,8 +74,8 @@
|
||||
{$t('routes.postRedirect.actions.back')}
|
||||
</Button>
|
||||
</div>
|
||||
{#if profileData.profiles}
|
||||
{@const filtered = profileData.profiles.filter(
|
||||
{#if profile.meta.profiles}
|
||||
{@const filtered = profile.meta.profiles.filter(
|
||||
i => i.instance == page.params.instance,
|
||||
)}
|
||||
<div class="space-y-1">
|
||||
|
||||
@@ -2,6 +2,6 @@ import { profile } from '$lib/auth.svelte.js'
|
||||
import { redirect } from '@sveltejs/kit'
|
||||
|
||||
export async function load({ params }) {
|
||||
if (profile.data.instance == params.instance)
|
||||
if (profile.current.instance == params.instance)
|
||||
redirect(302, `/post/${params.instance}/${params.id}`)
|
||||
}
|
||||
@@ -30,7 +30,7 @@
|
||||
let data = $state(pageData)
|
||||
|
||||
async function unblockUser(item: PersonBlockView) {
|
||||
if (!profile.data?.jwt) return
|
||||
if (!profile.current?.jwt) return
|
||||
|
||||
data.person_blocks.splice(
|
||||
data.person_blocks.findIndex(i => i.target.id == item.target.id),
|
||||
@@ -46,7 +46,7 @@
|
||||
}
|
||||
|
||||
async function unblockCommunity(item: CommunityBlockView) {
|
||||
if (!profile.data?.jwt) return
|
||||
if (!profile.current?.jwt) return
|
||||
|
||||
data.community_blocks.splice(
|
||||
data.community_blocks.findIndex(i => i.community.id == item.community.id),
|
||||
@@ -63,7 +63,7 @@
|
||||
}
|
||||
|
||||
async function unblockInstances(item: InstanceBlockView) {
|
||||
if (!profile.data?.jwt) return
|
||||
if (!profile.current?.jwt) return
|
||||
if (!data.my_user?.instance_blocks) return
|
||||
|
||||
data.my_user.instance_blocks.splice(
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
<script lang="ts">
|
||||
import { preventDefault } from 'svelte/legacy'
|
||||
|
||||
import { deleteProfile, profile, setUser } from '$lib/auth.svelte'
|
||||
import { client } from '$lib/lemmy.svelte'
|
||||
import { t } from '$lib/i18n/translations'
|
||||
import { Button, TextInput, toast } from 'mono-svelte'
|
||||
import { errorMessage } from '$lib/lemmy/error'
|
||||
import { profile } from '$lib/auth.svelte'
|
||||
|
||||
let oldPassword = $state(''),
|
||||
newPassword = $state(''),
|
||||
@@ -21,9 +21,9 @@
|
||||
old_password: oldPassword,
|
||||
})
|
||||
if (res?.jwt) {
|
||||
const { instance, username } = profile.data
|
||||
deleteProfile(profile.data.id)
|
||||
await setUser(res.jwt, instance, username!)
|
||||
const { instance } = profile.current
|
||||
profile.remove(profile.current.id)
|
||||
await profile.add(res.jwt, instance)
|
||||
|
||||
toast({ content: $t('toast.loginRefresh'), type: 'success' })
|
||||
} else {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { goto } from '$app/navigation'
|
||||
import { profileData, setUserID } from '$lib/auth.svelte'
|
||||
import Header from '$lib/components/ui/layout/pages/Header.svelte'
|
||||
import { client } from '$lib/lemmy.svelte'
|
||||
import { t } from '$lib/i18n/translations'
|
||||
@@ -14,6 +13,7 @@
|
||||
TextInput,
|
||||
toast,
|
||||
} from 'mono-svelte'
|
||||
import { profile } from '$lib/auth.svelte'
|
||||
|
||||
let deletion = $state({
|
||||
modal: false,
|
||||
@@ -70,11 +70,11 @@
|
||||
delete_content: deletion.deleteContent,
|
||||
})
|
||||
|
||||
profileData.profiles.splice(
|
||||
profileData.profiles.findIndex(p => profileData.profile == p.id),
|
||||
profile.meta.profiles.splice(
|
||||
profile.meta.profiles.findIndex(p => profile.meta.profile == p.id),
|
||||
)
|
||||
|
||||
setUserID(-1)
|
||||
profile.meta.profile = -1
|
||||
toast({
|
||||
content: $t('toast.deleted'),
|
||||
})
|
||||
|
||||
@@ -41,7 +41,7 @@
|
||||
let bannerImage: FileList | undefined = $state()
|
||||
|
||||
async function save() {
|
||||
if (!formData || !profile.data?.jwt) return
|
||||
if (!formData || !profile.current?.jwt) return
|
||||
|
||||
loading = true
|
||||
|
||||
@@ -49,16 +49,16 @@
|
||||
let pfp = profileImage
|
||||
? await uploadImage(
|
||||
profileImage[0],
|
||||
profile.data.instance,
|
||||
profile.data.jwt,
|
||||
profile.current.instance,
|
||||
profile.current.jwt,
|
||||
)
|
||||
: undefined
|
||||
|
||||
let banner = bannerImage
|
||||
? await uploadImage(
|
||||
bannerImage[0],
|
||||
profile.data.instance,
|
||||
profile.data.jwt,
|
||||
profile.current.instance,
|
||||
profile.current.jwt,
|
||||
)
|
||||
: undefined
|
||||
|
||||
|
||||
@@ -6,11 +6,12 @@ import { error } from '@sveltejs/kit'
|
||||
export const ssr = false
|
||||
|
||||
export async function load({ fetch }) {
|
||||
if (!profile.data.jwt) error(401)
|
||||
if (!profile.current.jwt) error(401)
|
||||
|
||||
const my_user =
|
||||
// profile.data?.user ??
|
||||
(await client({ auth: profile.data?.jwt, func: fetch }).getSite()).my_user
|
||||
// profile.current?.user ??
|
||||
(await client({ auth: profile.current?.jwt, func: fetch }).getSite())
|
||||
.my_user
|
||||
|
||||
return {
|
||||
my_user: my_user,
|
||||
|
||||
@@ -3,7 +3,7 @@ import { client } from '$lib/lemmy.svelte.js'
|
||||
import { ReactiveState } from '$lib/promise.svelte.js'
|
||||
|
||||
export async function load({ fetch, url }) {
|
||||
const { jwt } = profile.data
|
||||
const { jwt } = profile.current
|
||||
|
||||
const page = Number(url.searchParams.get('page')) || 1
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ function getSavedItemPublished(item: PostView | CommentView) {
|
||||
}
|
||||
|
||||
export async function load({ url, fetch }) {
|
||||
if (!profile.data.jwt) throw error(401)
|
||||
if (!profile.current.jwt) throw error(401)
|
||||
|
||||
const page = Number(url.searchParams.get('page')) || 1
|
||||
const type: 'comments' | 'posts' | 'all' =
|
||||
|
||||
@@ -96,7 +96,7 @@
|
||||
>
|
||||
<ObjectAutocomplete
|
||||
label={$t('nav.create.community')}
|
||||
jwt={profile.data?.jwt}
|
||||
jwt={profile.current?.jwt}
|
||||
listing_type="All"
|
||||
showWhenEmpty={true}
|
||||
onselect={c =>
|
||||
|
||||
@@ -50,7 +50,7 @@ export async function load({ url, fetch }) {
|
||||
})!,
|
||||
results: new ReactiveState(everything),
|
||||
streamed: {
|
||||
object: profile.data?.jwt
|
||||
object: profile.current?.jwt
|
||||
? getClient(undefined, fetch).resolveObject({
|
||||
q: query,
|
||||
})
|
||||
|
||||
@@ -208,7 +208,7 @@
|
||||
class="flex flex-col *:py-2 divide-y divide-slate-200 dark:divide-zinc-800"
|
||||
style="scroll-behavior: smooth;"
|
||||
>
|
||||
{#if profile.data?.jwt}
|
||||
{#if profile.current?.jwt}
|
||||
<Section open={false} id="account" title={$t('settings.account.title')}>
|
||||
<div>
|
||||
<Button
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
|
||||
import { goto } from '$app/navigation'
|
||||
import { page } from '$app/state'
|
||||
import { setUser } from '$lib/auth.svelte.js'
|
||||
import ErrorContainer, {
|
||||
clearErrorScope,
|
||||
pushError,
|
||||
@@ -37,6 +36,7 @@
|
||||
QuestionMarkCircle,
|
||||
XCircle,
|
||||
} from 'svelte-hero-icons'
|
||||
import { profile } from '$lib/auth.svelte.js'
|
||||
|
||||
let { data } = $props()
|
||||
|
||||
@@ -88,7 +88,7 @@
|
||||
const registrationMode = data.site_view.local_site.registration_mode
|
||||
|
||||
if (res?.jwt) {
|
||||
await setUser(res.jwt, page.params.instance)
|
||||
await profile.add(res.jwt, page.params.instance)
|
||||
|
||||
toast({ content: $t('toast.logIn'), type: 'success' })
|
||||
goto('/')
|
||||
@@ -127,7 +127,7 @@
|
||||
})
|
||||
|
||||
if (res.jwt) {
|
||||
await setUser(res.jwt, page.params.instance)
|
||||
await profile.add(res.jwt, page.params.instance)
|
||||
goto('/')
|
||||
} else if (res.verify_email_sent) {
|
||||
pushError({
|
||||
|
||||
@@ -55,11 +55,11 @@
|
||||
let sortForm = $state<HTMLFormElement>()
|
||||
|
||||
async function blockUser(block: number) {
|
||||
if (!profile.data?.user || !profile.data?.jwt)
|
||||
if (!profile.current?.user || !profile.current?.jwt)
|
||||
throw new Error('Unauthenticated')
|
||||
|
||||
try {
|
||||
const blocked = isBlocked(profile.data.user, block)
|
||||
const blocked = isBlocked(profile.current.user, block)
|
||||
|
||||
await getClient().blockPerson({
|
||||
block: !blocked,
|
||||
@@ -67,10 +67,10 @@
|
||||
})
|
||||
|
||||
if (blocked) {
|
||||
const index = profile.data.user.person_blocks
|
||||
const index = profile.current.user.person_blocks
|
||||
.map(p => p.target.id)
|
||||
.indexOf(block)
|
||||
profile.data.user.person_blocks.splice(index, 1)
|
||||
profile.current.user.person_blocks.splice(index, 1)
|
||||
}
|
||||
|
||||
toast({
|
||||
@@ -210,7 +210,7 @@
|
||||
</Expandable>
|
||||
{/if}
|
||||
{#snippet actions()}
|
||||
{#if profile.data?.user && profile.data.jwt && data.person_view.value.person.id != profile.data.user.local_user_view.person.id}
|
||||
{#if profile.current?.user && profile.current.jwt && data.person_view.value.person.id != profile.current.user.local_user_view.person.id}
|
||||
<div class="flex items-center gap-2 w-full flex-wrap">
|
||||
<Button
|
||||
size="sm"
|
||||
@@ -237,7 +237,7 @@
|
||||
{$t('form.profile.matrix')}
|
||||
</Button>
|
||||
{/if}
|
||||
{#if isAdmin(profile.data?.user)}
|
||||
{#if isAdmin(profile.current?.user)}
|
||||
<Menu class="ml-auto" placement="bottom-end">
|
||||
{#snippet target()}
|
||||
<Button size="sm" rounding="pill">
|
||||
@@ -292,7 +292,7 @@
|
||||
<Icon mini size="16" src={NoSymbol} />
|
||||
{/snippet}
|
||||
{isBlocked(
|
||||
profile.data.user,
|
||||
profile.current.user,
|
||||
data.person_view.value.person.id,
|
||||
)
|
||||
? 'Unblock'
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
style="rotate: -5deg; transition: rotate 1s linear;"
|
||||
>
|
||||
<div class="bg-black/20 font-mono fixed left-1/2 -translate-x-1/2">
|
||||
<p>{profile.data.username ?? 'You'} was slain by Command Palette</p>
|
||||
<p>{profile.current.username ?? 'You'} was slain by Command Palette</p>
|
||||
</div>
|
||||
<img
|
||||
src="/other/mc.png"
|
||||
|
||||
Reference in new issue
Block a user