Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const notifyFailedLogin = async (ipOrUsername: string, blockedUntil: Date, faile
],
};

await sendMessage(rocketCat, message, room, false);
await sendMessage(rocketCat, message, room);
};

export const isValidLoginAttemptByIp = async (ip: string): Promise<boolean> => {
Expand Down
9 changes: 8 additions & 1 deletion apps/meteor/app/lib/server/functions/sendMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ import { afterSaveMessage } from '../lib/afterSaveMessage';
import { notifyOnRoomChangedById } from '../lib/notifyListener';
import { validateCustomMessageFields } from '../lib/validateCustomMessageFields';

type SendMessageOptions = {
upsert?: boolean;
previewUrls?: string[];
};

// TODO: most of the types here are wrong, but I don't want to change them now

/**
Expand Down Expand Up @@ -217,7 +222,9 @@ export function prepareMessageObject(
* Caller of the function should verify the Message_MaxAllowedSize if needed.
* There might be same use cases which needs to override this setting. Example - sending error logs.
*/
export const sendMessage = async function (user: any, message: any, room: any, upsert = false, previewUrls?: string[]) {
export const sendMessage = async function (user: any, message: any, room: any, options: SendMessageOptions = {}) {
const { upsert = false, previewUrls } = options;

if (!user || !message || !room._id) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/lib/server/methods/sendMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export async function executeSendMessage(
}

metrics.messagesSent.inc(); // TODO This line needs to be moved to it's proper place. See the comments on: https://github.com/RocketChat/Rocket.Chat/pull/5736
return await sendMessage(user, message, room, false, extraInfo?.previewUrls);
return await sendMessage(user, message, room, { previewUrls: extraInfo?.previewUrls });
} catch (err: any) {
SystemLogger.error({ msg: 'Error sending message:', err });

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ callbacks.add(
groupable: false,
};

await sendMessage(user, message, room, true);
await sendMessage(user, message, room, { upsert: true });
},
callbacks.priority.MEDIUM,
'livechat-send-email-offline-message-to-channel',
Expand Down
4 changes: 2 additions & 2 deletions apps/meteor/app/slackbridge/server/RocketAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -503,13 +503,13 @@ export default class RocketAdapter {
// Make sure that a message with the same bot_id and timestamp doesn't already exists
const msg = await Messages.findOneBySlackBotIdAndSlackTs(slackMessage.bot_id, slackMessage.ts);
if (!msg) {
void sendMessage(rocketUser, rocketMsgObj, rocketChannel, true);
void sendMessage(rocketUser, rocketMsgObj, rocketChannel, { upsert: true });
}
}
}, 500);
} else {
rocketLogger.debug('Send message to Rocket.Chat');
await sendMessage(rocketUser, rocketMsgObj, rocketChannel, true);
await sendMessage(rocketUser, rocketMsgObj, rocketChannel, { upsert: true });
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/slackbridge/server/SlackAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1320,7 +1320,7 @@ export default class SlackAdapter {
msg._id = details.message_id;
}

void sendMessage(rocketUser, msg, rocketChannel, true);
void sendMessage(rocketUser, msg, rocketChannel, { upsert: true });
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ callbacks.add(
],
},
room,
true,
{ upsert: true },
);
return message;
}
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/server/services/media-call/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ export class MediaCallService extends ServiceClassInternal implements IMediaCall
const record = getHistoryMessagePayload(state, duration, call._id);

try {
const message = await sendMessage(user, record, room, false);
const message = await sendMessage(user, record, room);

if ('_id' in message) {
await CallHistory.updateMany({ callId: call._id }, { $set: { messageId: message._id } });
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/server/services/messages/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export class MessageService extends ServiceClassInternal implements IMessageServ
}

async sendMessageWithValidation(user: IUser, message: Partial<IMessage>, room: Partial<IRoom>, upsert = false): Promise<IMessage> {
return sendMessage(user, message, room, upsert);
return sendMessage(user, message, room, { upsert });
}

async deleteMessage(user: IUser, message: IMessage): Promise<void> {
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/server/services/video-conference/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ export class VideoConfService extends ServiceClassInternal implements IVideoConf
const appId = videoConfProviders.getProviderAppId(call.providerName);
const user = createdBy || (appId && (await Users.findOneByAppId(appId))) || (await Users.findOneById('rocket.cat'));

const message = await sendMessage(user, record, room, false);
const message = await sendMessage(user, record, room);

if (!message) {
throw new Error('failed-to-create-message');
Expand Down
Loading