Skip to content
Snippets Groups Projects
Unverified Commit 6e7c5b36 authored by dionisio-bot[bot]'s avatar dionisio-bot[bot] Committed by GitHub
Browse files

fix(Omnichannel): Open expanded view (galery mode) for image attachments from livechat (#32256)

parent f02012b2
Branches backport-6.7.1-31958 release-6.7.1
No related tags found
No related merge requests found
---
"@rocket.chat/meteor": patch
---
Fixed open expanded view (galery mode) for image attachments sent by livechat widget
...@@ -26,7 +26,7 @@ declare module '@rocket.chat/ui-contexts' { ...@@ -26,7 +26,7 @@ declare module '@rocket.chat/ui-contexts' {
} }
export const sendMessageLivechat = async ({ export const sendMessageLivechat = async ({
message: { token, _id, rid, msg, file, attachments }, message: { token, _id, rid, msg, file, files, attachments },
agent, agent,
}: ISendMessageLivechat): Promise<boolean> => { }: ISendMessageLivechat): Promise<boolean> => {
check(token, String); check(token, String);
...@@ -67,6 +67,7 @@ export const sendMessageLivechat = async ({ ...@@ -67,6 +67,7 @@ export const sendMessageLivechat = async ({
msg, msg,
token, token,
file, file,
files,
attachments, attachments,
}, },
agent, agent,
...@@ -79,7 +80,7 @@ export const sendMessageLivechat = async ({ ...@@ -79,7 +80,7 @@ export const sendMessageLivechat = async ({
}; };
Meteor.methods<ServerMethods>({ Meteor.methods<ServerMethods>({
async sendMessageLivechat({ token, _id, rid, msg, file, attachments }: ILivechatMessage, agent: ILivechatMessageAgent) { async sendMessageLivechat({ token, _id, rid, msg, file, files, attachments }: ILivechatMessage, agent: ILivechatMessageAgent) {
return sendMessageLivechat({ message: { token, _id, rid, msg, file, attachments }, agent }); return sendMessageLivechat({ message: { token, _id, rid, msg, file, files, attachments }, agent });
}, },
}); });
...@@ -13,6 +13,7 @@ import { IUserCredentialsHeader, adminUsername } from '../user'; ...@@ -13,6 +13,7 @@ import { IUserCredentialsHeader, adminUsername } from '../user';
import { getRandomVisitorToken } from './users'; import { getRandomVisitorToken } from './users';
import { DummyResponse, sleep } from './utils'; import { DummyResponse, sleep } from './utils';
import { Response } from 'supertest'; import { Response } from 'supertest';
import { imgURL } from '../interactions';
export const createLivechatRoom = async (visitorToken: string, extraRoomParams?: Record<string, string>): Promise<IOmnichannelRoom> => { export const createLivechatRoom = async (visitorToken: string, extraRoomParams?: Record<string, string>): Promise<IOmnichannelRoom> => {
const urlParams = new URLSearchParams(); const urlParams = new URLSearchParams();
...@@ -208,6 +209,21 @@ export const sendMessage = (roomId: string, message: string, visitorToken: strin ...@@ -208,6 +209,21 @@ export const sendMessage = (roomId: string, message: string, visitorToken: strin
}); });
}; };
export const uploadFile = (roomId: string, visitorToken: string): Promise<IMessage> => {
return new Promise((resolve, reject) => {
request
.post(api(`livechat/upload/${roomId}`))
.set({ 'x-visitor-token': visitorToken, ...credentials })
.attach('file', imgURL)
.end((err: Error, res: DummyResponse<IMessage>) => {
if (err) {
return reject(err);
}
resolve(res.body as unknown as IMessage);
});
});
};
// Sends a message using sendMessage method from agent // Sends a message using sendMessage method from agent
export const sendAgentMessage = (roomId: string, msg?: string): Promise<IMessage> => { export const sendAgentMessage = (roomId: string, msg?: string): Promise<IMessage> => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
...@@ -243,6 +259,12 @@ export const fetchMessages = (roomId: string, visitorToken: string): Promise<IMe ...@@ -243,6 +259,12 @@ export const fetchMessages = (roomId: string, visitorToken: string): Promise<IMe
if (err) { if (err) {
return reject(err); return reject(err);
} }
if (!res.body.success) {
reject(res.body);
return;
}
resolve(res.body.messages); resolve(res.body.messages);
}); });
}); });
......
...@@ -9,6 +9,7 @@ import { ...@@ -9,6 +9,7 @@ import {
sendAgentMessage, sendAgentMessage,
createAgent, createAgent,
makeAgentAvailable, makeAgentAvailable,
uploadFile,
} from '../../../data/livechat/rooms'; } from '../../../data/livechat/rooms';
import { updateSetting } from '../../../data/permissions.helper'; import { updateSetting } from '../../../data/permissions.helper';
...@@ -51,5 +52,18 @@ describe('LIVECHAT - messages', () => { ...@@ -51,5 +52,18 @@ describe('LIVECHAT - messages', () => {
expect(quotedMessageAttachments).to.have.property('text').that.is.equal(agentMsgSentence); expect(quotedMessageAttachments).to.have.property('text').that.is.equal(agentMsgSentence);
} }
}); });
it('should verify if visitor is receiving a message with a image attachment', async () => {
const {
room: { _id: roomId },
visitor: { token },
} = await startANewLivechatRoomAndTakeIt();
const imgMessage = await uploadFile(roomId, token);
expect(imgMessage).to.have.property('files').that.is.an('array');
expect(imgMessage.files?.[0]).to.have.keys('_id', 'name', 'type');
expect(imgMessage).to.have.property('file').that.deep.equal(imgMessage?.files?.[0]);
});
}); });
}); });
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment