chore: fix memo comment inbox

This commit is contained in:
Steven 2024-04-01 00:26:46 +08:00
parent ec35a42fb5
commit b79f626a74
3 changed files with 19 additions and 24 deletions

View file

@ -5,7 +5,6 @@ import (
"fmt"
"time"
"github.com/pkg/errors"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/timestamppb"
@ -90,24 +89,11 @@ func (s *APIV2Service) DeleteInbox(ctx context.Context, request *apiv2pb.DeleteI
return &apiv2pb.DeleteInboxResponse{}, nil
}
func (s *APIV2Service) convertInboxFromStore(ctx context.Context, inbox *store.Inbox) (*apiv2pb.Inbox, error) {
sender, err := s.Store.GetUser(ctx, &store.FindUser{
ID: &inbox.SenderID,
})
if err != nil {
return nil, errors.Wrap(err, "failed to get sender")
}
receiver, err := s.Store.GetUser(ctx, &store.FindUser{
ID: &inbox.ReceiverID,
})
if err != nil {
return nil, errors.Wrap(err, "failed to get receiver")
}
func (s *APIV2Service) convertInboxFromStore(_ context.Context, inbox *store.Inbox) (*apiv2pb.Inbox, error) {
return &apiv2pb.Inbox{
Name: fmt.Sprintf("%s%d", InboxNamePrefix, inbox.ID),
Sender: fmt.Sprintf("%s%d", UserNamePrefix, sender.ID),
Receiver: fmt.Sprintf("%s%d", UserNamePrefix, receiver.ID),
Sender: fmt.Sprintf("%s%d", UserNamePrefix, inbox.SenderID),
Receiver: fmt.Sprintf("%s%d", UserNamePrefix, inbox.ReceiverID),
Status: convertInboxStatusFromStore(inbox.Status),
CreateTime: timestamppb.New(time.Unix(inbox.CreatedTs, 0)),
Type: apiv2pb.Inbox_Type(inbox.Message.Type),

View file

@ -4,9 +4,10 @@ import { useEffect, useState } from "react";
import toast from "react-hot-toast";
import { activityServiceClient } from "@/grpcweb";
import useNavigateTo from "@/hooks/useNavigateTo";
import { MemoNamePrefix, useInboxStore, useMemoStore } from "@/store/v1";
import { MemoNamePrefix, useInboxStore, useMemoStore, useUserStore } from "@/store/v1";
import { Inbox, Inbox_Status } from "@/types/proto/api/v2/inbox_service";
import { Memo } from "@/types/proto/api/v2/memo_service";
import { User } from "@/types/proto/api/v2/user_service";
import { useTranslate } from "@/utils/i18n";
import Icon from "../Icon";
@ -19,7 +20,9 @@ const MemoCommentMessage = ({ inbox }: Props) => {
const navigateTo = useNavigateTo();
const inboxStore = useInboxStore();
const memoStore = useMemoStore();
const userStore = useUserStore();
const [relatedMemo, setRelatedMemo] = useState<Memo | undefined>(undefined);
const [sender, setSender] = useState<User | undefined>(undefined);
useEffect(() => {
if (!inbox.activityId) {
@ -33,11 +36,15 @@ const MemoCommentMessage = ({ inbox }: Props) => {
if (!activity) {
return;
}
if (activity.payload?.memoComment?.relatedMemoId) {
const memo = await memoStore.getOrFetchMemoByName(`${MemoNamePrefix}${activity.payload?.memoComment?.relatedMemoId}`, {
if (activity.payload?.memoComment) {
const memoCommentPayload = activity.payload.memoComment;
const relatedMemoId = memoCommentPayload.relatedMemoId;
const memo = await memoStore.getOrFetchMemoByName(`${MemoNamePrefix}${relatedMemoId}`, {
skipStore: true,
});
setRelatedMemo(memo);
const sender = await userStore.getOrFetchUserByName(inbox.sender);
setSender(sender);
}
})();
}, [inbox.activityId]);
@ -47,7 +54,7 @@ const MemoCommentMessage = ({ inbox }: Props) => {
return;
}
navigateTo(`/m/${relatedMemo.name}`);
navigateTo(`/m/${relatedMemo.uid}`);
if (inbox.status === Inbox_Status.UNREAD) {
handleArchiveMessage(true);
}
@ -104,8 +111,9 @@ const MemoCommentMessage = ({ inbox }: Props) => {
onClick={handleNavigateToMemo}
>
{t("inbox.memo-comment", {
user: inbox.sender,
memo: `memos#${relatedMemo?.name}`,
user: sender?.nickname || sender?.username,
memo: `memos\/${relatedMemo?.uid}`,
interpolation: { escapeValue: false },
})}
</p>
</div>

View file

@ -1,4 +1,5 @@
import { Button, Input } from "@mui/joy";
import { ClientError } from "nice-grpc-web";
import { useState } from "react";
import { toast } from "react-hot-toast";
import { Link } from "react-router-dom";
@ -64,7 +65,7 @@ const SignUp = () => {
}
} catch (error: any) {
console.error(error);
toast.error(error.response.data.message || error.message || t("message.signup-failed"));
toast.error((error as ClientError).details || t("message.signup-failed"));
}
actionBtnLoadingState.setFinish();
};