mirror of
https://github.com/turt2live/matrix-dimension.git
synced 2024-08-31 06:02:09 +00:00
Automatic refresh of IRC links
This commit is contained in:
parent
76ebdf043c
commit
3426429105
@ -25,6 +25,7 @@ class DimensionApi {
|
||||
app.get("/api/v1/dimension/integrations/:roomId", this._getIntegrations.bind(this));
|
||||
app.delete("/api/v1/dimension/integrations/:roomId/:type/:integrationType", this._removeIntegration.bind(this));
|
||||
app.put("/api/v1/dimension/integrations/:roomId/:type/:integrationType/state", this._updateIntegrationState.bind(this));
|
||||
app.get("/api/v1/dimension/integrations/:roomId/:type/:integrationType/state", this._getIntegrationState.bind(this));
|
||||
}
|
||||
|
||||
_getIntegration(integrationConfig, roomId, scalarToken) {
|
||||
@ -137,6 +138,38 @@ class DimensionApi {
|
||||
res.status(500).send({error: err.message});
|
||||
});
|
||||
}
|
||||
|
||||
_getIntegrationState(req, res) {
|
||||
var roomId = req.params.roomId;
|
||||
var scalarToken = req.query.scalar_token;
|
||||
var type = req.params.type;
|
||||
var integrationType = req.params.integrationType;
|
||||
|
||||
if (!roomId || !scalarToken || !type || !integrationType) {
|
||||
res.status(400).send({error: "Missing room, integration type, type, or token"});
|
||||
return;
|
||||
}
|
||||
|
||||
var integrationConfig = Integrations.byType[type][integrationType];
|
||||
if (!integrationConfig) {
|
||||
res.status(400).send({error: "Unknown integration"});
|
||||
return;
|
||||
}
|
||||
|
||||
log.info("DimensionApi", "State requested for " + type + " (" + integrationType + ") in room " + roomId);
|
||||
|
||||
this._db.checkToken(scalarToken).then(() => {
|
||||
return this._getIntegration(integrationConfig, roomId, scalarToken);
|
||||
}).then(integration => {
|
||||
return integration.getState();
|
||||
}).then(state => {
|
||||
res.status(200).send(state);
|
||||
}).catch(err => {
|
||||
log.error("DimensionApi", err);
|
||||
console.error(err);
|
||||
res.status(500).send({error: err.message});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = new DimensionApi();
|
||||
|
@ -1,16 +1,19 @@
|
||||
import { Component } from "@angular/core";
|
||||
import { Component, OnDestroy } from "@angular/core";
|
||||
import { IRCIntegration } from "../../shared/models/integration";
|
||||
import { ModalComponent, DialogRef } from "angular2-modal";
|
||||
import { ConfigModalContext } from "../../integration/integration.component";
|
||||
import { IrcApiService } from "../../shared/irc-api.service";
|
||||
import { ToasterService } from "angular2-toaster";
|
||||
import { IntervalObservable } from "rxjs/observable/IntervalObservable";
|
||||
import { ApiService } from "../../shared/api.service";
|
||||
import { Subscription } from "rxjs";
|
||||
|
||||
@Component({
|
||||
selector: 'my-irc-config',
|
||||
templateUrl: './irc-config.component.html',
|
||||
styleUrls: ['./irc-config.component.scss', './../config.component.scss'],
|
||||
})
|
||||
export class IrcConfigComponent implements ModalComponent<ConfigModalContext> {
|
||||
export class IrcConfigComponent implements ModalComponent<ConfigModalContext>, OnDestroy {
|
||||
|
||||
public integration: IRCIntegration;
|
||||
public loadingOps = false;
|
||||
@ -27,18 +30,32 @@ export class IrcConfigComponent implements ModalComponent<ConfigModalContext> {
|
||||
|
||||
private roomId: string;
|
||||
private scalarToken: string;
|
||||
private stateTimer: Subscription;
|
||||
|
||||
constructor(public dialog: DialogRef<ConfigModalContext>,
|
||||
private ircApi: IrcApiService,
|
||||
private toaster: ToasterService,
|
||||
// private api: ApiService
|
||||
) {
|
||||
private api: ApiService) {
|
||||
this.integration = <IRCIntegration>dialog.context.integration;
|
||||
this.roomId = dialog.context.roomId;
|
||||
this.scalarToken = dialog.context.scalarToken;
|
||||
|
||||
this.newChannel.network = this.integration.availableNetworks[0].id;
|
||||
this.buildChannelLinks();
|
||||
|
||||
this.stateTimer = IntervalObservable.create(5000).subscribe(() => {
|
||||
this.api.getIntegrationState(this.roomId, this.integration.type, this.integration.integrationType, this.scalarToken)
|
||||
.then(state => {
|
||||
for (let key in state) {
|
||||
this.integration[key] = state[key];
|
||||
}
|
||||
this.buildChannelLinks();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public ngOnDestroy(): void {
|
||||
this.stateTimer.unsubscribe();
|
||||
}
|
||||
|
||||
public checkOps(): void {
|
||||
|
@ -28,4 +28,10 @@ export class ApiService {
|
||||
return this.http.put(url, {scalar_token: scalarToken, state: newState})
|
||||
.map(res => res.json()).toPromise();
|
||||
}
|
||||
|
||||
getIntegrationState(roomId: string, type: string, integrationType: string, scalarToken: string): Promise<any> {
|
||||
const url = "/api/v1/dimension/integrations/" + roomId + "/" + type + "/" + integrationType + "/state";
|
||||
return this.http.get(url, {params: {scalar_token: scalarToken}})
|
||||
.map(res => res.json()).toPromise();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user