Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NEW FEATURE] Allows Deletion of message when a messageID is given #483

Open
wants to merge 5 commits into
base: alpha
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 additions & 0 deletions src/definition/accessors/IModifyDeleter.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export interface IModifyDeleter {
deleteRoom(roomId: string): Promise<void>;
/*Deletes a message given a messageId*/
deleteMessage(messageId: string): Promise<void>;
}
4 changes: 4 additions & 0 deletions src/server/accessors/ModifyDeleter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@ export class ModifyDeleter implements IModifyDeleter {
public async deleteRoom(roomId: string): Promise<void> {
return this.bridges.getRoomBridge().doDelete(roomId, this.appId);
}

public async deleteMessage(messageId: string): Promise<void> {
return this.bridges.getMessageBridge().doDelete(messageId, this.appId);
}
}
6 changes: 6 additions & 0 deletions src/server/bridges/MessageBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,19 @@ export abstract class MessageBridge extends BaseBridge {
return this.getById(messageId, appId);
}
}
public async doDelete(messageId: string, appId: string): Promise<void> {
if (this.hasWritePermission(appId)) {
return this.delete(messageId, appId);
}
}

protected abstract create(message: IMessage, appId: string): Promise<string>;
protected abstract update(message: IMessage, appId: string): Promise<void>;
protected abstract notifyUser(user: IUser, message: IMessage, appId: string): Promise<void>;
protected abstract notifyRoom(room: IRoom, message: IMessage, appId: string): Promise<void>;
protected abstract typing(options: ITypingDescriptor, appId: string): Promise<void>;
protected abstract getById(messageId: string, appId: string): Promise<IMessage>;
protected abstract delete(messageId: string, appId: string): Promise<void>;

private hasReadPermission(appId: string): boolean {
if (AppPermissionManager.hasPermission(appId, AppPermissions.message.read)) {
Expand Down
3 changes: 3 additions & 0 deletions tests/test-data/bridges/messageBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,7 @@ export class TestsMessageBridge extends MessageBridge {
public typing(options: ITypingDescriptor): Promise<void> {
throw new Error('Method not implemented.');
}
public delete(roomId: string, appId: string): Promise<void> {
kulkarnigaurav38 marked this conversation as resolved.
Show resolved Hide resolved
throw new Error('Method not implemented.');
}
}