snapshot of https://github.com/RocketChat/Rocket.Chat.git (develop, 2026-09-16; blobs > 131072B omitted)
Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Code scanning - action / CodeQL-Build (push) Failing after 1s
Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Code scanning - action / CodeQL-Build (push) Failing after 1s
This commit is contained in:
173
apps/meteor/server/meteor-methods/messages/getChannelHistory.ts
Normal file
173
apps/meteor/server/meteor-methods/messages/getChannelHistory.ts
Normal file
@@ -0,0 +1,173 @@
|
||||
import { Authorization } from '@rocket.chat/core-services';
|
||||
import type { IMessage, MessageTypesValues } from '@rocket.chat/core-typings';
|
||||
import type { ServerMethods } from '@rocket.chat/ddp-client';
|
||||
import { Messages, Rooms } from '@rocket.chat/models';
|
||||
import { check } from 'meteor/check';
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
|
||||
import { methodDeprecationLogger } from '../../lib/deprecationWarningLogger';
|
||||
import { getHiddenSystemMessages } from '../../lib/messaging/getHiddenSystemMessages';
|
||||
import { normalizeMessagesForUser } from '../../lib/utils/lib/normalizeMessagesForUser';
|
||||
import { settings } from '../../settings/cached';
|
||||
|
||||
declare module '@rocket.chat/ddp-client' {
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
interface ServerMethods {
|
||||
getChannelHistory(params: {
|
||||
rid: string;
|
||||
latest?: Date;
|
||||
oldest?: Date;
|
||||
inclusive?: boolean;
|
||||
offset?: number;
|
||||
count?: number;
|
||||
unreads?: boolean;
|
||||
showThreadMessages?: boolean;
|
||||
}): boolean | IMessage[] | { messages: IMessage[]; firstUnread?: any; unreadNotLoaded?: number };
|
||||
}
|
||||
}
|
||||
|
||||
export const getChannelHistory = async ({
|
||||
rid,
|
||||
fromUserId,
|
||||
latest,
|
||||
oldest,
|
||||
inclusive,
|
||||
offset = 0,
|
||||
count = 20,
|
||||
unreads,
|
||||
showThreadMessages = true,
|
||||
}: {
|
||||
rid: string;
|
||||
fromUserId: string;
|
||||
latest?: Date;
|
||||
oldest?: Date;
|
||||
inclusive?: boolean;
|
||||
offset?: number;
|
||||
count?: number;
|
||||
unreads?: boolean;
|
||||
showThreadMessages?: boolean;
|
||||
}): Promise<false | IMessage[] | { messages: IMessage[]; firstUnread?: any; unreadNotLoaded?: number }> => {
|
||||
check(rid, String);
|
||||
|
||||
if (!fromUserId) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const room = await Rooms.findOneById(rid);
|
||||
if (!room) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Make sure they can access the room
|
||||
if (!(await Authorization.canReadRoom(room, { _id: fromUserId }))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Ensure latest is always defined.
|
||||
if (latest === undefined) {
|
||||
latest = new Date();
|
||||
}
|
||||
|
||||
// Verify oldest is a date if it exists
|
||||
|
||||
if (oldest !== undefined && {}.toString.call(oldest) !== '[object Date]') {
|
||||
throw new Meteor.Error('error-invalid-date', 'Invalid date', { method: 'getChannelHistory' });
|
||||
}
|
||||
|
||||
const hiddenSystemMessages = settings.get<MessageTypesValues[]>('Hide_System_Messages');
|
||||
|
||||
const hiddenMessageTypes = getHiddenSystemMessages(room, hiddenSystemMessages);
|
||||
|
||||
const options: Record<string, unknown> = {
|
||||
sort: {
|
||||
ts: -1,
|
||||
},
|
||||
skip: offset,
|
||||
limit: count,
|
||||
};
|
||||
|
||||
const records =
|
||||
oldest === undefined
|
||||
? await Messages.findVisibleByRoomIdBeforeTimestampNotContainingTypes(
|
||||
rid,
|
||||
latest,
|
||||
hiddenMessageTypes,
|
||||
options,
|
||||
showThreadMessages,
|
||||
inclusive,
|
||||
).toArray()
|
||||
: await Messages.findVisibleByRoomIdBetweenTimestampsNotContainingTypes(
|
||||
rid,
|
||||
oldest,
|
||||
latest,
|
||||
hiddenMessageTypes,
|
||||
options,
|
||||
showThreadMessages,
|
||||
inclusive,
|
||||
).toArray();
|
||||
|
||||
const messages = await normalizeMessagesForUser(records, fromUserId);
|
||||
|
||||
if (unreads) {
|
||||
let unreadNotLoaded = 0;
|
||||
let firstUnread = undefined;
|
||||
|
||||
if (oldest !== undefined) {
|
||||
const firstMsg = messages[messages.length - 1];
|
||||
if (firstMsg !== undefined && firstMsg.ts > oldest) {
|
||||
const unreadMessages = Messages.findVisibleByRoomIdBetweenTimestampsNotContainingTypes(
|
||||
rid,
|
||||
oldest,
|
||||
firstMsg.ts,
|
||||
hiddenMessageTypes,
|
||||
{
|
||||
limit: 1,
|
||||
sort: {
|
||||
ts: 1,
|
||||
},
|
||||
},
|
||||
showThreadMessages,
|
||||
);
|
||||
|
||||
const totalCursor = await Messages.countVisibleByRoomIdBetweenTimestampsNotContainingTypes(
|
||||
rid,
|
||||
oldest,
|
||||
firstMsg.ts,
|
||||
hiddenMessageTypes,
|
||||
showThreadMessages,
|
||||
);
|
||||
|
||||
firstUnread = (await unreadMessages.toArray())[0];
|
||||
unreadNotLoaded = totalCursor;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
messages: messages || [],
|
||||
firstUnread,
|
||||
unreadNotLoaded,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
messages: messages || [],
|
||||
};
|
||||
};
|
||||
|
||||
Meteor.methods<ServerMethods>({
|
||||
async getChannelHistory({ rid, latest, oldest, inclusive, offset = 0, count = 20, unreads, showThreadMessages = true }) {
|
||||
methodDeprecationLogger.method('getChannelHistory', '9.0.0', '/v1/channels.history');
|
||||
check(rid, String);
|
||||
|
||||
if (!Meteor.userId()) {
|
||||
throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'getChannelHistory' });
|
||||
}
|
||||
|
||||
const fromUserId = Meteor.userId();
|
||||
if (!fromUserId) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return getChannelHistory({ rid, fromUserId, latest, oldest, inclusive, offset, count, unreads, showThreadMessages });
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user