Skip to content

Commit

Permalink
[pronouns] fix on compact mode (fixes #33) and prioritize guild profi…
Browse files Browse the repository at this point in the history
…les (helps people out in some communities but not others)
  • Loading branch information
yellowsink committed Nov 27, 2024
1 parent 473171a commit bf09523
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 20 deletions.
16 changes: 16 additions & 0 deletions plugins/pronoundb/compactMode.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
$increase: 4rem;

[class*="latin12CompactTimeStamp"] {
/* originally 2.25rem */
width: #{2.25rem + $increase} !important;
--timestamp-width: #{2.25rem + $increase} !important;
}
[class*="latin12CompactTimeStamp"]::before {
/* originally --timestamp-width */
--avatar-size: 2.25rem !important;
}

:root {
/* originally 5rem, increase by the same amount. */
--custom-message-margin-compact-indent: #{5rem + $increase};
}
37 changes: 29 additions & 8 deletions plugins/pronoundb/db.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
import type { FluxStore } from "@uwu/shelter-defs";

const UserProfileStore = shelter.flux.stores.UserProfileStore as FluxStore<{
const UserProfileStore = shelter.flux.storesFlat.UserProfileStore as FluxStore<{
getUserProfile(id: string): { bio: string; pronouns: string } | undefined;
getGuildMemberProfile(
u: string,
g: string,
): { bio: string; pronouns: string } | null;
}>;

const SelectedGuildStore = shelter.flux.storesFlat
.SelectedGuildStore as FluxStore<{
getGuildId(): string;
}>;

const pronouns = {
he: "he/him",
it: "it/its",
she: "she/her",
they: "they/them",
any: "Any pronouns",
other: "Other pronouns",
ask: "Ask me my pronouns",
avoid: "Avoid pronouns, use my name",
any: "Any",
other: "Other",
ask: "Ask me",
avoid: "Use name",
};

const additionalPronouns = [
Expand All @@ -35,11 +44,23 @@ const pronounsToSearch = Object.values(pronouns)
.filter((p) => p.includes("/"))
.sort((a, b) => b.length - a.length);

export const fromStore = (id) => {
export const fromStore = (id: string) => {
const profile = UserProfileStore.getUserProfile(id);
const scoped = UserProfileStore.getGuildMemberProfile(
id,
SelectedGuildStore.getGuildId(),
);
if (!profile) return;
const pronounSource = (profile.pronouns + profile.bio).toLowerCase();
return pronounsToSearch.find((p) => pronounSource.includes(p));

const search = (s: string) =>
s && pronounsToSearch.find((p) => s.includes(p));

return (
search(scoped?.pronouns) ??
search(scoped?.bio) ??
search(profile.pronouns) ??
search(profile.bio)
);
};

const endpoint = "https://pronoundb.org/api/v2/lookup?platform=discord&ids=";
Expand Down
26 changes: 14 additions & 12 deletions plugins/pronoundb/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ const {
observeDom,
util: { getFiber, reactFiberWalker },
ui: { Space },
solid: { Show },
} = shelter;

import { fetchPronouns, fromStore } from "./db.js";

import "./compactMode.scss"; // css modules brrr

// I love async!
const patchedEls = new WeakSet<Element>();

Expand All @@ -31,18 +34,17 @@ async function inject(el) {
pronouns = fromStore(authorId);
}

if (!pronouns) pronouns = "Unspecified";

el.insertAdjacentElement(
"beforebegin",
(
<span>
<Space />
{pronouns}
<Space />
</span>
) as HTMLSpanElement,
);
if (pronouns)
el.insertAdjacentElement(
"beforebegin",
(
<span>
<Space />
{pronouns}
<Space />
</span>
) as HTMLSpanElement,
);
}

function onDispatch() {
Expand Down
5 changes: 5 additions & 0 deletions plugins/pronoundb/lune.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { defineConfig } from "@uwu/lune";

export default defineConfig({
cssModules: true,
});

0 comments on commit bf09523

Please sign in to comment.