Skip to content

Commit

Permalink
Support 0.19 auth changes, nsfw edit fix
Browse files Browse the repository at this point in the history
The main part of this is updating to the way 0.19 does auth.

Additionally, if you edit a post that was marked NSFW, the NSFW setting defaults to the current value. Previously you'd need to check it again, fixes #87.
  • Loading branch information
sheodox committed Dec 17, 2023
1 parent fe82a4b commit 07e9ff9
Show file tree
Hide file tree
Showing 54 changed files with 393 additions and 420 deletions.
529 changes: 268 additions & 261 deletions package-lock.json

Large diffs are not rendered by default.

46 changes: 23 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "Alexandrite",
"version": "0.8.11",
"version": "0.8.12",
"private": true,
"scripts": {
"dev": "vite dev",
"dev": "vite dev --host 0.0.0.0",
"build": "vite build",
"preview": "vite preview",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
Expand All @@ -17,32 +17,32 @@
"devDependencies": {
"@sveltejs/adapter-auto": "^2.0.0",
"@sveltejs/adapter-node": "^1.3.1",
"@sveltejs/kit": "^1.22.3",
"@types/markdown-it": "^12.2.3",
"@types/markdown-it-container": "^2.0.6",
"@types/markdown-it-footnote": "^3.0.0",
"@typescript-eslint/eslint-plugin": "^6.2.0",
"@typescript-eslint/parser": "^6.2.0",
"eslint": "^8.45.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-svelte": "^2.32.4",
"prettier": "^3.0.0",
"prettier-plugin-svelte": "^3.0.0",
"sass": "^1.64.1",
"@sveltejs/kit": "^1.27.1",
"@types/markdown-it": "^13.0.5",
"@types/markdown-it-container": "^2.0.8",
"@types/markdown-it-footnote": "^3.0.2",
"@typescript-eslint/eslint-plugin": "^6.9.0",
"@typescript-eslint/parser": "^6.9.0",
"eslint": "^8.52.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-svelte": "^2.34.0",
"prettier": "^3.0.3",
"prettier-plugin-svelte": "^3.0.3",
"sass": "^1.69.4",
"sheodox-ui": "^0.20.3",
"svelte": "^4.1.1",
"svelte-check": "^3.4.6",
"tslib": "^2.6.1",
"typescript": "^5.1.6",
"vite": "^4.4.7",
"vitest": "^0.33.0"
"svelte": "^4.2.2",
"svelte-check": "^3.5.2",
"tslib": "^2.6.2",
"typescript": "^5.2.2",
"vite": "^4.5.0",
"vitest": "^0.34.6"
},
"type": "module",
"dependencies": {
"@fortawesome/fontawesome-free": "^6.4.0",
"@fortawesome/fontawesome-free": "^6.4.2",
"date-fns": "^2.30.0",
"lemmy-js-client": "^0.18.3-rc.3",
"markdown-it": "^13.0.1",
"lemmy-js-client": "^0.19.0-rc.19",
"markdown-it": "^13.0.2",
"markdown-it-container": "^3.0.0",
"markdown-it-footnote": "^3.0.3",
"markdown-it-ruby": "^0.1.1",
Expand Down
1 change: 0 additions & 1 deletion src/lib/CommunityJoin.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
}
const res = await client.followCommunity({
auth: jwt,
follow: communityView.subscribed === 'NotSubscribed',
community_id: communityView.community.id
});
Expand Down
2 changes: 0 additions & 2 deletions src/lib/CommunitySelector.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@
}
const res = await client.getCommunity({
auth: jwt,
name: communityName
});
Expand All @@ -102,7 +101,6 @@
}
} else {
const comms = await client.search({
auth: jwt,
type_: 'Communities',
q: searchText,
limit: 50
Expand Down
3 changes: 0 additions & 3 deletions src/lib/InboxReadButton.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,19 @@
if (content.type === 'reply') {
const res = await client.markCommentReplyAsRead({
auth: jwt,
comment_reply_id: id,
read
});
cvStore.updateView(replyViewToContentView(res.comment_reply_view));
} else if (content.type === 'mention') {
const res = await client.markPersonMentionAsRead({
auth: jwt,
person_mention_id: id,
read
});
cvStore.updateView(mentionViewToContentView(res.person_mention_view));
} else if (content.type === 'message') {
const res = await client.markPrivateMessageAsRead({
auth: jwt,
private_message_id: id,
read
});
Expand Down
1 change: 0 additions & 1 deletion src/lib/MarkdownEditor.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@
// busy = true;
// const { selectionStart } = textarea,
// res = await client.uploadImage({
// auth: jwt,
// image: file
// });
// console.log(res);
Expand Down
5 changes: 1 addition & 4 deletions src/lib/PostPage.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,6 @@
}
const res = await client.createComment({
content: body.content as string,
auth: jwt,
post_id: postView.post.id,
language_id: body.languageId ? Number(body.languageId) : undefined
});
Expand Down Expand Up @@ -514,7 +513,6 @@
const { comments, busy, error } = await loadComments(async () => {
const { comments } = await client.getComments({
auth: jwt,
post_id: postView.post.id,
limit: 100,
page: commentsPageNum++,
Expand All @@ -541,7 +539,6 @@
commentExpandLoadingIds = commentExpandLoadingIds;
await loadComments(async () => {
const { comments } = await client.getComments({
auth: jwt,
post_id: postView.post.id,
limit: 100,
parent_id: e.detail,
Expand Down Expand Up @@ -570,7 +567,7 @@
onMount(async () => {
if (jwt) {
// getting the post has a side effect of marking it and its comments as read
const res = await client.getPost({ id: postView.post.id, auth: jwt }).then((res) => {
const res = await client.getPost({ id: postView.post.id }).then((res) => {
res.post_view.read = true;
res.post_view.unread_comments = 0;
return res;
Expand Down
2 changes: 0 additions & 2 deletions src/lib/PrivateMessage.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@
return;
}
await client.createPrivateMessageReport({
auth: jwt,
reason: e.detail,
private_message_id: privateMessageView.private_message.id
});
Expand Down Expand Up @@ -154,7 +153,6 @@
}
if (confirm('Are you sure you want to delete this message?')) {
await client.deletePrivateMessage({
auth: jwt,
deleted: true,
private_message_id: privateMessageView.private_message.id
});
Expand Down
2 changes: 0 additions & 2 deletions src/lib/PrivateMessageCompose.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
// if they're editing a message, save the changes, don't send a new one
if (privateMessageView) {
res = await client.editPrivateMessage({
auth: jwt,
content: body.content as string,
private_message_id: privateMessageView.private_message.id
});
Expand All @@ -70,7 +69,6 @@
} else {
//else just create a new message
res = await client.createPrivateMessage({
auth: jwt,
content: body.content as string,
recipient_id: to.id
});
Expand Down
6 changes: 1 addition & 5 deletions src/lib/UserCounts.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,24 @@
<Stack dir="r" gap={2} align="center">
<strong>{count.count.toLocaleString()}</strong>
<span class="muted">{count.label}</span>
<strong>{count.score.toLocaleString()}</strong>
<Icon icon="trophy" />
</Stack>
{/each}
</Stack>

<script lang="ts">
import { Stack, Icon } from 'sheodox-ui';
import { Stack } from 'sheodox-ui';
import type { PersonView } from 'lemmy-js-client';
export let personView: PersonView;
$: counts = [
{
label: personView.counts.post_count === 1 ? 'Post' : 'Posts',
score: personView.counts.post_score,
count: personView.counts.post_count,
icon: 'file-lines'
},
{
label: personView.counts.comment_count === 1 ? 'Comment' : 'Comments',
score: personView.counts.comment_score,
count: personView.counts.comment_count,
icon: 'comments'
}
Expand Down
12 changes: 3 additions & 9 deletions src/lib/comments/Comment.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,9 @@
let showReportModal = false;
let replyForm: HTMLFormElement;
let editForm: HTMLFormElement;
$: isAdmin = $siteMeta.admins.some(
(admin) => admin.person.actor_id === $siteMeta.my_user?.local_user_view.person.actor_id
);
$: replyState = createStatefulForm(replyForm, replySubmit);
$: editState = createStatefulForm(editForm, editSubmit);
$: voteState = createStatefulAction<number>(async (score) => {
Expand All @@ -318,7 +321,6 @@
}
const res = await client.likeComment({
auth: jwt,
comment_id: comment.id,
score
});
Expand Down Expand Up @@ -378,7 +380,6 @@
const res = await client.createComment({
content: body.content as string,
auth: jwt,
post_id: contentView.view.post.id,
parent_id,
language_id: body.languageId ? Number(body.languageId) : undefined
Expand All @@ -400,7 +401,6 @@
const res = await client.editComment({
content: body.content as string,
auth: jwt,
comment_id: Number(body.commentId),
language_id: body.languageId ? Number(body.languageId) : undefined
});
Expand All @@ -415,7 +415,6 @@
}
const res = await client.deleteComment({
auth: jwt,
comment_id: comment.id,
deleted
});
Expand All @@ -429,7 +428,6 @@
return;
}
const res = await client.saveComment({
auth: jwt,
comment_id: contentView.view.comment.id,
save: !contentView.view.saved
});
Expand All @@ -441,7 +439,6 @@
return;
}
await client.createCommentReport({
auth: jwt,
reason: e.detail,
comment_id: contentView.view.comment.id
});
Expand All @@ -458,7 +455,6 @@
return;
}
await client.blockPerson({
auth: jwt,
person_id: contentView.view.creator.id,
block
});
Expand Down Expand Up @@ -597,8 +593,6 @@
});
}
const isAdmin = $siteMeta.my_user?.local_user_view.person.admin ?? false;
if (isCommunityModerator || isAdmin) {
const warn = isCommunityModerator ? $showModlogWarningModerated : $showModlogWarning,
modlogBase = `/${$profile.instance}/modlog${warn ? '' : '/view'}`;
Expand Down
1 change: 0 additions & 1 deletion src/lib/community-context/community-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ export const createCommunityContext = () => {
const { client, jwt } = get(profile);

Check failure on line 37 in src/lib/community-context/community-context.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'jwt' is assigned a value but never used

const res = await client.getCommunity({
auth: jwt,
name
});

Expand Down
3 changes: 0 additions & 3 deletions src/lib/feed-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ export const loadFeedData = async (filters: FeedDataQuery): Promise<ApiFeedLoad>
if (filters.username) {
const userDetails = await client.getPersonDetails({
sort: postQuery.sort,
auth: jwt,
username: filters.username,
limit: 50,
page,
Expand All @@ -72,7 +71,6 @@ export const loadFeedData = async (filters: FeedDataQuery): Promise<ApiFeedLoad>
if (typePosts || typeSaved) {
const postViews = await client
.getPosts({
auth: jwt,
limit: 50,
page,
community_name: filters.communityName ?? undefined,
Expand All @@ -98,7 +96,6 @@ export const loadFeedData = async (filters: FeedDataQuery): Promise<ApiFeedLoad>
query,
commentViews: await client
.getComments({
auth: jwt,
page,
sort: query.sort,
type_: query.listing,
Expand Down
1 change: 0 additions & 1 deletion src/lib/feeds/posts/CommunityHeader.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
return;
}
const res = await client.blockCommunity({
auth: jwt,
community_id: community.id,
block
});
Expand Down
12 changes: 4 additions & 8 deletions src/lib/feeds/posts/PostLayout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,10 @@
$: isMyPost = postView.creator.local && postView.creator.name === username;
$: isCommunityModerator =
$siteMeta.my_user?.moderates?.some((m) => m.community.id === postView.community.id) ?? false;
$: isAdminOfCommunity = $siteMeta.my_user?.local_user_view.person.admin && postView.community.local;
$: isAdmin = $siteMeta.admins.some(
(admin) => admin.person.actor_id === $siteMeta.my_user?.local_user_view.person.actor_id
);
$: isAdminOfCommunity = isAdmin && postView.community.local;
$: communityName = nameAtInstance(postView.community);
$: community = weaklyGetCommunity(communityName);
$: postMadeByModerator = $community?.moderators.some((m) => m.moderator.id === postView.creator.id);
Expand Down Expand Up @@ -228,7 +231,6 @@
const pv = await client
.likePost({
auth: jwt,
post_id: postView.post.id,
score: score
})
Expand All @@ -248,7 +250,6 @@
const pv = await client
.savePost({
post_id: postView.post.id,
auth: jwt,
save: !postView.saved
})
.then(({ post_view }) => post_view);
Expand All @@ -262,7 +263,6 @@
return;
}
await client.createPostReport({
auth: jwt,
reason: e.detail,
post_id: postView.post.id
});
Expand Down Expand Up @@ -450,8 +450,6 @@
});
}
const isAdmin = $siteMeta.my_user?.local_user_view.person.admin ?? false;
if (isCommunityModerator || isAdmin) {
const warn = isCommunityModerator ? $showModlogWarningModerated : $showModlogWarning,
modlogBase = `/${$profile.instance}/modlog${warn ? '' : '/view'}`;
Expand Down Expand Up @@ -482,7 +480,6 @@
return;
}
await client.blockPerson({
auth: jwt,
person_id: postView.creator.id,
block: true
});
Expand All @@ -500,7 +497,6 @@
return;
}
await client.blockCommunity({
auth: jwt,
community_id: postView.community.id,
block: true
});
Expand Down
Loading

0 comments on commit 07e9ff9

Please sign in to comment.