-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
608 changed files
with
2,725 additions
and
71 deletions.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import type { IMessageBuilder, INotifier } from '@rocket.chat/apps-engine/definition/accessors'; | ||
import type { ITypingOptions } from '@rocket.chat/apps-engine/definition/accessors/INotifier.ts'; | ||
import type { _TypingScope } from '@rocket.chat/apps-engine/definition/accessors/INotifier.ts'; | ||
import type { IMessage } from '@rocket.chat/apps-engine/definition/messages'; | ||
import type { IRoom } from '@rocket.chat/apps-engine/definition/rooms'; | ||
import type { IUser } from '@rocket.chat/apps-engine/definition/users'; | ||
import { MessageBuilder } from './builders/MessageBuilder.ts'; | ||
import { AppObjectRegistry } from '../../AppObjectRegistry.ts'; | ||
import * as Messenger from '../messenger.ts'; | ||
import { require } from "../require.ts"; | ||
|
||
const { TypingScope } = require('@rocket.chat/apps-engine/definition/accessors/INotifier.js') as { | ||
TypingScope: typeof _TypingScope; | ||
}; | ||
|
||
export class Notifier implements INotifier { | ||
private senderFn: typeof Messenger.sendRequest; | ||
|
||
constructor(senderFn: typeof Messenger.sendRequest) { | ||
this.senderFn = senderFn; | ||
} | ||
|
||
public async notifyUser(user: IUser, message: IMessage): Promise<void> { | ||
if (!message.sender || !message.sender.id) { | ||
const appUser = await this.getAppUser(); | ||
|
||
message.sender = appUser; | ||
} | ||
|
||
await this.callMessageBridge('doNotifyUser', [user, message, AppObjectRegistry.get<string>('id')]); | ||
} | ||
|
||
public async notifyRoom(room: IRoom, message: IMessage): Promise<void> { | ||
if (!message.sender || !message.sender.id) { | ||
const appUser = await this.getAppUser(); | ||
|
||
message.sender = appUser; | ||
} | ||
|
||
await this.callMessageBridge('doNotifyRoom', [room, message, AppObjectRegistry.get<string>('id')]); | ||
} | ||
|
||
public async typing(options: ITypingOptions): Promise<() => Promise<void>> { | ||
options.scope = options.scope || TypingScope.Room; | ||
|
||
if (!options.username) { | ||
const appUser = await this.getAppUser(); | ||
options.username = (appUser && appUser.name) || ''; | ||
} | ||
|
||
const appId = AppObjectRegistry.get<string>('id'); | ||
|
||
await this.callMessageBridge('doTyping', [{ ...options, isTyping: true }, appId]); | ||
|
||
return async () => { | ||
await this.callMessageBridge('doTyping', [{ ...options, isTyping: false }, appId]); | ||
}; | ||
} | ||
|
||
public getMessageBuilder(): IMessageBuilder { | ||
return new MessageBuilder(); | ||
} | ||
|
||
private async callMessageBridge(method: string, params: Array<unknown>): Promise<void> { | ||
await this.senderFn({ | ||
method: `bridges:getMessageBridge:${method}`, | ||
params, | ||
}); | ||
} | ||
|
||
private async getAppUser(): Promise<IUser | undefined> { | ||
const response = await this.senderFn({ method: 'bridges:getUserBridge:doGetAppUser', params: [AppObjectRegistry.get<string>('id')] }); | ||
return response.result; | ||
} | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -130,13 +130,13 @@ <h4>See</h4><p><a href="https://v8.dev/docs/stack-trace-api#customizing-stack-tr | |
</div></li></ul></li></ul></div><aside class="tsd-sources"> | ||
<p>Inherited from Error.prepareStackTrace</p> | ||
<ul> | ||
<li>Defined in node_modules/.deno/@types[email protected]/node_modules/@types/node/globals.d.ts:27</li></ul></aside></section> | ||
<li>Defined in node_modules/@types/node/globals.d.ts:11</li></ul></aside></section> | ||
<section class="tsd-panel tsd-member tsd-is-inherited tsd-is-external"><a id="stackTraceLimit" class="tsd-anchor"></a> | ||
<h3 class="tsd-anchor-link"><code class="tsd-tag ts-flagStatic">Static</code> <span>stack<wbr/>Trace<wbr/>Limit</span><a href="#stackTraceLimit" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="#icon-anchor"></use></svg></a></h3> | ||
<div class="tsd-signature"><span class="tsd-kind-property">stack<wbr/>Trace<wbr/>Limit</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">number</span></div><aside class="tsd-sources"> | ||
<p>Inherited from Error.stackTraceLimit</p> | ||
<ul> | ||
<li>Defined in node_modules/.deno/@types[email protected]/node_modules/@types/node/globals.d.ts:29</li></ul></aside></section></section> | ||
<li>Defined in node_modules/@types/node/globals.d.ts:13</li></ul></aside></section></section> | ||
<section class="tsd-panel-group tsd-member-group"> | ||
<h2>Methods</h2> | ||
<section class="tsd-panel tsd-member"><a id="getErrorInfo" class="tsd-anchor"></a> | ||
|
@@ -170,7 +170,7 @@ <h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">void</spa | |
<div class="tsd-comment tsd-typography"></div><aside class="tsd-sources"> | ||
<p>Inherited from Error.captureStackTrace</p> | ||
<ul> | ||
<li>Defined in node_modules/.deno/@types[email protected]/node_modules/@types/node/globals.d.ts:20</li></ul></aside></li></ul></section></section></div> | ||
<li>Defined in node_modules/@types/node/globals.d.ts:4</li></ul></aside></li></ul></section></section></div> | ||
<div class="col-sidebar"> | ||
<div class="page-menu"> | ||
<div class="tsd-navigation settings"> | ||
|
@@ -214,6 +214,7 @@ <h3><svg width="20" height="20" viewBox="0 0 24 24" fill="none"><use href="#icon | |
<li><a href="../modules/accessors_IConfigurationExtend.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-4"></use></svg><span>accessors/IConfiguration<wbr/>Extend</span></a></li> | ||
<li><a href="../modules/accessors_IConfigurationModify.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-4"></use></svg><span>accessors/IConfiguration<wbr/>Modify</span></a></li> | ||
<li><a href="../modules/accessors_IDiscussionBuilder.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-4"></use></svg><span>accessors/IDiscussion<wbr/>Builder</span></a></li> | ||
<li><a href="../modules/accessors_IEmailCreator.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-4"></use></svg><span>accessors/IEmail<wbr/>Creator</span></a></li> | ||
<li><a href="../modules/accessors_IEnvironmentRead.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-4"></use></svg><span>accessors/IEnvironment<wbr/>Read</span></a></li> | ||
<li><a href="../modules/accessors_IEnvironmentWrite.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-4"></use></svg><span>accessors/IEnvironment<wbr/>Write</span></a></li> | ||
<li><a href="../modules/accessors_IEnvironmentalVariableRead.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-4"></use></svg><span>accessors/IEnvironmental<wbr/>Variable<wbr/>Read</span></a></li> | ||
|
@@ -283,6 +284,7 @@ <h3><svg width="20" height="20" viewBox="0 0 24 24" fill="none"><use href="#icon | |
<li><a href="../modules/cloud_IWorkspaceToken.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-4"></use></svg><span>cloud/IWorkspace<wbr/>Token</span></a></li> | ||
<li><a href="../modules/definition_roles.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-4"></use></svg><span>definition/roles</span></a></li> | ||
<li><a href="../modules/email.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-4"></use></svg><span>email</span></a></li> | ||
<li><a href="../modules/email_IEmail.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-4"></use></svg><span>email/IEmail</span></a></li> | ||
<li><a href="../modules/email_IEmailDescriptor.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-4"></use></svg><span>email/IEmail<wbr/>Descriptor</span></a></li> | ||
<li><a href="../modules/email_IPreEmailSent.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-4"></use></svg><span>email/IPre<wbr/>Email<wbr/>Sent</span></a></li> | ||
<li><a href="../modules/email_IPreEmailSentContext.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-4"></use></svg><span>email/IPre<wbr/>Email<wbr/>Sent<wbr/>Context</span></a></li> | ||
|
Oops, something went wrong.