Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Apr 23, 2024
Merged
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
5 changes: 5 additions & 0 deletions .changeset/green-ways-tie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": patch
---

Fixed open expanded view (galery mode) for image attachments sent by livechat widget
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ declare module '@rocket.chat/ui-contexts' {
}

export const sendMessageLivechat = async ({
message: { token, _id, rid, msg, file, attachments },
message: { token, _id, rid, msg, file, files, attachments },
agent,
}: ISendMessageLivechat): Promise<boolean> => {
check(token, String);
Expand Down Expand Up @@ -67,6 +67,7 @@ export const sendMessageLivechat = async ({
msg,
token,
file,
files,
attachments,
},
agent,
Expand All @@ -79,7 +80,7 @@ export const sendMessageLivechat = async ({
};

Meteor.methods<ServerMethods>({
async sendMessageLivechat({ token, _id, rid, msg, file, attachments }: ILivechatMessage, agent: ILivechatMessageAgent) {
return sendMessageLivechat({ message: { token, _id, rid, msg, file, attachments }, agent });
async sendMessageLivechat({ token, _id, rid, msg, file, files, attachments }: ILivechatMessage, agent: ILivechatMessageAgent) {
return sendMessageLivechat({ message: { token, _id, rid, msg, file, files, attachments }, agent });
},
});
22 changes: 22 additions & 0 deletions apps/meteor/tests/data/livechat/rooms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { IUserCredentialsHeader, adminUsername } from '../user';
import { getRandomVisitorToken } from './users';
import { DummyResponse, sleep } from './utils';
import { Response } from 'supertest';
import { imgURL } from '../interactions';

export const createLivechatRoom = async (visitorToken: string, extraRoomParams?: Record<string, string>): Promise<IOmnichannelRoom> => {
const urlParams = new URLSearchParams();
Expand Down Expand Up @@ -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
export const sendAgentMessage = (roomId: string, msg?: string): Promise<IMessage> => {
return new Promise((resolve, reject) => {
Expand Down Expand Up @@ -243,6 +259,12 @@ export const fetchMessages = (roomId: string, visitorToken: string): Promise<IMe
if (err) {
return reject(err);
}

if (!res.body.success) {
reject(res.body);
return;
}

resolve(res.body.messages);
});
});
Expand Down
14 changes: 14 additions & 0 deletions apps/meteor/tests/end-to-end/api/livechat/20-messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
sendAgentMessage,
createAgent,
makeAgentAvailable,
uploadFile,
} from '../../../data/livechat/rooms';
import { updateSetting } from '../../../data/permissions.helper';

Expand Down Expand Up @@ -51,5 +52,18 @@ describe('LIVECHAT - messages', () => {
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]);
});
});
});
Loading