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

Return event_id when sending a message #242

Merged
merged 2 commits into from
Oct 5, 2020
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
1 change: 1 addition & 0 deletions changelog.d/242.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Return `event_id` when sending a event or state event
24 changes: 15 additions & 9 deletions src/components/intent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,17 +358,20 @@ export class Intent {
* @param type The event type
* @param content The event content
*/
public async sendEvent(roomId: string, type: string, content: Record<string, unknown>) {
public async sendEvent(roomId: string, type: string, content: Record<string, unknown>)
// eslint-disable-next-line camelcase
: Promise<{event_id: string}> {
if (this.encryption) {
// We *need* to sync before we can send a message.
await this.ensureRegistered();
await this.encryption.ensureClientSyncingCallback();
}
await this._ensureJoined(roomId);
await this._ensureHasPowerLevelFor(roomId, type);
return this._joinGuard(roomId, async() => (
this.client.sendEvent(roomId, type, content)
));
return this._joinGuard(roomId, async() =>
// eslint-disable-next-line camelcase
this.client.sendEvent(roomId, type, content) as Promise<{event_id: string}>
);
}

/**
Expand All @@ -381,12 +384,15 @@ export class Intent {
* @param skey The state key
* @param content The event content
*/
public async sendStateEvent(roomId: string, type: string, skey: string, content: Record<string, unknown>) {
public async sendStateEvent(roomId: string, type: string, skey: string, content: Record<string, unknown>
// eslint-disable-next-line camelcase
): Promise<{event_id: string}> {
await this._ensureJoined(roomId);
await this._ensureHasPowerLevelFor(roomId, type);
return this._joinGuard(roomId, async() => (
this.client.sendStateEvent(roomId, type, content, skey)
));
return this._joinGuard(roomId, async() =>
// eslint-disable-next-line camelcase
this.client.sendStateEvent(roomId, type, content, skey) as Promise<{event_id: string}>
);
}

/**
Expand Down Expand Up @@ -682,7 +688,7 @@ export class Intent {

// Guard a function which returns a promise which may reject if the user is not
// in the room. If the promise rejects, join the room and retry the function.
private async _joinGuard(roomId: string, promiseFn: () => Promise<unknown>) {
private async _joinGuard<T>(roomId: string, promiseFn: () => Promise<T>): Promise<T> {
try {
// await so we can handle the error
return await promiseFn();
Expand Down