specify protocol in channel plugin list

This commit is contained in:
Evert Prants 2020-12-05 13:21:56 +02:00
parent accf789b2a
commit b4aa431223
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
2 changed files with 15 additions and 12 deletions

View File

@ -8,8 +8,6 @@ export interface IChannel {
enabled: boolean;
}
// TODO: Source specification to support plugin services.
export class ChannelManager {
private channels: IChannel[] = [];
@ -39,14 +37,15 @@ export class ChannelManager {
return;
}
const source = plugin.manifest.name;
const emitTo = this.getChannelsByPluginName(source);
const emitTo = this.getChannelsByPluginName(source, data.source);
for (const chan of emitTo) {
if (chan.plugins.length < 2) {
continue;
}
for (const pl of chan.plugins) {
if (pl !== source) {
this.stream.emitTo(pl, event, data);
if (pl !== source &&
!(pl.indexOf('/') !== -1 && pl.split('/')[0] === source)) {
this.stream.emitTo(pl, event, data, chan);
}
}
}
@ -54,14 +53,21 @@ export class ChannelManager {
}
}
private getChannelsByPluginName(plugin: string): IChannel[] {
private getChannelsByPluginName(plugin: string, source: Protocol): IChannel[] {
const list = [];
for (const chan of this.channels) {
if (chan.enabled === false) {
continue;
}
if (chan.plugins.indexOf(plugin) !== -1) {
list.push(chan);
for (const pl of chan.plugins) {
if (pl.indexOf('/') !== -1) {
const split = pl.split('/');
if (split[0] === plugin && split[1] === source.name) {
list.push(chan);
}
} else if (pl === plugin) {
list.push(chan);
}
}
}
return list;

View File

@ -1,3 +1,4 @@
import { IChannel } from '../channel';
import { Protocol } from './protocol';
export enum EMessageType {
@ -90,8 +91,4 @@ export interface IMessage {
* @param target UserTarget to mention (i.e. `msg.sender`)
*/
mention(target: IMessageTarget): string;
kick?(reason: string): void;
ban?(reason: string): void;
mute?(reason: string): void;
}