Skip to content

Commit

Permalink
fix: fix getui.service cannot get client problem
Browse files Browse the repository at this point in the history
  • Loading branch information
moonrailgun committed Mar 30, 2023
1 parent 70f98c5 commit a245373
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions server/plugins/com.msgbyte.getui/services/getui.service.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { RequestError } from 'got';
import { TcService, TcDbService, InboxStruct, call } from 'tailchat-server-sdk';
import { GetuiClient } from '../lib/GetuiClient';
import type { GetuiLogDocument, GetuiLogModel } from '../models/log';
Expand All @@ -9,8 +10,6 @@ interface GetuiService
extends TcService,
TcDbService<GetuiLogDocument, GetuiLogModel> {}
class GetuiService extends TcService {
client: GetuiClient = null;

get serviceName() {
return 'plugin:com.msgbyte.getui';
}
Expand Down Expand Up @@ -40,7 +39,8 @@ class GetuiService extends TcService {
return;
}

this.initClient();
const { appId, appKey, masterSecert } = this.getuiInfo;
const client = new GetuiClient(appId, appKey, masterSecert);

this.registerLocalDb(require('../models/log').default);
this.registerEventListener(
Expand All @@ -62,7 +62,7 @@ class GetuiService extends TcService {
};

try {
await this.client.singlePush(userId, title, content, payload);
await client.singlePush(userId, title, content, payload);
await this.adapter.model.create({
userId,
title,
Expand All @@ -71,24 +71,24 @@ class GetuiService extends TcService {
success: true,
});
} catch (err) {
let errorMsg = String(err);

if (err instanceof RequestError && err.response) {
errorMsg = String(err.response.body);
}
await this.adapter.model.create({
userId,
title,
content,
payload,
success: false,
errorMsg: String(err),
errorMsg,
});
}
}
}
);
}

initClient() {
const { appId, appKey, masterSecert } = this.getuiInfo;
this.client = new GetuiClient(appId, appKey, masterSecert);
}
}

export default GetuiService;

0 comments on commit a245373

Please sign in to comment.