Skip to content

Commit

Permalink
fix patches for mediaTweaks and allActivities
Browse files Browse the repository at this point in the history
  • Loading branch information
Cynosphere committed Dec 13, 2024
1 parent f3400f2 commit 706e00a
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/allActivities/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ExtensionWebpackModule, Patch } from "@moonlight-mod/types";
export const patches: Patch[] = [
// Replace the existing activity/stream wrapper component with one we can add to easier
{
find: /user:.,currentUser:.,stream:.,className:.+?user:.,currentUser:.,activity:.,className:/,
find: '"UserProfileFeaturedActivity"',
replace: {
match: /:function\(\){return (.)}/,
replacement: ':function(){return require("allActivities_activities").default}'
Expand Down
46 changes: 44 additions & 2 deletions src/allActivities/webpackModules/activities.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,85 @@ const UserProfileActivityCardWrapper = spacepack.findByCode('location:"' + 'User
const UserProfileStreamActivityCard = spacepack.findByCode('surface:"' + 'user-profile-stream-activity-card",')[0]
.exports.Z;
const useUserProfileActivity = spacepack.findByCode('("use-user-' + 'profile-activity")')[0].exports.Z;
const useUserActivityFeedRecent = spacepack.findByCode(
'"application_id"in',
".extra.application_id",
".GAME_PROFILE_FEED"
)[0].exports.Z;
const ActivityFeedTimeUtils = spacepack.findByCode(".TRENDING_CONTENT))||void 0===")[0].exports;
const ActivityFeed48h = spacepack.findFunctionByStrings(ActivityFeedTimeUtils, ".Millis.HOUR<48");
const UserProfileRecentActivityCard = spacepack.findByCode("{recentActivityEnabled:", ".bot?(0,")[0].exports.Z;

type UserPopoutActivitiesProps = {
user: any; // no discord common types :(
currentUser: any;
profileGuildId: string;
className: string;
onClose: () => void;
};

export default function UserPopoutActivities({ user, currentUser, className, onClose }: UserPopoutActivitiesProps) {
const { live, stream } = useUserProfileActivity(user.id);
const LOCATION = "UserProfileFeaturedActivity";

export default function UserPopoutActivities({
user,
currentUser,
profileGuildId,
className,
onClose
}: UserPopoutActivitiesProps) {
const { live, recent, stream } = useUserProfileActivity(user.id);
const [firstActivity] = live;

const isCurrentUser = user.id === currentUser.id;

const recentFeedEntry = useUserActivityFeedRecent(user.id, LOCATION);
const feedEntry = React.useMemo(
() => (isCurrentUser ? recent.find(ActivityFeed48h) : recentFeedEntry),
[isCurrentUser, recent, recentFeedEntry]
);

const activities = [...live];
activities.shift();

return [
null != stream ? (
<UserProfileStreamActivityCard
location={LOCATION}
user={user}
currentUser={currentUser}
stream={stream}
profileGuildId={profileGuildId}
className={className}
onClose={onClose}
/>
) : null != firstActivity ? (
<UserProfileActivityCardWrapper
location={LOCATION}
user={user}
currentUser={currentUser}
activity={firstActivity}
profileGuildId={profileGuildId}
className={className}
onClose={onClose}
/>
) : feedEntry != null ? (
<UserProfileRecentActivityCard
location={LOCATION}
user={user}
currentUser={currentUser}
entry={feedEntry}
profileGuildId={profileGuildId}
className={className}
onClose={onClose}
/>
) : null,
...activities.map((activity: any) => (
<UserProfileActivityCardWrapper
location={LOCATION}
user={user}
currentUser={currentUser}
activity={activity}
profileGuildId={profileGuildId}
className={className}
onClose={onClose}
/>
Expand Down
6 changes: 3 additions & 3 deletions src/mediaTweaks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const patches: Patch[] = [
{
find: ".TOGGLE_GIF_PICKER,handler:",
replace: {
match: /.{1,2}===.\..\.CREATE_FORUM_POST/,
match: /[A-Za-z_$][\w$]*===[A-Za-z_$][\w$]*\.[A-Za-z_$][\w$]*\.CREATE_FORUM_POST/,
replacement: (orig: string) => `(moonlight.getConfigOption("mediaTweaks","noGifAutosend")??true?true:${orig})`
}
},
Expand All @@ -34,9 +34,9 @@ export const patches: Patch[] = [
{
find: 'location:"MessageAccessories"',
replace: {
match: /=.\.length>1\?(\(0,.\..{1,2}\))\((.),({shouldRedactExplicitContent:.,shouldHideMediaOptions:.}),(.)\):{}/,
match: /=(\(0,.\..{1,2}\))\((.),({shouldRedactExplicitContent:.,shouldHideMediaOptions:.}),(.)\),/,
replacement: (_, createCarousel, attachments, props, analytics) =>
`=${attachments}.length>1?${createCarousel}((moonlight.getConfigOption("mediaTweaks","inlineMosaicPlayback")??true)?${attachments}.filter(x=>x.type!="VIDEO"):${attachments},${props},${analytics}):{}`
`=${createCarousel}((moonlight.getConfigOption("mediaTweaks","inlineMosaicPlayback")??true)?${attachments}.filter(x=>x.type!="VIDEO"):${attachments},${props},${analytics}),`
}
},

Expand Down

0 comments on commit 706e00a

Please sign in to comment.