);
}
- })
- : null;
+ }
+ }
- const unconfirmedMessages = chat.unconfirmedMessages.map(m => {
+ for (let i = 0; i < chat.unconfirmedMessages.length; i++) {
+ const message = chat.unconfirmedMessages[i];
const props = {
- message: m.text,
- timestamp: m.timestamp,
+ message: message.text,
+ date: timestamp.asDate(message.timestamp),
confirmed: false
};
- return ;
- });
+ children.push();
+ }
return (
- {confirmedMessages}
- {unconfirmedMessages}
+ {children}
);
}
diff --git a/src/website/public/components/messages/DayChangeMarker.tsx b/src/website/public/components/messages/DayChangeMarker.tsx
new file mode 100644
index 0000000000..354068704b
--- /dev/null
+++ b/src/website/public/components/messages/DayChangeMarker.tsx
@@ -0,0 +1,26 @@
+import React from "react";
+
+export default DayChangeMarker;
+
+interface Props {
+ date: Date
+}
+
+function DayChangeMarker(props : Props) {
+ const dayOfWeek = props.date.toLocaleDateString("en", { weekday: "long" });
+ const dayOfMonth = props.date.getDate();
+ const month = props.date.toLocaleDateString("en", { month: "long" });
+ const ordinal = getOrdinal(dayOfMonth);
+ const year = props.date.getFullYear();
+
+ const text = `-- ${dayOfWeek} ${dayOfMonth}${ordinal} ${month} ${year} --`;
+
+ return (
+ {text}
+ );
+}
+
+function getOrdinal(n: number) : string {
+ // Taken from https://stackoverflow.com/a/39466341
+ return [,"st","nd","rd"][n/10%10^1&&n%10]||"th";
+}
diff --git a/src/website/public/components/messages/DirectMessageSentByThem.tsx b/src/website/public/components/messages/DirectMessageSentByThem.tsx
index 1813a657dd..6b62f311a9 100644
--- a/src/website/public/components/messages/DirectMessageSentByThem.tsx
+++ b/src/website/public/components/messages/DirectMessageSentByThem.tsx
@@ -1,12 +1,10 @@
import React from "react";
-import { Timestamp } from "../../model/common";
-
export default DirectMessageSentByThem;
-interface Props {
+type Props = {
message: string,
- timestamp: Timestamp
+ date: Date
}
function DirectMessageSentByThem(props : Props) {
diff --git a/src/website/public/components/messages/GroupMessageSentByElse.tsx b/src/website/public/components/messages/GroupMessageSentByElse.tsx
index 68a1b115e0..1611fabe5a 100644
--- a/src/website/public/components/messages/GroupMessageSentByElse.tsx
+++ b/src/website/public/components/messages/GroupMessageSentByElse.tsx
@@ -1,10 +1,8 @@
import React from "react";
-import { Timestamp } from "../../model/common";
-
interface Props {
message: string,
- timestamp: Timestamp,
+ date: Date,
senderUsername: string
}
diff --git a/src/website/public/components/messages/MessageSentByMe.tsx b/src/website/public/components/messages/MessageSentByMe.tsx
index 2eb3d51d5c..96587dbeed 100644
--- a/src/website/public/components/messages/MessageSentByMe.tsx
+++ b/src/website/public/components/messages/MessageSentByMe.tsx
@@ -1,12 +1,10 @@
import React from "react";
-import { Timestamp } from "../../model/common";
-
export default MessageSentByMe;
interface Props {
message: string,
- timestamp: Timestamp,
+ date: Date,
confirmed: boolean
}
diff --git a/src/website/public/utils/timestamp.ts b/src/website/public/utils/timestamp.ts
index ad808b7147..9b31db7f64 100644
--- a/src/website/public/utils/timestamp.ts
+++ b/src/website/public/utils/timestamp.ts
@@ -3,3 +3,7 @@ import { Timestamp } from "../model/common";
export function getCurrent() : Timestamp {
return Date.now();
}
+
+export function asDate(timestamp: Timestamp) : Date {
+ return new Date(timestamp);
+}