Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

入室メッセージ #14

Merged
merged 4 commits into from
Jun 17, 2023
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
55 changes: 28 additions & 27 deletions components/MessagesList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,38 @@ export interface Props {
messages: Message[];
}

export default function MessageList(props: Props) {

export default function MessageList(props: Props) {
return (
<div>
{props.messages.map((message, index) => {
const dateText = dateFns.format(message.date, "HH:mm:ss yyyy/MM/dd");
const MsgTripID = EasyHash(message.date + message.user + message.body); //識別ID ここ消さんでな リプライ用
{
props.messages.map((message, index) => {
const dateText = dateFns.format(message.date, "HH:mm:ss yyyy/MM/dd");

if (DoNotUseWords.includes(message.body)) {
for (let i = 0; i < DoNotUseWords.length; i++) {
message.body = message.body.replaceAll(DoNotUseWords[i], SysMsg);
if(message.type === "enter"){
// 誰かが入室
return <div class="text-center bg-slate-500 text-white rounded-lg drop-shadow-lg">
<span class="mx-2">{ dateText }</span>
<span class="mx-2">@{ message.user }</span>
<span class="mx-2">が入室しました。</span>
</div>
}
}


return (
<div
key={index}
msg-trip={MsgTripID}
className="block w-full my-4 p-2 bg-white border border-gray-200 rounded-lg shadow dark:bg-gray-800 dark:border-gray-700 dark:hover:bg-gray-700"
>
<div className="mb-2 tracking-tight text-gray-600 dark:text-white flex gap-4">
<span>{message.user}</span>
<span>{dateText}</span>

const MsgTripID = EasyHash(message.date + message.user + message.body); //識別ID ここ消さんでな リプライ用
return <div
key={index}
msg-trip={MsgTripID}
className="block w-full my-4 p-2 bg-white border border-gray-200 rounded-lg shadow dark:bg-gray-800 dark:border-gray-700 dark:hover:bg-gray-700"
>
<div className="mb-2 tracking-tight text-gray-600 dark:text-white flex gap-4">
<span>{message.user}</span>
<span>{dateText}</span>
</div>
<p className="mb-2 font-bold tracking-tight text-gray-800 dark:text-white break-words">
{message.body}
</p>
</div>
<p className="mb-2 font-bold tracking-tight text-gray-800 dark:text-white break-words">
{message.body}
</p>
</div>
);
})}
})
}
</div>
);
}
}
14 changes: 7 additions & 7 deletions islands/Room.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,13 @@ export default class extends Component {
}

socket.on("message", (data) => {
this.addMessage({
user: "@" + "Anonymous",
type: "text",
body: data.body,
room: data.room,
date: new Date(),
});
const safeData = {}
safeData.user = "@" + "Anonymous"
safeData.type = ["text","enter"].includes(data.type) ? data.type : "text"
safeData.body = data.body ? data.body : ""
safeData.room = data.room
safeData.date = new Date()
this.addMessage(safeData);
});

socket.emit("message", {
Expand Down