Skip to content

Commit f7ac627

Browse files
committed
fix(regression): ensure compact-mode and message-body-only work well together
1 parent db9df40 commit f7ac627

File tree

2 files changed

+23
-16
lines changed

2 files changed

+23
-16
lines changed

packages/core/demo/index.html

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -170,27 +170,28 @@ <h3 class="title">Compact mode</h3>
170170
<h3 class="title">With subsequent messages</h3>
171171
<discord-messages>
172172
<discord-message profile="favna">I can send multiple messages with my avatar showing only once</discord-message>
173-
<discord-message profile="favna" message-body-only message-body-only-time="12:39"
173+
<discord-message profile="favna" message-body-only timestamp="12:39"
174174
>That's how Discord handles multiple messages from the same author as well</discord-message
175175
>
176-
<discord-message profile="favna" message-body-only
176+
<discord-message profile="favna" message-body-only timestamp="12:39"
177177
>Just keep in mind that Discord does some funky stuff like with time between messages, this library doesn't automatically
178178
change what is displayed!</discord-message
179179
>
180180
</discord-messages>
181181

182-
<h3 class="title">With subsequent messages in compact mode</h3>
182+
<h3 class="title">With subsequent messages and compact mode</h3>
183183
<discord-messages compact-mode>
184-
<discord-message profile="favna">I can send multiple messages with my avatar showing only once</discord-message>
185-
<discord-message profile="favna" message-body-only message-body-only-time="12:39"
184+
<discord-message profile="favna" twenty-four timestamp="12:38"
185+
>I can send multiple messages with my avatar showing only once</discord-message
186+
>
187+
<discord-message profile="favna" message-body-only timestamp="12:39"
186188
>That's how Discord handles multiple messages from the same author as well</discord-message
187189
>
188-
<discord-message profile="favna" message-body-only
190+
<discord-message profile="favna" message-body-only timestamp="12:40"
189191
>Just keep in mind that Discord does some funky stuff like with time between messages, this library doesn't automatically
190192
change what is displayed!</discord-message
191193
>
192194
</discord-messages>
193-
194195
<h3 class="title">Markdown Styling</h3>
195196
<discord-messages>
196197
<discord-message profile="favna">

packages/core/src/components/discord-message/DiscordMessage.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,8 @@ export class DiscordMessage extends LitElement implements DiscordMessageProps, L
335335

336336
/**
337337
* The timestamp to use for the message date.
338+
*
339+
* if {@link DiscordMessage.messageBodyOnly} is `true`, this will be shown in the gutter before the message on hover.
338340
*/
339341
@property({
340342
type: String,
@@ -343,12 +345,6 @@ export class DiscordMessage extends LitElement implements DiscordMessageProps, L
343345
})
344346
public accessor timestamp: DiscordTimestamp = new Date();
345347

346-
/**
347-
* The timestamp to use for the message time if {@link DiscordMessage.messageBodyOnly} is `true`.
348-
*/
349-
@property({ type: String, attribute: 'message-body-only-time' })
350-
public accessor messageBodyOnlyTime: DiscordTimestamp | null = null;
351-
352348
/**
353349
* Whether to use 24-hour format for the timestamp.
354350
*/
@@ -386,8 +382,8 @@ export class DiscordMessage extends LitElement implements DiscordMessageProps, L
386382
}
387383

388384
protected handleMessageEnter() {
389-
if (this.messageBodyOnly && this.messageBodyOnlyTimeRef.value && this.messageBodyOnlyTime) {
390-
const computedTimestamp = handleTimestamp(this.messageBodyOnlyTime, true, this.twentyFour);
385+
if (this.messageBodyOnly && this.messageBodyOnlyTimeRef.value) {
386+
const computedTimestamp = handleTimestamp(this.timestamp, true, this.twentyFour);
391387
this.messageBodyOnlyTimeRef.value.textContent = computedTimestamp ?? '';
392388
}
393389
}
@@ -419,7 +415,7 @@ export class DiscordMessage extends LitElement implements DiscordMessageProps, L
419415
<slot name="reply"></slot>
420416
<div class="discord-message-inner" @mouseenter=${this.handleMessageEnter} @mouseleave=${this.handleMessageLeave}>
421417
${when(
422-
this.compactMode,
418+
this.compactMode && !this.messageBodyOnly,
423419
() => html`<time datetime="${ifDefined(computedTimestamp)}" class="discord-message-timestamp">${computedTimestamp}</time>`,
424420
() => null
425421
)}
@@ -433,6 +429,16 @@ export class DiscordMessage extends LitElement implements DiscordMessageProps, L
433429
></time>`,
434430
() => null
435431
)}
432+
${when(
433+
this.compactMode && this.messageBodyOnly,
434+
() =>
435+
html`<time
436+
${ref(this.messageBodyOnlyTimeRef)}
437+
datetime="${ifDefined(computedTimestamp)}"
438+
class="discord-message-timestamp"
439+
></time>`,
440+
() => null
441+
)}
436442
${when(
437443
this.compactMode || this.messageBodyOnly,
438444
() => null,

0 commit comments

Comments
 (0)