Skip to content

Commit

Permalink
fix: Imported messages are not displayed (#29416)
Browse files Browse the repository at this point in the history
  • Loading branch information
matheusbsilva137 authored Jun 6, 2023
1 parent 1e1d10e commit 4513378
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 17 deletions.
6 changes: 6 additions & 0 deletions .changeset/slow-maps-swim.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@rocket.chat/meteor": patch
---

fix: Imported messages are not displayed
fix: Importer agent is added as a member of every imported room
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ const create = async ({
user.username as string,
[...new Set(invitedUsers)].filter(Boolean),
false,
false,
{
fname: discussionName,
description, // TODO discussions remove
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/importer-slack/server/importer.js
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ export class SlackImporter extends Base {
const isBotMessage = message.subtype && ['bot_message', 'slackbot_response'].includes(message.subtype);

if (message.subtype && !regularTypes.includes(message.subtype) && !isBotMessage) {
if (this.processMessageSubType(message, slackChannelId, newMessage, missedTypes)) {
if (await this.processMessageSubType(message, slackChannelId, newMessage, missedTypes)) {
await this.converter.addMessage(newMessage, this._useUpsert);
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -848,15 +848,15 @@ export class ImportDataConverter {
try {
let roomInfo;
if (roomData.t === 'd') {
roomInfo = await createDirectMessage(members, startedByUserId);
roomInfo = await createDirectMessage(members, startedByUserId, true);
} else {
if (!roomData.name) {
return;
}
if (roomData.t === 'p') {
roomInfo = await createPrivateGroupMethod(startedByUserId, roomData.name, members);
roomInfo = await createPrivateGroupMethod(startedByUserId, roomData.name, members, false, {}, {}, true);
} else {
roomInfo = await createChannelMethod(startedByUserId, roomData.name, members);
roomInfo = await createChannelMethod(startedByUserId, roomData.name, members, false, {}, {}, true);
}
}

Expand Down
3 changes: 2 additions & 1 deletion apps/meteor/app/lib/server/functions/createRoom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const createRoom = async <T extends RoomType>(
name: T extends 'd' ? undefined : string,
ownerUsername: string | undefined,
members: T extends 'd' ? IUser[] : string[] = [],
excludeSelf?: boolean,
readOnly?: boolean,
roomExtraData?: Partial<IRoom>,
options?: ICreateRoomParams['options'],
Expand Down Expand Up @@ -65,7 +66,7 @@ export const createRoom = async <T extends RoomType>(
});
}

if (owner.username && !members.includes(owner.username)) {
if (!excludeSelf && owner.username && !members.includes(owner.username)) {
members.push(owner.username);
}

Expand Down
13 changes: 5 additions & 8 deletions apps/meteor/app/lib/server/functions/insertMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,11 @@ export const insertMessage = async function (
},
{ $set: rest },
);
}
await Messages.insertOne({
_id,
// @ts-expect-error - seems it doesn't like this syntax :(
'u._id': message.u._id,
...rest,
});
if (!existingMessage) {
} else {
await Messages.insertOne({
_id,
...rest,
});
await Rooms.incMsgCountById(rid, 1);
}
message._id = _id;
Expand Down
3 changes: 2 additions & 1 deletion apps/meteor/app/lib/server/methods/createChannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const createChannelMethod = async (
readOnly = false,
customFields: Record<string, any> = {},
extraData: Record<string, any> = {},
excludeSelf = false,
) => {
check(name, String);
check(members, Match.Optional([String]));
Expand All @@ -43,7 +44,7 @@ export const createChannelMethod = async (
if (!(await hasPermissionAsync(userId, 'create-c'))) {
throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'createChannel' });
}
return createRoom('c', name, user.username, members, readOnly, {
return createRoom('c', name, user.username, members, excludeSelf, readOnly, {
customFields,
...extraData,
});
Expand Down
3 changes: 2 additions & 1 deletion apps/meteor/app/lib/server/methods/createPrivateGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const createPrivateGroupMethod = async (
readOnly = false,
customFields = {},
extraData = {},
excludeSelf = false,
): Promise<
ICreatedRoom & {
rid: string;
Expand All @@ -50,7 +51,7 @@ export const createPrivateGroupMethod = async (
throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'createPrivateGroup' });
}

return createRoom('p', name, user.username, members, readOnly, {
return createRoom('p', name, user.username, members, excludeSelf, readOnly, {
customFields,
...extraData,
});
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/server/methods/createDirectMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export async function createDirectMessage(
} catch (error) {
throw new Meteor.Error((error as any)?.message);
}
const { _id: rid, inserted, ...room } = await createRoom('d', undefined, undefined, roomUsers as IUser[], undefined, {}, options);
const { _id: rid, inserted, ...room } = await createRoom('d', undefined, undefined, roomUsers as IUser[], false, undefined, {}, options);

return {
// @ts-expect-error - room type is already defined in the `createRoom` return type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,14 @@ export class RocketChatRoomAdapter {
}

const readonly = false;
const excludeSelf = false;
const extraData = undefined;
const { rid, _id } = await createRoom(
federatedRoom.getRoomType(),
federatedRoom.getDisplayName(),
usernameOrId,
federatedRoom.getMembersUsernames(),
excludeSelf,
readonly,
extraData,
{ creator: creatorId },
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/server/services/room/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class RoomService extends ServiceClassInternal implements IRoomService {
}

// TODO convert `createRoom` function to "raw" and move to here
return createRoom(type, name, user.username, members, readOnly, extraData, options) as unknown as IRoom;
return createRoom(type, name, user.username, members, false, readOnly, extraData, options) as unknown as IRoom;
}

async createDirectMessage({ to, from }: { to: string; from: string }): Promise<{ rid: string }> {
Expand Down

0 comments on commit 4513378

Please sign in to comment.