Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ In a PR that changes something users will notice, add a line under **Unreleased*

- CustomAppIcon's System appearance follows macOS light and dark mode instead of Slack's theme.
- UserPronouns shows pronouns on channel messages again.
- LocalTime shows local times on channel messages again.

## Build 162

Expand Down
44 changes: 25 additions & 19 deletions src/plugins/LocalTime/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,25 +118,31 @@ export default class LocalTime extends SlickPlugin<typeof meta.settings> {
}

private patchMessages() {
this.api.patchComponent<BroadcastPreambleProps>('BaseBroadcastPreamble', (Original) => (props) => {
if (!isPerson(props.msg)) return <Original {...props} />;

const children = React.Children.toArray(props.children);
const timestamp = children.findIndex(isTimestamp);
const anchor = timestamp === -1 ? children.findIndex(isSender) : timestamp;
if (anchor === -1) return <Original {...props} />;

children.splice(
anchor + 1,
0,
<this.Clock
key="slick-local-time"
userId={props.msg.user}
className={`slick-local-time${timestamp !== -1 ? ' slick-local-time--bulleted' : ''}`}
/>,
);
return <Original {...props}>{children}</Original>;
});
// Slack flips between these two names across builds.
for (const name of ['BroadcastPreamble', 'BaseBroadcastPreamble']) {
this.api.patchComponent<BroadcastPreambleProps>(name, (Original) => (props) => {
if (!isPerson(props.msg)) return <Original {...props} />;

const children = React.Children.toArray(props.children);
if (children.some((child) => React.isValidElement(child) && child.type === this.Clock)) {
return <Original {...props} />;
}
const timestamp = children.findIndex(isTimestamp);
const anchor = timestamp === -1 ? children.findIndex(isSender) : timestamp;
if (anchor === -1) return <Original {...props} />;

children.splice(
anchor + 1,
0,
<this.Clock
key="slick-local-time"
userId={props.msg.user}
className={`slick-local-time${timestamp !== -1 ? ' slick-local-time--bulleted' : ''}`}
/>,
);
return <Original {...props}>{children}</Original>;
});
}

this.api.patchComponent<ThreadHeaderProps>('ThreadSenderAndTimestampGeneric', (Original) => (props) => {
if (props.adjacent || props.visible === false || !isPerson(props.msg)) return <Original {...props} />;
Expand Down
Loading