Skip to content

Commit

Permalink
Refactor code to use 'timestamp' instead of 'time' in ChatTalkContent
Browse files Browse the repository at this point in the history
  • Loading branch information
tako0614 committed Jul 17, 2024
1 parent 476ee1a commit 6c24cb4
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 14 deletions.
8 changes: 1 addition & 7 deletions components/OtherMessage.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
const ChatOtherMessage = (
{ time, message, sender, senderNickName, isPrimary }: {
time: string;
message: string;
sender: string;
senderNickName: string;
isPrimary: boolean;
},
{ time, message, sender, senderNickName, isPrimary }: any,
) => {
const isPrimaryClass = isPrimary ? "c-talk-chat other primary" : "c-talk-chat other subsequent";

Expand Down
2 changes: 2 additions & 0 deletions components/chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ function createAppState(obj: {
const setIsValidInput = signal(false);
const roomType = signal("");
const friendid = signal(obj.friendid || "");
const ChatUserInfo = signal({});
return {
isChoiceUser: isChoiceUser,
ws: ws,
Expand All @@ -39,6 +40,7 @@ function createAppState(obj: {
isValidInput: setIsValidInput,
roomType: roomType,
friendid: friendid,
ChatUserInfo: ChatUserInfo,
};
}
function chat(props: { page: any; userName: string; friendid?: string }) {
Expand Down
2 changes: 2 additions & 0 deletions fresh.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import * as $api_v2_client_talks_group_text from "./routes/api/v2/client/talks/g
import * as $api_v2_client_talks_group_update from "./routes/api/v2/client/talks/group/update.ts";
import * as $api_v2_client_talks_group_video from "./routes/api/v2/client/talks/group/video.ts";
import * as $api_v2_client_talks_read from "./routes/api/v2/client/talks/read.ts";
import * as $api_v2_client_talks_roomsInfo from "./routes/api/v2/client/talks/roomsInfo.ts";
import * as $api_v2_client_unblock_server from "./routes/api/v2/client/unblock/server.ts";
import * as $api_v2_client_unblock_user from "./routes/api/v2/client/unblock/user.ts";
import * as $api_v2_client_users_uuid_icon from "./routes/api/v2/client/users/[uuid]/icon.ts";
Expand Down Expand Up @@ -161,6 +162,7 @@ const manifest = {
"./routes/api/v2/client/talks/group/update.ts": $api_v2_client_talks_group_update,
"./routes/api/v2/client/talks/group/video.ts": $api_v2_client_talks_group_video,
"./routes/api/v2/client/talks/read.ts": $api_v2_client_talks_read,
"./routes/api/v2/client/talks/roomsInfo.ts": $api_v2_client_talks_roomsInfo,
"./routes/api/v2/client/unblock/server.ts": $api_v2_client_unblock_server,
"./routes/api/v2/client/unblock/user.ts": $api_v2_client_unblock_user,
"./routes/api/v2/client/users/[uuid]/icon.ts": $api_v2_client_users_uuid_icon,
Expand Down
15 changes: 8 additions & 7 deletions islands/ChatTalkContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ function ChatTalkMain({ state }: { state: AppStateType }) {
if (OtherPrimary) {
OtherPrimary = false;
SendPrimary = true;
console.log(data);
return (
<>
{isEncodeDate && (
Expand All @@ -93,14 +94,13 @@ function ChatTalkMain({ state }: { state: AppStateType }) {
<ChatOtherMessage
time={data.time}
message={data.message}
sender={data.sender}
senderNickName={data.senderNickName}
name={data.userName}
nickName={data.nickName}
isPrimary={true}
/>
</>
);
}

// 前のメッセージから1分以上経過のものはprimaryに
const prevDate = new Date(state.talkData.value[index - 1].time);
if (date.getTime() - prevDate.getTime() > 60000) {
Expand All @@ -114,8 +114,8 @@ function ChatTalkMain({ state }: { state: AppStateType }) {
<ChatOtherMessage
time={data.time}
message={data.message}
sender={data.sender}
senderNickName={data.senderNickName}
name={data.nickName}
nickName={data.nickName}
isPrimary={true}
/>
</>
Expand All @@ -131,8 +131,9 @@ function ChatTalkMain({ state }: { state: AppStateType }) {
<ChatOtherMessage
time={data.time}
message={data.message}
sender={data.sender}
senderNickName={data.senderNickName}
name={data.nickName}
userName={data.userName}
nickName={data.nickName}
isPrimary={false}
/>
</>
Expand Down
2 changes: 2 additions & 0 deletions routes/api/v2/client/talks/friend/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ export const handler = {
return {
messageid: message.messageid,
userName: CacheUser.userName,
nickName: CacheUser.nickName,
message: message.message,
timestamp: message.timestamp,
type: message.messageType,
Expand Down Expand Up @@ -142,6 +143,7 @@ export const handler = {
return {
messageid: message.messageid,
userName: userInfo?.userName,
nickName: userInfo?.nickName,
message: message.message,
timestamp: message.timestamp,
type: message.messageType,
Expand Down
Empty file.
9 changes: 9 additions & 0 deletions util/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ export interface AppStateType {
isValidInput: { value: boolean };
roomType: { value: string };
friendid: { value: string };
ChatUserInfo: {
value: {
[key: string]: {
userName: string;
nickName: string;
readedMessage: string;
};
};
};
}
export interface MessageTypes {
type: string;
Expand Down

0 comments on commit 6c24cb4

Please sign in to comment.