ref: applications/channels
This commit is contained in:
@@ -18,7 +18,6 @@ import SearchRepository from "../../../core/platform/services/search/repository"
|
|||||||
import assert from "assert";
|
import assert from "assert";
|
||||||
|
|
||||||
import gr from "../../global-resolver";
|
import gr from "../../global-resolver";
|
||||||
import { InternalToHooksProcessor } from "./internal-event-to-hooks";
|
|
||||||
|
|
||||||
export class ApplicationServiceImpl implements TwakeServiceProvider, Initializable {
|
export class ApplicationServiceImpl implements TwakeServiceProvider, Initializable {
|
||||||
version: "1";
|
version: "1";
|
||||||
@@ -37,8 +36,6 @@ export class ApplicationServiceImpl implements TwakeServiceProvider, Initializab
|
|||||||
logger.error("Error while initializing applications service");
|
logger.error("Error while initializing applications service");
|
||||||
}
|
}
|
||||||
|
|
||||||
gr.platformServices.messageQueue.processor.addHandler(new InternalToHooksProcessor());
|
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,64 +0,0 @@
|
|||||||
import { logger } from "../../../core/platform/framework";
|
|
||||||
import { HookType } from "../../applications-api/types";
|
|
||||||
import { MessageQueueHandler } from "../../../core/platform/services/message-queue/api";
|
|
||||||
import { MessageHook } from "../../messages/types";
|
|
||||||
import gr from "../../global-resolver";
|
|
||||||
import { ExecutionContext } from "../../../core/platform/framework/api/crud-service";
|
|
||||||
|
|
||||||
export class InternalToHooksProcessor implements MessageQueueHandler<MessageHook, void> {
|
|
||||||
readonly topics = {
|
|
||||||
in: "application:hook:message",
|
|
||||||
};
|
|
||||||
|
|
||||||
readonly options = {
|
|
||||||
unique: true,
|
|
||||||
ack: true,
|
|
||||||
queue: "application:hook:message:consumer1",
|
|
||||||
};
|
|
||||||
|
|
||||||
readonly name = "Application::InternalToHooksProcessor";
|
|
||||||
|
|
||||||
validate(_: HookType): boolean {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
async process(message: HookType, context?: ExecutionContext): Promise<void> {
|
|
||||||
logger.debug(`${this.name} - Receive hook of type ${message.type}`);
|
|
||||||
|
|
||||||
const application = await gr.services.applications.marketplaceApps.get(
|
|
||||||
{
|
|
||||||
id: message.application_id,
|
|
||||||
},
|
|
||||||
context,
|
|
||||||
);
|
|
||||||
|
|
||||||
//TODO Check application access rights (hooks)
|
|
||||||
const _access = application.access;
|
|
||||||
|
|
||||||
// Check application still exists in the company
|
|
||||||
if (
|
|
||||||
!(await gr.services.applications.companyApps.get({
|
|
||||||
company_id: message.company_id,
|
|
||||||
application_id: message.application_id,
|
|
||||||
id: undefined,
|
|
||||||
}))
|
|
||||||
) {
|
|
||||||
logger.error(
|
|
||||||
`${this.name} - Application ${message.application_id} not found in company ${message.company_id}`,
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
await gr.services.applications.hooks.notifyApp(
|
|
||||||
message.application_id,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
"hook",
|
|
||||||
null,
|
|
||||||
{ message },
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
context,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -26,7 +26,6 @@ import {
|
|||||||
ChannelMemberType,
|
ChannelMemberType,
|
||||||
ChannelVisibility,
|
ChannelVisibility,
|
||||||
WorkspaceExecutionContext,
|
WorkspaceExecutionContext,
|
||||||
CompanyExecutionContext,
|
|
||||||
} from "../../types";
|
} from "../../types";
|
||||||
import { Channel, ResourceEventsPayload, User } from "../../../../utils/types";
|
import { Channel, ResourceEventsPayload, User } from "../../../../utils/types";
|
||||||
import { cloneDeep, isNil, omitBy } from "lodash";
|
import { cloneDeep, isNil, omitBy } from "lodash";
|
||||||
@@ -53,7 +52,7 @@ import { WorkspacePrimaryKey } from "../../../workspaces/entities/workspace";
|
|||||||
import gr from "../../../global-resolver";
|
import gr from "../../../global-resolver";
|
||||||
import uuidTime from "uuid-time";
|
import uuidTime from "uuid-time";
|
||||||
import { ChannelObject } from "../channel/types";
|
import { ChannelObject } from "../channel/types";
|
||||||
|
import { CompanyExecutionContext } from "../../../applications/web/types";
|
||||||
const USER_CHANNEL_KEYS = [
|
const USER_CHANNEL_KEYS = [
|
||||||
"id",
|
"id",
|
||||||
"company_id",
|
"company_id",
|
||||||
|
|||||||
@@ -52,7 +52,3 @@ export type ChannelActivityNotification = {
|
|||||||
sender_name: string;
|
sender_name: string;
|
||||||
body: string;
|
body: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export interface CompanyExecutionContext extends ExecutionContext {
|
|
||||||
company: { id: string };
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -25,6 +25,8 @@ import { UserExternalLinksServiceImpl } from "./user/services/external_links";
|
|||||||
import { UserNotificationBadgeService } from "./notifications/services/bages";
|
import { UserNotificationBadgeService } from "./notifications/services/bages";
|
||||||
import { NotificationPreferencesService } from "./notifications/services/preferences";
|
import { NotificationPreferencesService } from "./notifications/services/preferences";
|
||||||
import { UserServiceImpl } from "./user/services/users/service";
|
import { UserServiceImpl } from "./user/services/users/service";
|
||||||
|
import { CompanyApplicationServiceImpl } from "./applications/services/company-applications";
|
||||||
|
import { ApplicationServiceImpl } from "./applications/services/applications";
|
||||||
import { FileServiceImpl } from "./files/services";
|
import { FileServiceImpl } from "./files/services";
|
||||||
import { ChannelServiceImpl } from "./channels/services/channel/service";
|
import { ChannelServiceImpl } from "./channels/services/channel/service";
|
||||||
import { MemberServiceImpl } from "./channels/services/member/service";
|
import { MemberServiceImpl } from "./channels/services/member/service";
|
||||||
@@ -36,6 +38,7 @@ import { NotificationEngine } from "./notifications/services/engine";
|
|||||||
import { MobilePushService } from "./notifications/services/mobile-push";
|
import { MobilePushService } from "./notifications/services/mobile-push";
|
||||||
import { ChannelMemberPreferencesServiceImpl } from "./notifications/services/channel-preferences";
|
import { ChannelMemberPreferencesServiceImpl } from "./notifications/services/channel-preferences";
|
||||||
import { ChannelThreadUsersServiceImpl } from "./notifications/services/channel-thread-users";
|
import { ChannelThreadUsersServiceImpl } from "./notifications/services/channel-thread-users";
|
||||||
|
import { ApplicationHooksService } from "./applications/services/hooks";
|
||||||
import OnlineServiceImpl from "./online/service";
|
import OnlineServiceImpl from "./online/service";
|
||||||
import { ChannelsMessageQueueListener } from "./channels/services/pubsub";
|
import { ChannelsMessageQueueListener } from "./channels/services/pubsub";
|
||||||
import { UserNotificationDigestService } from "./notifications/services/digest";
|
import { UserNotificationDigestService } from "./notifications/services/digest";
|
||||||
@@ -75,6 +78,11 @@ type TwakeServices = {
|
|||||||
mobilePush: MobilePushService;
|
mobilePush: MobilePushService;
|
||||||
digest: UserNotificationDigestService;
|
digest: UserNotificationDigestService;
|
||||||
};
|
};
|
||||||
|
applications: {
|
||||||
|
marketplaceApps: ApplicationServiceImpl;
|
||||||
|
companyApps: CompanyApplicationServiceImpl;
|
||||||
|
hooks: ApplicationHooksService;
|
||||||
|
};
|
||||||
files: FileServiceImpl;
|
files: FileServiceImpl;
|
||||||
channels: {
|
channels: {
|
||||||
channels: ChannelServiceImpl;
|
channels: ChannelServiceImpl;
|
||||||
@@ -145,6 +153,11 @@ class GlobalResolver {
|
|||||||
mobilePush: await new MobilePushService().init(),
|
mobilePush: await new MobilePushService().init(),
|
||||||
digest: await new UserNotificationDigestService().init(),
|
digest: await new UserNotificationDigestService().init(),
|
||||||
},
|
},
|
||||||
|
applications: {
|
||||||
|
marketplaceApps: await new ApplicationServiceImpl().init(),
|
||||||
|
companyApps: await new CompanyApplicationServiceImpl().init(),
|
||||||
|
hooks: await new ApplicationHooksService().init(),
|
||||||
|
},
|
||||||
files: await new FileServiceImpl().init(),
|
files: await new FileServiceImpl().init(),
|
||||||
channels: {
|
channels: {
|
||||||
channels: await new ChannelServiceImpl().init(),
|
channels: await new ChannelServiceImpl().init(),
|
||||||
|
|||||||
Reference in New Issue
Block a user