2018-03-25 23:01:05 -04:00
|
|
|
import { ComplexBotComponent } from "../complex-bot.component";
|
|
|
|
import { Component } from "@angular/core";
|
2018-03-26 23:48:44 -04:00
|
|
|
import { SessionStorage } from "../../../shared/SessionStorage";
|
2018-03-25 23:01:05 -04:00
|
|
|
|
|
|
|
interface RssConfig {
|
|
|
|
feeds: {
|
2018-03-26 23:48:44 -04:00
|
|
|
[feedUrl: string]: {
|
|
|
|
addedByUserId: string;
|
|
|
|
};
|
2018-03-25 23:01:05 -04:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-03-26 23:48:44 -04:00
|
|
|
interface LocalFeed {
|
|
|
|
url: string;
|
|
|
|
addedByUserId: string;
|
|
|
|
isSelf: boolean;
|
|
|
|
}
|
|
|
|
|
2018-03-25 23:01:05 -04:00
|
|
|
@Component({
|
|
|
|
templateUrl: "rss.complex-bot.component.html",
|
|
|
|
styleUrls: ["rss.complex-bot.component.scss"],
|
|
|
|
})
|
|
|
|
export class RssComplexBotConfigComponent extends ComplexBotComponent<RssConfig> {
|
2018-03-26 23:48:44 -04:00
|
|
|
|
|
|
|
public newFeedUrl = "";
|
|
|
|
|
2018-03-25 23:01:05 -04:00
|
|
|
constructor() {
|
|
|
|
super("rss");
|
|
|
|
}
|
2018-03-26 23:48:44 -04:00
|
|
|
|
|
|
|
public addFeed(): void {
|
|
|
|
if (!this.newFeedUrl.trim()) {
|
|
|
|
this.toaster.pop('warning', 'Please enter a feed URL');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.newConfig.feeds[this.newFeedUrl] = {addedByUserId: SessionStorage.userId};
|
|
|
|
this.newFeedUrl = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
public getFeeds(): LocalFeed[] {
|
|
|
|
if (!this.newConfig.feeds) this.newConfig.feeds = {};
|
|
|
|
return Object.keys(this.newConfig.feeds).map(url => {
|
|
|
|
return {
|
|
|
|
url: url,
|
|
|
|
addedByUserId: this.newConfig.feeds[url].addedByUserId,
|
|
|
|
isSelf: SessionStorage.userId === this.newConfig.feeds[url].addedByUserId,
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public removeFeed(feed: LocalFeed): void {
|
|
|
|
delete this.newConfig.feeds[feed.url];
|
|
|
|
}
|
|
|
|
|
|
|
|
public async interceptSave(): Promise<any> {
|
|
|
|
const memberEvent = await this.scalarClientApi.getMembershipState(this.roomId, this.bot.notificationUserId);
|
|
|
|
const isJoined = memberEvent && memberEvent.response && ["join", "invite"].indexOf(memberEvent.response.membership) !== -1;
|
|
|
|
|
|
|
|
if (!isJoined) {
|
|
|
|
await this.scalarClientApi.inviteUser(this.roomId, this.bot.notificationUserId);
|
|
|
|
}
|
|
|
|
|
|
|
|
super.save();
|
|
|
|
}
|
2018-03-25 23:01:05 -04:00
|
|
|
}
|