Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
Text,
Title,
} from "@vkontakte/vkui";
import { Icon24CheckCircleOutline } from "@vkontakte/icons";
import { Icon24CheckCircleOutline, Icon24Share } from "@vkontakte/icons";

import { GptMessage } from "$/entity/GPT";

Expand All @@ -23,6 +23,7 @@ import classes from "./Message.module.css";
import { Copy } from "$/components/Copy";
import { ChatGptTemplate } from "$/entity/GPT/ChatGptTemplate";
import { appService } from "$/services/AppService";
import { shareService } from "$/services/ShareService";

interface IProps {
chatGpt: ChatGptTemplate;
Expand All @@ -45,6 +46,15 @@ function Message({ chatGpt, message }: IProps) {
message.toggleSelected();
};

const onForwardMessage = (e: any) => {
e.stopPropagation();
const senderName = message.role === "assistant"
? appService.getGPTName()
: vkUser?.first_name || "Пользователь";

shareService.forwardMessage(message.content$.get(), senderName);
};

return (
<div
className={classNames(
Expand All @@ -69,6 +79,9 @@ function Message({ chatGpt, message }: IProps) {
<WarningTooltip />
)}
<Copy textToClickBoard={message.content$.get()} />
<IconButton onClick={onForwardMessage}>
<Icon24Share />
</IconButton>
<IconButton
className={selected ? classes.selectedIcon : ""}
onClick={onSelectFirstMessage}
Expand Down
17 changes: 17 additions & 0 deletions GPTutor-Frontend/src/services/ShareService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,23 @@ class ShareService {
console.log(data);
});
}

forwardMessage(messageContent: string, senderName: string) {
const forwardText = `Сообщение от ${senderName}:\n\n${messageContent}\n\nПередано через GPTutor: https://vk.com/app51602327`;

return bridge
.send("VKWebAppShowWallPostBox", {
message: forwardText,
})
.then((data) => {
console.log("Message forwarded successfully:", data);
return data;
})
.catch((error) => {
console.error("Error forwarding message:", error);
throw error;
});
}
}

export const shareService = new ShareService();
45 changes: 45 additions & 0 deletions examples/test-forward-functionality.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Testing Message Forwarding Functionality

## Changes Made

1. **ShareService.ts** - Added `forwardMessage` method
- Takes message content and sender name
- Creates formatted message with source attribution
- Uses VK Bridge to show wall post box
- Returns promise for proper error handling

2. **Message.tsx** - Added forward button
- Added `Icon24Share` import from VK icons
- Added `shareService` import
- Created `onForwardMessage` handler
- Added IconButton with share icon in the icons block

## Expected Behavior

When user clicks the forward (share) icon on any message:
1. The `onForwardMessage` handler is triggered
2. It extracts the sender name (GPT name for assistant or user's first name)
3. Creates formatted forwarding text including:
- Original sender identification
- Complete message content
- Attribution to GPTutor app
4. Opens VK wall post box with the formatted message
5. User can share to their wall or send to friends

## Integration Points

- Uses existing VK Bridge integration
- Follows existing UI patterns (same icon styling as copy/select buttons)
- Maintains existing message structure and styling
- Compatible with existing message selection system

## Files Modified

- `/src/services/ShareService.ts` - Added forwardMessage method
- `/src/components/Messenger/MessengerList/Message/Message.tsx` - Added forward button and handler

## Russian Context

The forwarding message is formatted in Russian:
- "Сообщение от [Sender Name]:" - "Message from [Sender Name]:"
- "Передано через GPTutor:" - "Forwarded via GPTutor:"