cordova-plugin-ymchat 2.2.0 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -56,6 +56,12 @@ public class YmChatCordova extends CordovaPlugin {
|
|
|
56
56
|
case "unlinkDeviceToken":
|
|
57
57
|
unlinkDeviceToken(args, callbackContext);
|
|
58
58
|
return true;
|
|
59
|
+
case "registerDevice":
|
|
60
|
+
registerDevice(args, callbackContext);
|
|
61
|
+
return true;
|
|
62
|
+
case "getUnreadMessagesCount":
|
|
63
|
+
getUnreadMessagesCount(callbackContext);
|
|
64
|
+
return true;
|
|
59
65
|
case "setVersion":
|
|
60
66
|
setVersion(args,callbackContext);
|
|
61
67
|
return true;
|
|
@@ -205,10 +211,25 @@ public class YmChatCordova extends CordovaPlugin {
|
|
|
205
211
|
|
|
206
212
|
private void unlinkDeviceToken(JSONArray args, CallbackContext callbackContext) {
|
|
207
213
|
try {
|
|
208
|
-
String
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
214
|
+
String apiKey = args.getString(0);
|
|
215
|
+
ymChatService.unlinkDeviceToken(apiKey, callbackContext);
|
|
216
|
+
} catch (Exception e) {
|
|
217
|
+
Utils.genericErrorHelper(e, callbackContext);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
private void registerDevice(JSONArray args, CallbackContext callbackContext) {
|
|
222
|
+
try {
|
|
223
|
+
String apiKey = args.getString(0);
|
|
224
|
+
ymChatService.registerDevice(apiKey, result);
|
|
225
|
+
} catch (Exception e) {
|
|
226
|
+
Utils.genericErrorHelper(e, callbackContext);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
private void getUnreadMessagesCount(CallbackContext callbackContext) {
|
|
231
|
+
try {
|
|
232
|
+
ymChatService.getUnreadMessagesCount(result);
|
|
212
233
|
} catch (Exception e) {
|
|
213
234
|
Utils.genericErrorHelper(e, callbackContext);
|
|
214
235
|
}
|
|
@@ -105,9 +105,9 @@ public class YmChatService {
|
|
|
105
105
|
});
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
-
public void unlinkDeviceToken(String
|
|
108
|
+
public void unlinkDeviceToken(String apiKey, CallbackContext callbackContext) {
|
|
109
109
|
try{
|
|
110
|
-
ymChat.unlinkDeviceToken(
|
|
110
|
+
ymChat.unlinkDeviceToken(apiKey, ymChat.config, new YellowCallback() {
|
|
111
111
|
@Override
|
|
112
112
|
public void success() {
|
|
113
113
|
callbackContext.success();
|
|
@@ -125,6 +125,47 @@ public class YmChatService {
|
|
|
125
125
|
}
|
|
126
126
|
}
|
|
127
127
|
|
|
128
|
+
public void registerDevice(String apiKey, CallbackContext callbackContext) {
|
|
129
|
+
try{
|
|
130
|
+
ymChat.registerDevice(apiKey, ymChat.config, new YellowCallback() {
|
|
131
|
+
@Override
|
|
132
|
+
public void success() {
|
|
133
|
+
callbackContext.success();
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
@Override
|
|
137
|
+
public void failure(String message) {
|
|
138
|
+
Utils.genericErrorHelper(new Exception(),callbackContext);
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
catch (Exception e)
|
|
143
|
+
{
|
|
144
|
+
Utils.genericErrorHelper(e, callbackContext);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
public void getUnreadMessagesCount(CallbackContext callbackContext) {
|
|
149
|
+
try{
|
|
150
|
+
ymChat.getUnreadMessagesCount(ymChat.config, new YellowCallback() {
|
|
151
|
+
@Override
|
|
152
|
+
public <T> void success(T data) {
|
|
153
|
+
YellowUnreadMessageResponse response = (YellowUnreadMessageResponse) data;
|
|
154
|
+
callbackContext.success(response.getUnreadCount());
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
@Override
|
|
158
|
+
public void failure(String message) {
|
|
159
|
+
Utils.genericErrorHelper(new Exception(),callbackContext);
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
catch (Exception e)
|
|
164
|
+
{
|
|
165
|
+
Utils.genericErrorHelper(e, callbackContext);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
128
169
|
public void setVersion(int version, CallbackContext callbackContext) {
|
|
129
170
|
ymChat.config.version = version;
|
|
130
171
|
}
|
package/src/ios/ymchat.m
CHANGED
|
@@ -95,7 +95,11 @@
|
|
|
95
95
|
|
|
96
96
|
- (void)onEventFromBotWithResponse:(YMBotEventResponse *)response {
|
|
97
97
|
CDVPluginResult* pluginResult = nil;
|
|
98
|
-
|
|
98
|
+
NSMutableDictionary *event = [[NSMutableDictionary alloc]initWithCapacity:10];
|
|
99
|
+
[event setObject:response.code forKey:@"code"];
|
|
100
|
+
if(response.data){
|
|
101
|
+
[event setObject:response.data forKey:@"data"];
|
|
102
|
+
}
|
|
99
103
|
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:event];
|
|
100
104
|
[pluginResult setKeepCallbackAsBool:YES];
|
|
101
105
|
[self.commandDelegate sendPluginResult:pluginResult callbackId:onEvent.callbackId];
|
|
@@ -116,18 +120,59 @@
|
|
|
116
120
|
}
|
|
117
121
|
|
|
118
122
|
- (void) unlinkDeviceToken:(CDVInvokedUrlCommand*)command {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
+
if(YMChat.shared.config) {
|
|
124
|
+
NSString* apiKey = [command.arguments objectAtIndex:0];
|
|
125
|
+
[[YMChat shared] unlinkDeviceTokenWithApiKey:apiKey ymConfig:YMChat.shared.config success:^{
|
|
126
|
+
CDVPluginResult* pluginResult = nil;
|
|
127
|
+
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
|
|
128
|
+
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
|
129
|
+
} failure:^(NSString * _Nonnull failureMessage) {
|
|
130
|
+
CDVPluginResult* pluginResult = nil;
|
|
131
|
+
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:failureMessage];
|
|
132
|
+
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
|
133
|
+
}];
|
|
134
|
+
} else {
|
|
135
|
+
CDVPluginResult* pluginResult = nil;
|
|
136
|
+
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Bot id not found"];
|
|
137
|
+
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
- (void) registerDevice:(CDVInvokedUrlCommand*)command {
|
|
142
|
+
NSString* apiKey = [command.arguments objectAtIndex:0];
|
|
143
|
+
if(YMChat.shared.config) {
|
|
144
|
+
[[YMChat shared] registerDeviceWithApiKey:apiKey ymConfig:YMChat.shared.config success:^{
|
|
145
|
+
CDVPluginResult* pluginResult = nil;
|
|
146
|
+
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
|
|
147
|
+
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
|
148
|
+
} failure:^(NSString * _Nonnull failureMessage) {
|
|
149
|
+
CDVPluginResult* pluginResult = nil;
|
|
150
|
+
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:failureMessage];
|
|
151
|
+
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
|
152
|
+
}];
|
|
153
|
+
} else {
|
|
123
154
|
CDVPluginResult* pluginResult = nil;
|
|
124
|
-
pluginResult = [CDVPluginResult resultWithStatus:
|
|
155
|
+
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Bot id not found"];
|
|
125
156
|
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
|
126
|
-
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
- (void) getUnreadMessagesCount:(CDVInvokedUrlCommand*)command {
|
|
161
|
+
if(YMChat.shared.config) {
|
|
162
|
+
[[YMChat shared] getUnreadMessagesCountWithYmConfig:YMChat.shared.config success:^(NSString * _Nonnull unreadCount) {
|
|
163
|
+
CDVPluginResult* pluginResult = nil;
|
|
164
|
+
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:unreadCount];
|
|
165
|
+
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
|
166
|
+
} failure:^(NSString * _Nonnull failureMessage) {
|
|
167
|
+
CDVPluginResult* pluginResult = nil;
|
|
168
|
+
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:failureMessage];
|
|
169
|
+
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
|
170
|
+
}];
|
|
171
|
+
} else {
|
|
127
172
|
CDVPluginResult* pluginResult = nil;
|
|
128
|
-
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString
|
|
173
|
+
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Bot id not found"];
|
|
129
174
|
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
|
130
|
-
}
|
|
175
|
+
}
|
|
131
176
|
}
|
|
132
177
|
|
|
133
178
|
- (void)setCustomLoaderURL:(CDVInvokedUrlCommand*)command
|
package/www/ymchat.js
CHANGED
|
@@ -35,8 +35,14 @@ const YmChatAPI = {
|
|
|
35
35
|
closeBot: () => {
|
|
36
36
|
exec(null, null, "ymchat", "closeBot", []);
|
|
37
37
|
},
|
|
38
|
-
unlinkDeviceToken: (
|
|
39
|
-
exec(success, failure, "ymchat", "unlinkDeviceToken", [
|
|
38
|
+
unlinkDeviceToken: (apiKey, success, failure) => {
|
|
39
|
+
exec(success, failure, "ymchat", "unlinkDeviceToken", [apiKey])
|
|
40
|
+
},
|
|
41
|
+
registerDevice: (apiKey, success, failure) => {
|
|
42
|
+
exec(success, failure, "ymchat", "registerDevice", [apiKey])
|
|
43
|
+
},
|
|
44
|
+
getUnreadMessagesCount: (success, failure) => {
|
|
45
|
+
exec(success, failure, "ymchat", "getUnreadMessagesCount", [])
|
|
40
46
|
},
|
|
41
47
|
setVersion: (version) => {
|
|
42
48
|
exec(null, null, "ymchat", "setVersion", [version])
|