Skip to content

Commit

Permalink
feat: auto switch model when using use message actions in shared co…
Browse files Browse the repository at this point in the history
…nversation (#116)
  • Loading branch information
zmh-program committed Mar 13, 2024
1 parent 8dde7c4 commit f67aded
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 16 deletions.
1 change: 1 addition & 0 deletions app/src/api/sharing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export type ViewData = {
name: string;
username: string;
time: string;
model?: string;
messages: Message[];
};

Expand Down
26 changes: 13 additions & 13 deletions app/src/dialogs/ShareManagementDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,20 +131,20 @@ function ShareManagementDialog() {
<Dialog open={open} onOpenChange={(open) => dispatch(setDialog(open))}>
<DialogContent>
<DialogHeader>
<DialogTitle className={`mb-4`}>{t("share.manage")}</DialogTitle>
{data.length > 0 ? (
<ScrollArea className={`max-h-[60vh]`}>
<DialogDescription className={`share-table`}>
<ShareTable data={data} />
</DialogDescription>
</ScrollArea>
) : (
<DialogDescription>
<p className={`text-center select-none mt-6 mb-2`}>
{t("conversation.empty")}
</p>
<DialogTitle className={`mb-4`}>{t("share.manage")}</DialogTitle>
{data.length > 0 ? (
<ScrollArea className={`max-h-[60vh]`}>
<DialogDescription className={`share-table`}>
<ShareTable data={data} />
</DialogDescription>
)}
</ScrollArea>
) : (
<DialogDescription>
<p className={`text-center select-none mt-6 mb-2`}>
{t("conversation.empty")}
</p>
</DialogDescription>
)}
</DialogHeader>
<DialogFooter>
<Button variant={`outline`} onClick={() => dispatch(closeDialog())}>
Expand Down
7 changes: 6 additions & 1 deletion app/src/routes/Sharing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function SharingForm({ data }: SharingFormProps) {
const { t } = useTranslation();
const { toast } = useToast();
const mobile = useMobile();
const { mask: setMask } = useConversationActions();
const { mask: setMask, selected: setModel } = useConversationActions();
const [maximized, setMaximized] = useState(false);
const container = useRef<HTMLDivElement>(null);
const date = new Date(data.time);
Expand Down Expand Up @@ -163,6 +163,11 @@ function SharingForm({ data }: SharingFormProps) {
name: data.name,
context: message,
});
setModel(data?.model);

console.debug(
`[sharing] switch to conversation (name: ${data.name}, model: ${data.model})`,
);
await router.navigate("/");
}}
>
Expand Down
8 changes: 8 additions & 0 deletions app/src/store/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,8 @@ export function useConversationActions() {
const current = useSelector(selectCurrent);
const mask = useSelector(selectMaskItem);

const supportModels = useSelector(selectSupportModels);

return {
toggle: async (id: number) => {
const conversation = conversations[id];
Expand Down Expand Up @@ -478,6 +480,12 @@ export function useConversationActions() {
dispatch(setCurrent(-1));
}
},
selected: (model?: string) => {
if (!model || model === "") return;
if (!supportModels.map((item) => item.id).includes(model)) return;

dispatch(setModel(model));
},
};
}

Expand Down
5 changes: 3 additions & 2 deletions manager/conversation/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type SharedForm struct {
Username string `json:"username"`
Name string `json:"name"`
Messages []globals.Message `json:"messages"`
Model string `json:"model"`
Time time.Time `json:"time"`
}

Expand Down Expand Up @@ -138,12 +139,12 @@ func GetSharedConversation(db *sql.DB, hash string) (*SharedForm, error) {
)
if err := globals.QueryRowDb(db, `
SELECT auth.username, sharing.refs, sharing.updated_at, conversation.conversation_name,
sharing.user_id, sharing.conversation_id
sharing.user_id, sharing.conversation_id, conversation.model
FROM sharing
INNER JOIN auth ON auth.id = sharing.user_id
INNER JOIN conversation ON conversation.conversation_id = sharing.conversation_id AND conversation.user_id = sharing.user_id
WHERE sharing.hash = ?
`, hash).Scan(&shared.Username, &ref, &updated, &shared.Name, &uid, &cid); err != nil {
`, hash).Scan(&shared.Username, &ref, &updated, &shared.Name, &uid, &cid, &shared.Model); err != nil {
return nil, err
}

Expand Down

0 comments on commit f67aded

Please sign in to comment.