mirror of
https://github.com/owncast/owncast.git
synced 2024-11-29 03:29:03 +03:00
refactoring
This commit is contained in:
parent
d27d4a798f
commit
2abde9186c
2 changed files with 19 additions and 19 deletions
|
@ -1,25 +1,13 @@
|
|||
import {Component, h} from 'https://unpkg.com/preact?module';
|
||||
import { h, Component } from 'https://unpkg.com/preact?module';
|
||||
import htm from 'https://unpkg.com/htm?module';
|
||||
const html = htm.bind(h);
|
||||
|
||||
import { messageBubbleColorForString } from '../../utils/user-colors.js';
|
||||
import {formatMessageText} from '../../utils/chat.js';
|
||||
import { formatMessageText, formatTimestamp } from '../../utils/chat.js';
|
||||
import { generateAvatar } from '../../utils/helpers.js';
|
||||
import { SOCKET_MESSAGE_TYPES } from '../../utils/websocket.js';
|
||||
|
||||
const html = htm.bind(h);
|
||||
|
||||
export default class Message extends Component {
|
||||
formatTimestamp(sentAt) {
|
||||
sentAt = new Date(sentAt);
|
||||
|
||||
let diffInDays = ((new Date()) - sentAt) / (24 * 3600 * 1000);
|
||||
if (diffInDays >= -1) {
|
||||
return `${sentAt.toLocaleDateString('en-US', {dateStyle: 'medium'})} at ` +
|
||||
sentAt.toLocaleTimeString();
|
||||
}
|
||||
|
||||
return sentAt.toLocaleTimeString();
|
||||
}
|
||||
|
||||
render(props) {
|
||||
const { message, username } = props;
|
||||
const { type } = message;
|
||||
|
@ -47,7 +35,7 @@ export default class Message extends Component {
|
|||
</div>
|
||||
<div
|
||||
class="message-text text-gray-300 font-normal overflow-y-hidden"
|
||||
title=${`Sent at ${this.formatTimestamp(timestamp)}`}
|
||||
title=${`Sent at ${formatTimestamp(timestamp)}`}
|
||||
dangerouslySetInnerHTML=${
|
||||
{ __html: formattedMessage }
|
||||
}
|
||||
|
|
|
@ -278,3 +278,15 @@ export function convertOnPaste( event = { preventDefault() {} }) {
|
|||
document.execCommand('insertText', false, value);
|
||||
}
|
||||
}
|
||||
|
||||
export function formatTimestamp(sentAt) {
|
||||
sentAt = new Date(sentAt);
|
||||
|
||||
let diffInDays = ((new Date()) - sentAt) / (24 * 3600 * 1000);
|
||||
if (diffInDays >= -1) {
|
||||
return `${sentAt.toLocaleDateString('en-US', {dateStyle: 'medium'})} at ` +
|
||||
sentAt.toLocaleTimeString();
|
||||
}
|
||||
|
||||
return sentAt.toLocaleTimeString();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue