Skip to content

Commit

Permalink
Fix send giphy media
Browse files Browse the repository at this point in the history
  • Loading branch information
hkhanouchi committed Mar 8, 2023
1 parent 5278242 commit 6bb9e51
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
5 changes: 5 additions & 0 deletions src/components/message/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ export class Message extends React.Component<Properties, State> {
return this.props.isOwner;
};

isMediaMessage = (): boolean => {
return !!this.props.media;
};

deleteMessage = (): void => this.props.onDelete(this.props.messageId);
toggleEdit = () => this.setState((state) => ({ isEditing: !state.isEditing }));
editMessage = (content: string, mentionedUserIds: string[]) => {
Expand Down Expand Up @@ -154,6 +158,7 @@ export class Message extends React.Component<Properties, State> {
onDelete={this.deleteMessage}
onEdit={this.toggleEdit}
onReply={this.onReply}
isMediaMessage={this.isMediaMessage()}
/>
</div>
);
Expand Down
5 changes: 3 additions & 2 deletions src/platform-apps/channels/messages-menu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ interface Properties {
className: string;
canEdit: boolean;
canReply?: boolean;
isMediaMessage?: boolean;

onDelete?: () => void;
onEdit?: () => void;
Expand All @@ -32,7 +33,7 @@ export class MessageMenu extends React.Component<Properties, State> {
renderItems = () => {
const menuItems = [];

if (this.props.onReply && this.props.canReply) {
if (this.props.onReply && this.props.canReply && !this.props.isMediaMessage) {
menuItems.push(
<li
className='menu-button reply-item'
Expand All @@ -54,7 +55,7 @@ export class MessageMenu extends React.Component<Properties, State> {
</li>
);
}
if (this.props.onEdit && this.props.canEdit) {
if (this.props.onEdit && this.props.canEdit && !this.props.isMediaMessage) {
menuItems.push(
<li
className='menu-button edit-item'
Expand Down
8 changes: 6 additions & 2 deletions src/store/messages/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { del, get, post, put } from '../../lib/api/rest';
import { ParentMessage } from '../../lib/chat/types';
import { LinkPreview } from '../../lib/link-preview';
import { Media, MessagesResponse } from './index';
import { SendPayload } from './saga';
import { FileUploadResult, SendPayload } from './saga';

export async function fetchMessagesByChannelId(channelId: string, lastCreatedAt?: number): Promise<MessagesResponse> {
const filter: any = {};
Expand All @@ -19,13 +19,17 @@ export async function sendMessagesByChannelId(
channelId: string,
message: string,
mentionedUserIds: string[],
parentMessage?: ParentMessage
parentMessage?: ParentMessage,
file?: FileUploadResult
): Promise<any> {
const filter: SendPayload = { message, mentionedUserIds };
if (parentMessage) {
filter.parentMessageId = parentMessage.messageId;
filter.parentMessageUserId = parentMessage.userId;
}
if (file) {
filter.file = file;
}

const response = await post<any>(`/chatChannels/${channelId}/message`).send(filter);

Expand Down
10 changes: 10 additions & 0 deletions src/store/messages/saga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export interface SendPayload {
parentMessage?: ParentMessage;
parentMessageId?: number;
parentMessageUserId?: string;
file?: FileUploadResult;
}

export interface MediaPyload {
Expand Down Expand Up @@ -244,6 +245,15 @@ export function* uploadFileMessage(action) {
messages.push(messagesResponse);
}

for (const file of media.filter((i) => i.giphy)) {
const original = file.giphy.images.original;
const giphyFile = { url: original.url, name: file.name, type: file.giphy.type };
const messagesResponse = yield call(sendMessagesByChannelId, channelId, undefined, undefined, undefined, giphyFile);

if (messagesResponse.status !== 200) return;
messages.push(messagesResponse.body);
}

yield put(
receive({
id: channelId,
Expand Down

0 comments on commit 6bb9e51

Please sign in to comment.