Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Option to view profile pictures in comments #1125

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 22 additions & 2 deletions src/features/labels/links/PersonLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@ import { Person } from "lemmy-js-client";
import Handle from "../Handle";
import { StyledLink, hideCss } from "./shared";
import { useAppSelector } from "../../../store";
import { OInstanceUrlDisplayMode } from "../../../services/db";
import {
OInstanceUrlDisplayMode,
OUserAvatarDisplayMode,
} from "../../../services/db";
import AgeBadge from "./AgeBadge";
import { useContext } from "react";
import { ShareImageContext } from "../../share/asImage/ShareAsImage";
import ItemIcon from "../img/ItemIcon";

const Prefix = styled.span`
font-weight: normal;
Expand Down Expand Up @@ -70,6 +74,11 @@ export default function PersonLink({
(state) => state.settings.appearance.general.userInstanceUrlDisplay,
) === OInstanceUrlDisplayMode.WhenRemote;

const userAvatarDisplay =
useAppSelector(
(state) => state.settings.appearance.general.userAvatarDisplay,
) === OUserAvatarDisplayMode.InComments;

if (isAdmin) color = "var(--ion-color-danger)";
else if (distinguished) color = "var(--ion-color-success)";
else if (opId && person.id === opId) color = "var(--ion-color-primary-fixed)";
Expand All @@ -86,7 +95,18 @@ export default function PersonLink({
<>
<Prefix>{prefix}</Prefix>{" "}
</>
) : undefined}
) : (
userAvatarDisplay && (
<ItemIcon
item={person}
size={24}
css={css`
margin-right: 0.4rem;
vertical-align: middle;
`}
/>
)
)}
<Handle
item={person}
showInstanceWhenRemote={showInstanceWhenRemote || forceInstanceUrl}
Expand Down
32 changes: 32 additions & 0 deletions src/features/settings/appearance/posts/AvatarDisplay.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { setUserAvatarDisplay } from "../../settingsSlice";
import { OUserAvatarDisplayMode } from "../../../../services/db";
import { useAppDispatch, useAppSelector } from "../../../../store";
import { IonToggle } from "@ionic/react";
import { InsetIonItem } from "../../shared/formatting";

export default function AvatarDisplay() {
const dispatch = useAppDispatch();

const userAvatarDisplay = useAppSelector(
(state) => state.settings.appearance.general.userAvatarDisplay,
);

return (
<InsetIonItem>
<IonToggle
checked={userAvatarDisplay === OUserAvatarDisplayMode.InComments}
onIonChange={(e) =>
dispatch(
setUserAvatarDisplay(
e.detail.checked
? OUserAvatarDisplayMode.InComments
: OUserAvatarDisplayMode.Never,
),
)
}
>
Show avatars in comments
</IonToggle>
</InsetIonItem>
);
}
2 changes: 2 additions & 0 deletions src/features/settings/appearance/posts/Posts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { IonLabel, IonList } from "@ionic/react";
import { ListHeader } from "../../shared/formatting";
import BlurNsfw from "./BlurNsfw";
import PostSize from "./PostSize";
import AvatarDisplay from "./AvatarDisplay";

export default function Posts() {
return (
Expand All @@ -12,6 +13,7 @@ export default function Posts() {
<IonList inset>
<PostSize />
<BlurNsfw />
<AvatarDisplay />
</IonList>
</>
);
Expand Down
13 changes: 13 additions & 0 deletions src/features/settings/settingsSlice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ import {
ODefaultFeedType,
TapToCollapseType,
OTapToCollapseType,
UserAvatarDisplayMode,
OUserAvatarDisplayMode,
} from "../../services/db";
import { get, set } from "./storage";
import { Mode } from "@ionic/core";
Expand All @@ -59,6 +61,7 @@ interface SettingsState {
};
general: {
userInstanceUrlDisplay: InstanceUrlDisplayMode;
userAvatarDisplay: UserAvatarDisplayMode;
profileLabel: ProfileLabelType;
};
posts: {
Expand Down Expand Up @@ -136,6 +139,7 @@ const initialState: SettingsState = {
},
general: {
userInstanceUrlDisplay: OInstanceUrlDisplayMode.Never,
userAvatarDisplay: OUserAvatarDisplayMode.Never,
profileLabel: OProfileLabelType.Instance,
},
posts: {
Expand Down Expand Up @@ -248,6 +252,10 @@ export const appearanceSlice = createSlice({
state.appearance.general.userInstanceUrlDisplay = action.payload;
db.setSetting("user_instance_url_display", action.payload);
},
setUserAvatarDisplay(state, action: PayloadAction<UserAvatarDisplayMode>) {
state.appearance.general.userAvatarDisplay = action.payload;
db.setSetting("user_avatar_display", action.payload);
},
setProfileLabel(state, action: PayloadAction<ProfileLabelType>) {
state.appearance.general.profileLabel = action.payload;
db.setSetting("profile_label", action.payload);
Expand Down Expand Up @@ -509,6 +517,7 @@ export const fetchSettingsFromDatabase = createAsyncThunk<SettingsState>(
const user_instance_url_display = await db.getSetting(
"user_instance_url_display",
);
const user_avatar_display = await db.getSetting("user_avatar_display");
const profile_label = await db.getSetting("profile_label");
const post_appearance_type = await db.getSetting("post_appearance_type");
const blur_nsfw = await db.getSetting("blur_nsfw");
Expand Down Expand Up @@ -560,6 +569,9 @@ export const fetchSettingsFromDatabase = createAsyncThunk<SettingsState>(
userInstanceUrlDisplay:
user_instance_url_display ??
initialState.appearance.general.userInstanceUrlDisplay,
userAvatarDisplay:
user_avatar_display ??
initialState.appearance.general.userAvatarDisplay,
profileLabel:
profile_label ?? initialState.appearance.general.profileLabel,
},
Expand Down Expand Up @@ -660,6 +672,7 @@ export const {
setFontSizeMultiplier,
setUseSystemFontSize,
setUserInstanceUrlDisplay,
setUserAvatarDisplay,
setProfileLabel,
setCommentsCollapsed,
setTapToCollapse,
Expand Down
9 changes: 9 additions & 0 deletions src/services/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ export const OInstanceUrlDisplayMode = {
export type InstanceUrlDisplayMode =
(typeof OInstanceUrlDisplayMode)[keyof typeof OInstanceUrlDisplayMode];

export const OUserAvatarDisplayMode = {
InComments: "in-comments",
Never: "never",
} as const;

export type UserAvatarDisplayMode =
(typeof OUserAvatarDisplayMode)[keyof typeof OUserAvatarDisplayMode];

export const OVoteDisplayMode = {
/**
* Show upvotes and downvotes separately
Expand Down Expand Up @@ -250,6 +258,7 @@ export type SwipeActions = Record<SwipeDirection, SwipeAction>;
export type SettingValueTypes = {
collapse_comment_threads: CommentThreadCollapse;
user_instance_url_display: InstanceUrlDisplayMode;
user_avatar_display: UserAvatarDisplayMode;
vote_display_mode: VoteDisplayMode;
profile_label: ProfileLabelType;
post_appearance_type: PostAppearanceType;
Expand Down