Skip to content

Commit

Permalink
Limit tags size #16
Browse files Browse the repository at this point in the history
Limit tags size
  • Loading branch information
debiff authored Feb 4, 2022
2 parents 934f72b + d6df7d3 commit 627da75
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReadableMap;
import com.zendesk.logger.Logger;
import com.zendesk.service.ErrorResponse;
import com.zendesk.service.ZendeskCallback;

Expand All @@ -29,7 +28,6 @@
import zendesk.chat.PushNotificationsProvider;
import zendesk.chat.Providers;
import zendesk.chat.VisitorInfo;
import zendesk.configurations.Configuration;
import zendesk.core.JwtIdentity;
import zendesk.core.AnonymousIdentity;
import zendesk.core.Identity;
Expand All @@ -51,6 +49,7 @@ public class RNZendeskChat extends ReactContextBaseJavaModule {

private ReactContext appContext;
private static final String TAG = "ZendeskChat";
private static final int MAX_TAGS_SIZE = 100;
private final HashMap<String, CustomField> customFields;
private final ArrayList<String> tags;
// Contains the aggregate of all the logs sent by the app
Expand Down Expand Up @@ -149,7 +148,6 @@ public void init(ReadableMap options) {

private void checkIdentity(){
Identity identity = Zendesk.INSTANCE.getIdentity();
Log.v(TAG,"identity: " + identity != null ? "not null" : "null");
}

@ReactMethod
Expand Down Expand Up @@ -197,7 +195,20 @@ public void addTicketCustomField(String key, String value){

@ReactMethod
public void addTicketTag(String tag){
this.tags.add(tag.replace(' ', '_'));
tag = tag.replace(' ', '_');
// avoid duplicates
if(this.tags.contains(tag)){
return;
}
// append to tail
this.tags.add(tag);
int elementsToRemove = this.tags.size() - MAX_TAGS_SIZE;
int i = 0;
while(i < elementsToRemove){
// remove from head
this.tags.remove(0);
i++;
}
}

@ReactMethod
Expand Down
14 changes: 14 additions & 0 deletions ios/RNZendeskChat.m
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ @implementation RNZendeskChat
#ifndef MAX_LOG_LENGTH
#define MAX_LOG_LENGTH 60000
#endif
#ifndef MAX_TAGS_LENGTH
#define MAX_TAGS_LENGTH 100
#endif

RCT_EXPORT_METHOD(reset) {
[self initGlobals];
Expand Down Expand Up @@ -115,7 +118,18 @@ - (void) addTicketTagFunction:(NSString *)tag
{
NSString * snakeTag = [tag stringByReplacingOccurrencesOfString:@" "
withString:@"_"];
// avoid duplicates
if([tags containsObject:snakeTag]){
return;
}
[tags addObject:snakeTag];
int elementsToRemove = (int)tags.count - MAX_TAGS_LENGTH;
int i = 0;
while(i < elementsToRemove){
[tags removeObjectAtIndex:0];
i++;
}

}
RCT_EXPORT_METHOD(addTicketTag:(NSString *)tag) {
[self initGlobals];
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "io-react-native-zendesk",
"version": "0.3.15",
"version": "0.3.16",
"description": "React native wrapper for Zendesk Unified SDK",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 627da75

Please sign in to comment.