-
Notifications
You must be signed in to change notification settings - Fork 11k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: register a dummy Read Receipts model in CE (#32022)
- Loading branch information
1 parent
c9a92e6
commit c3fe007
Showing
5 changed files
with
269 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { registerModel } from '@rocket.chat/models'; | ||
|
||
import { ReadReceiptsDummy } from './dummy/ReadReceipts'; | ||
|
||
registerModel('IReadReceiptsModel', new ReadReceiptsDummy(), false); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,196 @@ | ||
import type { RocketChatRecordDeleted } from '@rocket.chat/core-typings'; | ||
import type { DefaultFields, FindPaginated, IBaseModel, InsertionModel, ResultFields } from '@rocket.chat/model-typings'; | ||
import { getCollectionName } from '@rocket.chat/models'; | ||
import type { | ||
BulkWriteOptions, | ||
ChangeStream, | ||
Collection, | ||
DeleteOptions, | ||
DeleteResult, | ||
Document, | ||
Filter, | ||
FindCursor, | ||
FindOptions, | ||
InsertManyResult, | ||
InsertOneOptions, | ||
InsertOneResult, | ||
ModifyResult, | ||
UpdateFilter, | ||
UpdateOptions, | ||
UpdateResult, | ||
WithId, | ||
} from 'mongodb'; | ||
|
||
export class BaseDummy< | ||
T extends { _id: string }, | ||
C extends DefaultFields<T> = undefined, | ||
TDeleted extends RocketChatRecordDeleted<T> = RocketChatRecordDeleted<T>, | ||
> implements IBaseModel<T, C, TDeleted> | ||
{ | ||
public readonly col: Collection<T>; | ||
|
||
private collectionName: string; | ||
|
||
constructor(protected name: string) { | ||
this.collectionName = getCollectionName(name); | ||
this.col = undefined as any; | ||
} | ||
|
||
public async createIndexes(): Promise<string[] | void> { | ||
// nothing to do | ||
} | ||
|
||
getCollectionName(): string { | ||
return this.collectionName; | ||
} | ||
|
||
async findOneAndUpdate(): Promise<ModifyResult<T>> { | ||
return { | ||
value: null, | ||
ok: 1, | ||
}; | ||
} | ||
|
||
findOneById(_id: T['_id'], options?: FindOptions<T> | undefined): Promise<T | null>; | ||
|
||
findOneById<P extends Document = T>(_id: T['_id'], options?: FindOptions<P>): Promise<P | null>; | ||
|
||
async findOneById(_id: T['_id'], _options?: any): Promise<T | null> { | ||
return null; | ||
} | ||
|
||
findOne(query?: Filter<T> | T['_id'], options?: undefined): Promise<T | null>; | ||
|
||
findOne<P extends Document = T>(query: Filter<T> | T['_id'], options: FindOptions<P extends T ? T : P>): Promise<P | null>; | ||
|
||
async findOne<P>(_query: Filter<T> | T['_id'], _options?: any): Promise<WithId<T> | WithId<P> | null> { | ||
return null; | ||
} | ||
|
||
find(query?: Filter<T>): FindCursor<ResultFields<T, C>>; | ||
|
||
find<P extends Document = T>(query: Filter<T>, options: FindOptions<P extends T ? T : P>): FindCursor<P>; | ||
|
||
find<P extends Document>( | ||
_query: Filter<T> | undefined, | ||
_options?: FindOptions<P extends T ? T : P>, | ||
): FindCursor<WithId<P>> | FindCursor<WithId<T>> { | ||
return undefined as any; | ||
} | ||
|
||
findPaginated<P extends Document = T>(query: Filter<T>, options?: FindOptions<P extends T ? T : P>): FindPaginated<FindCursor<WithId<P>>>; | ||
|
||
findPaginated(_query: Filter<T>, _options?: any): FindPaginated<FindCursor<WithId<T>>> { | ||
return { | ||
cursor: undefined as any, | ||
totalCount: Promise.resolve(0), | ||
}; | ||
} | ||
|
||
async update( | ||
filter: Filter<T>, | ||
update: UpdateFilter<T> | Partial<T>, | ||
options?: UpdateOptions & { multi?: true }, | ||
): Promise<UpdateResult | Document> { | ||
return this.updateOne(filter, update, options); | ||
} | ||
|
||
async updateOne(_filter: Filter<T>, _update: UpdateFilter<T> | Partial<T>, _options?: UpdateOptions): Promise<UpdateResult> { | ||
return { | ||
acknowledged: true, | ||
matchedCount: 0, | ||
modifiedCount: 0, | ||
upsertedCount: 0, | ||
upsertedId: '' as any, | ||
}; | ||
} | ||
|
||
async updateMany(filter: Filter<T>, update: UpdateFilter<T> | Partial<T>, options?: UpdateOptions): Promise<Document | UpdateResult> { | ||
return this.updateOne(filter, update, options); | ||
} | ||
|
||
async insertMany(_docs: InsertionModel<T>[], _options?: BulkWriteOptions): Promise<InsertManyResult<T>> { | ||
return { | ||
acknowledged: true, | ||
insertedCount: 0, | ||
insertedIds: {}, | ||
}; | ||
} | ||
|
||
async insertOne(_doc: InsertionModel<T>, _options?: InsertOneOptions): Promise<InsertOneResult<T>> { | ||
return { | ||
acknowledged: true, | ||
insertedId: '' as any, | ||
}; | ||
} | ||
|
||
async removeById(_id: T['_id']): Promise<DeleteResult> { | ||
return { | ||
acknowledged: true, | ||
deletedCount: 0, | ||
}; | ||
} | ||
|
||
async deleteOne(filter: Filter<T>, options?: DeleteOptions & { bypassDocumentValidation?: boolean }): Promise<DeleteResult> { | ||
return this.deleteMany(filter, options); | ||
} | ||
|
||
async deleteMany(_filter: Filter<T>, _options?: DeleteOptions): Promise<DeleteResult> { | ||
return { | ||
acknowledged: true, | ||
deletedCount: 0, | ||
}; | ||
} | ||
|
||
// Trash | ||
trashFind<P extends TDeleted>( | ||
_query: Filter<TDeleted>, | ||
_options?: FindOptions<P extends TDeleted ? TDeleted : P>, | ||
): FindCursor<WithId<TDeleted>> | undefined { | ||
return undefined as any; | ||
} | ||
|
||
trashFindOneById(_id: TDeleted['_id']): Promise<TDeleted | null>; | ||
|
||
trashFindOneById<P extends Document>(_id: TDeleted['_id'], options: FindOptions<P extends TDeleted ? TDeleted : P>): Promise<P | null>; | ||
|
||
async trashFindOneById<P extends TDeleted>( | ||
_id: TDeleted['_id'], | ||
_options?: FindOptions<P extends TDeleted ? TDeleted : P>, | ||
): Promise<WithId<RocketChatRecordDeleted<P> | TDeleted> | null> { | ||
return null; | ||
} | ||
|
||
trashFindDeletedAfter(deletedAt: Date): FindCursor<WithId<TDeleted>>; | ||
|
||
trashFindDeletedAfter<P extends Document = TDeleted>( | ||
_deletedAt: Date, | ||
_query?: Filter<TDeleted>, | ||
_options?: FindOptions<P extends TDeleted ? TDeleted : P>, | ||
): FindCursor<WithId<TDeleted>> { | ||
return undefined as any; | ||
} | ||
|
||
trashFindPaginatedDeletedAfter<P extends Document = TDeleted>( | ||
_deletedAt: Date, | ||
_query?: Filter<TDeleted>, | ||
_options?: FindOptions<P extends TDeleted ? TDeleted : P>, | ||
): FindPaginated<FindCursor<WithId<TDeleted>>> { | ||
return { | ||
cursor: undefined as any, | ||
totalCount: Promise.resolve(0), | ||
}; | ||
} | ||
|
||
watch(_pipeline?: object[]): ChangeStream<T> { | ||
return undefined as any; | ||
} | ||
|
||
async countDocuments(): Promise<number> { | ||
return 0; | ||
} | ||
|
||
async estimatedDocumentCount(): Promise<number> { | ||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import type { IUser, IMessage, ReadReceipt } from '@rocket.chat/core-typings'; | ||
import type { IReadReceiptsModel } from '@rocket.chat/model-typings'; | ||
import type { FindCursor, DeleteResult, Filter, UpdateResult, Document } from 'mongodb'; | ||
|
||
import { BaseDummy } from './BaseDummy'; | ||
|
||
export class ReadReceiptsDummy extends BaseDummy<ReadReceipt> implements IReadReceiptsModel { | ||
constructor() { | ||
super('read_receipts'); | ||
} | ||
|
||
findByMessageId(_messageId: string): FindCursor<ReadReceipt> { | ||
return this.find({}); | ||
} | ||
|
||
removeByUserId(_userId: string): Promise<DeleteResult> { | ||
return this.deleteMany({}); | ||
} | ||
|
||
removeByRoomId(_roomId: string): Promise<DeleteResult> { | ||
return this.deleteMany({}); | ||
} | ||
|
||
removeByRoomIds(_roomIds: string[]): Promise<DeleteResult> { | ||
return this.deleteMany({}); | ||
} | ||
|
||
removeByMessageId(_messageId: string): Promise<DeleteResult> { | ||
return this.deleteMany({}); | ||
} | ||
|
||
removeByMessageIds(_messageIds: string[]): Promise<DeleteResult> { | ||
return this.deleteMany({}); | ||
} | ||
|
||
removeOTRReceiptsUntilDate(_roomId: string, _until: Date): Promise<DeleteResult> { | ||
return this.deleteMany({}); | ||
} | ||
|
||
async removeByIdPinnedTimestampLimitAndUsers( | ||
_roomId: string, | ||
_ignorePinned: boolean, | ||
_ignoreDiscussion: boolean, | ||
_ts: Filter<IMessage>['ts'], | ||
_users: IUser['_id'][], | ||
_ignoreThreads: boolean, | ||
): Promise<DeleteResult> { | ||
return this.deleteMany({}); | ||
} | ||
|
||
setPinnedByMessageId(_messageId: string, _pinned = true): Promise<Document | UpdateResult> { | ||
return this.updateMany({}, {}); | ||
} | ||
|
||
setAsThreadById(_messageId: string): Promise<Document | UpdateResult> { | ||
return this.updateMany({}, {}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters