Skip to content

Commit

Permalink
fix(Omnichannel): Open expanded view (galery mode) for image attachme…
Browse files Browse the repository at this point in the history
…nts from livechat (#31990)
  • Loading branch information
tiagoevanp authored Apr 10, 2024
1 parent 2c85280 commit e1948a6
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 3 deletions.
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]);
});
});
});

0 comments on commit e1948a6

Please sign in to comment.