#import "CustomUI.h"
#import <MessageSDKFramework/CometChat.h>
#import <MessageSDKFramework/CometChatChatroom.h>


@implementation CustomUI{
    CometChat *cometchat;
    CometChatChatroom *cometChatroom;

}

- (void)seturl:(CDVInvokedUrlCommand*)command{

    [[NSUserDefaults standardUserDefaults] setObject:[NSString stringWithFormat:@"%@",[[command arguments] objectAtIndex:0]] forKey:@"siteurl"];

    [self.commandDelegate sendPluginResult:[CDVPluginResult
                                            resultWithStatus:CDVCommandStatus_OK messageAsString:[[command arguments] objectAtIndex:0]] callbackId:command.callbackId];
}

- (void)loginUsername:(CDVInvokedUrlCommand*)command{

    cometchat = [[CometChat alloc] init];

    [cometchat loginWithURL:[[NSUserDefaults standardUserDefaults] objectForKey:@"siteurl"] username:[NSString stringWithFormat:@"%@",[[command arguments] objectAtIndex:0]] password:[NSString stringWithFormat:@"%@",[[command arguments] objectAtIndex:1]] success:^(NSDictionary *response) {
        NSDictionary *successDict = @{@"success":response};
        NSLog(@"login success");
        [self.commandDelegate sendPluginResult:[CDVPluginResult
                                                resultWithStatus:CDVCommandStatus_OK messageAsDictionary:successDict] callbackId:command.callbackId];
    } failure:^(NSError *error) {
        NSDictionary *errorDict = @{@"error":error};
        NSLog(@"login error");
        [self.commandDelegate sendPluginResult:[CDVPluginResult
                                                resultWithStatus:CDVCommandStatus_OK messageAsDictionary:errorDict] callbackId:command.callbackId];
    }];

}

- (void)loginUserid:(CDVInvokedUrlCommand*)command{

    cometchat = [[CometChat alloc] init];

    [cometchat loginWithURL:[[NSUserDefaults standardUserDefaults] objectForKey:@"siteurl"] userID:[NSString stringWithFormat:@"%@",[[command arguments] objectAtIndex:0]] success:^(NSDictionary *response) {

        NSDictionary *successDict = @{@"success":response};
        [self.commandDelegate sendPluginResult:[CDVPluginResult
                                                resultWithStatus:CDVCommandStatus_OK messageAsDictionary:successDict] callbackId:command.callbackId];
    } failure:^(NSError *error) {

        NSDictionary *errorDict = @{@"error":error};
        [self.commandDelegate sendPluginResult:[CDVPluginResult
                                                resultWithStatus:CDVCommandStatus_OK messageAsDictionary:errorDict] callbackId:command.callbackId];
    }];
}

- (void)guestLogin:(CDVInvokedUrlCommand*)command{

    cometchat = [[CometChat alloc] init];
    [cometchat guestLoginWithURL:[[NSUserDefaults standardUserDefaults] objectForKey:@"siteurl"] name:[NSString stringWithFormat:@"%@",[[command arguments] objectAtIndex:0]] success:^(NSDictionary *response) {

        NSDictionary *successDict = @{@"success":response};
        [self.commandDelegate sendPluginResult:[CDVPluginResult
                                                resultWithStatus:CDVCommandStatus_OK messageAsDictionary:successDict] callbackId:command.callbackId];

    } failure:^(NSError *error) {

        NSDictionary *errorDict = @{@"error":error};
        [self.commandDelegate sendPluginResult:[CDVPluginResult
                                                resultWithStatus:CDVCommandStatus_OK messageAsDictionary:errorDict] callbackId:command.callbackId];

    }];

}

- (void)setCometChatURL:(CDVInvokedUrlCommand*)command{

    cometchat = [[CometChat alloc] init];
    [cometchat setCometChatURL:[NSString stringWithFormat:@"%@",[[command arguments] objectAtIndex:0]]];

}

- (void)createUser:(CDVInvokedUrlCommand*)command{

    cometchat = [[CometChat alloc] initWithAPIKey:[NSString stringWithFormat:@"%@",[[command arguments] objectAtIndex:0]]];
    [cometchat createUser:[NSString stringWithFormat:@"%@",[[command arguments] objectAtIndex:1]] password:[NSString stringWithFormat:@"%@",[[command arguments] objectAtIndex:2]] link:[NSString stringWithFormat:@"%@",[[command arguments] objectAtIndex:3]] avatar:[NSString stringWithFormat:@"%@",[[command arguments] objectAtIndex:4]] displayName:[NSString stringWithFormat:@"%@",[[command arguments] objectAtIndex:5]] success:^(NSDictionary *response) {

        NSDictionary *successDict = @{@"success":response};
        [self.commandDelegate sendPluginResult:[CDVPluginResult
                                                resultWithStatus:CDVCommandStatus_OK messageAsDictionary:successDict] callbackId:command.callbackId];

    } failure:^(NSError *error) {

        NSDictionary *errorDict = @{@"error":error};
        [self.commandDelegate sendPluginResult:[CDVPluginResult
                                                resultWithStatus:CDVCommandStatus_OK messageAsDictionary:errorDict] callbackId:command.callbackId];

    }];

}

- (void)removeUserByID:(CDVInvokedUrlCommand*)command{

    cometchat = [[CometChat alloc] initWithAPIKey:[NSString stringWithFormat:@"%@",[[command arguments] objectAtIndex:0]]];
    [cometchat removeUserByID:[NSString stringWithFormat:@"%@",[[command arguments] objectAtIndex:1]] success:^(NSDictionary *response) {

        NSDictionary *successDict = @{@"success":response};
        [self.commandDelegate sendPluginResult:[CDVPluginResult
                                                resultWithStatus:CDVCommandStatus_OK messageAsDictionary:successDict] callbackId:command.callbackId];

    } failure:^(NSError *error) {

        NSDictionary *errorDict = @{@"error":error};
        [self.commandDelegate sendPluginResult:[CDVPluginResult
                                                resultWithStatus:CDVCommandStatus_OK messageAsDictionary:errorDict] callbackId:command.callbackId];

    }];
}

- (void)updateDisplayName:(CDVInvokedUrlCommand*)command{

    cometchat = [[CometChat alloc] initWithAPIKey:[NSString stringWithFormat:@"%@",[[command arguments] objectAtIndex:0]]];
    [cometchat updateDisplayName:[NSString stringWithFormat:@"%@",[[command arguments] objectAtIndex:1]] password:[NSString stringWithFormat:@"%@",[[command arguments] objectAtIndex:2]] link:[NSString stringWithFormat:@"%@",[[command arguments] objectAtIndex:3]] avatar:[NSString stringWithFormat:@"%@",[[command arguments] objectAtIndex:4]] ofUser:[NSString stringWithFormat:@"%@",[[command arguments] objectAtIndex:5]] withPassword:[NSString stringWithFormat:@"%@",[[command arguments] objectAtIndex:6]] setNULLValues:[NSString stringWithFormat:@"%@",[[command arguments] objectAtIndex:7]] success:^(NSDictionary *response) {

        NSDictionary *successDict = @{@"success":response};
        [self.commandDelegate sendPluginResult:[CDVPluginResult
                                                resultWithStatus:CDVCommandStatus_OK messageAsDictionary:successDict] callbackId:command.callbackId];

    } failure:^(NSError *error) {

        NSDictionary *errorDict = @{@"error":error};
        [self.commandDelegate sendPluginResult:[CDVPluginResult
                                                resultWithStatus:CDVCommandStatus_OK messageAsDictionary:errorDict] callbackId:command.callbackId];

    }];

}

- (void)addFriends:(CDVInvokedUrlCommand*)command{

    cometchat = [[CometChat alloc] initWithAPIKey:[NSString stringWithFormat:@"%@",[[command arguments] objectAtIndex:0]]];

    [cometchat addFriends:[[command arguments] objectAtIndex:1] success:^(NSDictionary *response) {

        NSDictionary *successDict = @{@"success":response};
        [self.commandDelegate sendPluginResult:[CDVPluginResult
                                                resultWithStatus:CDVCommandStatus_OK messageAsDictionary:successDict] callbackId:command.callbackId];

    } failure:^(NSError *error) {

        NSDictionary *errorDict = @{@"error":error};
        [self.commandDelegate sendPluginResult:[CDVPluginResult
                                                resultWithStatus:CDVCommandStatus_OK messageAsDictionary:errorDict] callbackId:command.callbackId];

    }];
}

- (void)removeFriends:(CDVInvokedUrlCommand*)command{

    cometchat = [[CometChat alloc] initWithAPIKey:[NSString stringWithFormat:@"%@",[[command arguments] objectAtIndex:0]]];

    [cometchat removeFriends:[[command arguments] objectAtIndex:1] success:^(NSDictionary *response) {

        NSDictionary *successDict = @{@"success":response};
        [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:successDict] callbackId:command.callbackId];

    } failure:^(NSError *error) {

        NSDictionary *errorDict = @{@"error":error};
        [self.commandDelegate sendPluginResult:[CDVPluginResult
                                                resultWithStatus:CDVCommandStatus_OK messageAsDictionary:errorDict] callbackId:command.callbackId];

    }];

}

- (void)subscribe:(CDVInvokedUrlCommand*)command{

    cometchat = [[CometChat alloc] init];
    [cometchat subscribeWithMode:[[command arguments] objectAtIndex:0] onMyInfoReceived:^(NSDictionary *response) {

        NSDictionary *successDict = @{@"myinfo":response};
        [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:successDict] callbackId:command.callbackId];

    } onGetOnlineUsers:^(NSDictionary *response) {
        NSDictionary *successDict = @{@"getonlineusers":response};
        [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:successDict] callbackId:command.callbackId];
    } onMessageReceived:^(NSDictionary *response) {
        NSDictionary *successDict = @{@"messagereceived":response};
        [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:successDict] callbackId:command.callbackId];
    } onAnnouncementReceived:^(NSDictionary *response) {
        NSDictionary *successDict = @{@"announcementreceived":response};
        [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:successDict] callbackId:command.callbackId];
    } onAVChatMessageReceived:^(NSDictionary *response) {
        NSDictionary *successDict = @{@"avchatmessagereceived":response};
        [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:successDict] callbackId:command.callbackId];
    } onActionMessageReceived:^(NSDictionary *response) {

        NSDictionary *successDict = @{@"actionmessagereceived":response};
        [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:successDict] callbackId:command.callbackId];

    }
                    onGetBotList:^(NSDictionary *response) {
                        NSDictionary *successDict = @{@"getbotlistreceived":response};
                        [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:successDict] callbackId:command.callbackId];
                    }
                         failure:^(NSError *error) {

                             NSDictionary *errorDict = @{@"error":error};
                             [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:errorDict] callbackId:command.callbackId];

                         }];

}

- (void)sendMessage:(CDVInvokedUrlCommand*)command{

    cometchat = [[CometChat alloc] init];
    [cometchat sendMessage:[[command arguments] objectAtIndex:0] toUser:[[command arguments] objectAtIndex:1] success:^(NSDictionary *response) {

        NSDictionary *successDict = @{@"success":response};
        [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:successDict] callbackId:command.callbackId];

    } failure:^(NSError *error) {

        NSDictionary *errorDict = @{@"error":error};
        [self.commandDelegate sendPluginResult:[CDVPluginResult
                                                resultWithStatus:CDVCommandStatus_OK messageAsDictionary:errorDict] callbackId:command.callbackId];

    }];

}

- (void)sendImageWithPath:(CDVInvokedUrlCommand*)command{

    cometchat = [[CometChat alloc] init];
    [cometchat sendImageWithPath:[[command arguments] objectAtIndex:0] toUser:[[command arguments] objectAtIndex:1] success:^(NSDictionary *response) {

        NSDictionary *successDict = @{@"success":response};
        [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:successDict] callbackId:command.callbackId];

    } failure:^(NSError *error) {

        NSDictionary *errorDict = @{@"error":error};
        [self.commandDelegate sendPluginResult:[CDVPluginResult
                                                resultWithStatus:CDVCommandStatus_OK messageAsDictionary:errorDict] callbackId:command.callbackId];
    }];

}

/*  Send image to user with given image data */
- (void)sendImageWithData:(CDVInvokedUrlCommand*)command{

    cometchat = [[CometChat alloc] init];
    [cometchat sendImageWithData:[[command arguments] objectAtIndex:0] toUser:[[command arguments] objectAtIndex:1] success:^(NSDictionary *response) {

        NSDictionary *successDict = @{@"success":response};
        [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:successDict] callbackId:command.callbackId];

    } failure:^(NSError *error) {

        NSDictionary *errorDict = @{@"error":error};
        [self.commandDelegate sendPluginResult:[CDVPluginResult
                                                resultWithStatus:CDVCommandStatus_OK messageAsDictionary:errorDict] callbackId:command.callbackId];

    }];

}

/*   Send audio to user with the given image path */
- (void)sendAudioWithPath:(CDVInvokedUrlCommand*)command{

    cometchat = [[CometChat alloc] init];
    [cometchat sendAudioWithPath:[[command arguments] objectAtIndex:0] toUser:[[command arguments] objectAtIndex:1] success:^(NSDictionary *response) {

        NSDictionary *successDict = @{@"success":response};
        [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:successDict] callbackId:command.callbackId];

    } failure:^(NSError *error) {

        NSDictionary *errorDict = @{@"error":error};
        [self.commandDelegate sendPluginResult:[CDVPluginResult
                                                resultWithStatus:CDVCommandStatus_OK messageAsDictionary:errorDict] callbackId:command.callbackId];

    }];

}

/*  Send audio to user with given image data */
- (void)sendAudioWithData:(CDVInvokedUrlCommand*)command{

    cometchat = [[CometChat alloc] init];
    [cometchat sendAudioWithData:[[command arguments] objectAtIndex:0] toUser:[[command arguments] objectAtIndex:1] success:^(NSDictionary *response) {

        NSDictionary *successDict = @{@"success":response};
        [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:successDict] callbackId:command.callbackId];

    } failure:^(NSError *error) {

        NSDictionary *errorDict = @{@"error":error};
        [self.commandDelegate sendPluginResult:[CDVPluginResult
                                                resultWithStatus:CDVCommandStatus_OK messageAsDictionary:errorDict] callbackId:command.callbackId];

    }];

}

/*   Send file to user with the given image path */
- (void)sendFileWithPath:(CDVInvokedUrlCommand*)command{

    cometchat = [[CometChat alloc] init];
    [cometchat sendFileWithPath:[[command arguments] objectAtIndex:0] toUser:[[command arguments] objectAtIndex:1] success:^(NSDictionary *response) {

        NSDictionary *successDict = @{@"success":response};
        [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:successDict] callbackId:command.callbackId];

    } failure:^(NSError *error) {

        NSDictionary *errorDict = @{@"error":error};
        [self.commandDelegate sendPluginResult:[CDVPluginResult
                                                resultWithStatus:CDVCommandStatus_OK messageAsDictionary:errorDict] callbackId:command.callbackId];

    }];

}

/*   Send video to user with the given video path */
- (void)sendVideoWithPath:(CDVInvokedUrlCommand*)command{

    cometchat = [[CometChat alloc] init];
    [cometchat sendVideoWithPath:[[command arguments] objectAtIndex:0] toUser:[[command arguments] objectAtIndex:1] success:^(NSDictionary *response) {

        NSDictionary *successDict = @{@"success":response};
        [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:successDict] callbackId:command.callbackId];

    } failure:^(NSError *error) {

        NSDictionary *errorDict = @{@"error":error};
        [self.commandDelegate sendPluginResult:[CDVPluginResult
                                                resultWithStatus:CDVCommandStatus_OK messageAsDictionary:errorDict] callbackId:command.callbackId];

    }];

}

/*  Send video to user with given video data */
- (void)sendVideoWithURL:(CDVInvokedUrlCommand*)command{

    cometchat = [[CometChat alloc] init];
    [cometchat sendVideoWithURL:[[command arguments] objectAtIndex:0] toUser:[[command arguments] objectAtIndex:1] success:^(NSDictionary *response) {

        NSDictionary *successDict = @{@"success":response};
        [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:successDict] callbackId:command.callbackId];

    } failure:^(NSError *error) {

        NSDictionary *errorDict = @{@"error":error};
        [self.commandDelegate sendPluginResult:[CDVPluginResult
                                                resultWithStatus:CDVCommandStatus_OK messageAsDictionary:errorDict] callbackId:command.callbackId];

    }];

}

/* Broadcast message to users of given userIDs*/
- (void)broadcastMessage:(CDVInvokedUrlCommand*)command{

    cometchat = [[CometChat alloc] init];
    [cometchat broadcastMessage:[[command arguments] objectAtIndex:0] toUsers:[[command arguments] objectAtIndex:1] success:^(NSDictionary *response) {

        NSDictionary *successDict = @{@"success":response};
        [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:successDict] callbackId:command.callbackId];

    } failure:^(NSError *error) {

        NSDictionary *errorDict = @{@"error":error};
        [self.commandDelegate sendPluginResult:[CDVPluginResult
                                                resultWithStatus:CDVCommandStatus_OK messageAsDictionary:errorDict] callbackId:command.callbackId];

    }];

}
/* Send Whiteboard Request */
- (void)sendWhiteBoardRequest:(CDVInvokedUrlCommand*)command{

    cometchat = [[CometChat alloc] init];
    [cometchat sendWhiteBoardRequest:[[command arguments] objectAtIndex:0] success:^(NSDictionary *response) {

        NSDictionary *successDict = @{@"success":response};
        [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:successDict] callbackId:command.callbackId];

    } failure:^(NSError *error) {

        NSDictionary *errorDict = @{@"error":error};
        [self.commandDelegate sendPluginResult:[CDVPluginResult
                                                resultWithStatus:CDVCommandStatus_OK messageAsDictionary:errorDict] callbackId:command.callbackId];

    }];

}

/* Send Writeboard Request */
- (void)sendWriteBoardRequest:(CDVInvokedUrlCommand*)command{

    cometchat = [[CometChat alloc] init];
    [cometchat sendWriteBoardRequest:[[command arguments] objectAtIndex:0] success:^(NSDictionary *response) {

        NSDictionary *successDict = @{@"success":response};
        [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:successDict] callbackId:command.callbackId];

    } failure:^(NSError *error) {

        NSDictionary *errorDict = @{@"error":error};
        [self.commandDelegate sendPluginResult:[CDVPluginResult
                                                resultWithStatus:CDVCommandStatus_OK messageAsDictionary:errorDict] callbackId:command.callbackId];

    }];

}

/* Send Writeboard Ack */
- (void)sendWriteBoardAck:(CDVInvokedUrlCommand*)command{

    cometchat = [[CometChat alloc] init];
    [cometchat sendWriteBoardAck:[[command arguments] objectAtIndex:0]];


    [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK] callbackId:command.callbackId];

}

/* Change status of logged-in user. Refer to STATUS_OPTIONS enum in CometChat.h file for status values. */
- (void)changeStatus:(CDVInvokedUrlCommand*)command{

    cometchat = [[CometChat alloc] init];
    [cometchat changeStatus:[[[command arguments] objectAtIndex:0] integerValue] success:^(NSDictionary *response) {

        NSDictionary *successDict = @{@"success":response};
        [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:successDict] callbackId:command.callbackId];

    } failure:^(NSError *error) {

        NSDictionary *errorDict = @{@"error":error};
        [self.commandDelegate sendPluginResult:[CDVPluginResult
                                                resultWithStatus:CDVCommandStatus_OK messageAsDictionary:errorDict] callbackId:command.callbackId];

    }];
}

/* Change status message of logged-in user. */
- (void)changeStatusMessage:(CDVInvokedUrlCommand*)command{

    cometchat = [[CometChat alloc] init];
    [cometchat changeStatusMessage:[[command arguments] objectAtIndex:0] success:^(NSDictionary *response) {

        NSDictionary *successDict = @{@"success":response};
        [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:successDict] callbackId:command.callbackId];

    } failure:^(NSError *error) {

        NSDictionary *errorDict = @{@"error":error};
        [self.commandDelegate sendPluginResult:[CDVPluginResult
                                                resultWithStatus:CDVCommandStatus_OK messageAsDictionary:errorDict] callbackId:command.callbackId];

    }];

}

/* Get Plugin Info if user is logged-in */
- (void)getPluginInfo:(CDVInvokedUrlCommand*)command{

    cometchat = [[CometChat alloc] init];
    [cometchat getPluginInfo:^(NSDictionary *response) {

        NSDictionary *successDict = @{@"success":response};
        [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:successDict] callbackId:command.callbackId];

    } failure:^(NSError *error) {

        NSDictionary *errorDict = @{@"error":error};
        [self.commandDelegate sendPluginResult:[CDVPluginResult
                                                resultWithStatus:CDVCommandStatus_OK messageAsDictionary:errorDict] callbackId:command.callbackId];

    }];

}

/* Get user information for userID */
- (void)getUserInfo:(CDVInvokedUrlCommand*)command{

    cometchat = [[CometChat alloc] init];
    [cometchat getUserInfo:[[command arguments] objectAtIndex:0] success:^(NSDictionary *response) {

        NSDictionary *successDict = @{@"success":response};
        [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:successDict] callbackId:command.callbackId];

    } failure:^(NSError *error) {

        NSDictionary *errorDict = @{@"error":error};
        [self.commandDelegate sendPluginResult:[CDVPluginResult
                                                resultWithStatus:CDVCommandStatus_OK messageAsDictionary:errorDict] callbackId:command.callbackId];

    }];

}

/* Get online users of the site */
- (void)getOnlineUsersWithResponse:(CDVInvokedUrlCommand*)command{

    cometchat = [[CometChat alloc] init];
    [cometchat getOnlineUsersWithResponse:^(NSDictionary *response) {

        NSDictionary *successDict = @{@"success":response};
        [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:successDict] callbackId:command.callbackId];

    } failure:^(NSError *error) {

        NSDictionary *errorDict = @{@"error":error};
        [self.commandDelegate sendPluginResult:[CDVPluginResult
                                                resultWithStatus:CDVCommandStatus_OK messageAsDictionary:errorDict] callbackId:command.callbackId];

    }];

}

/* Get Single Player Game URL */
- (void)getSinglePlayerGamesUrl:(CDVInvokedUrlCommand*)command{

    cometchat = [[CometChat alloc] init];
    [cometchat getSinglePlayerGamesUrl:^(NSDictionary *response) {

        NSDictionary *successDict = @{@"success":response};
        [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:successDict] callbackId:command.callbackId];

    } failure:^(NSError *error) {

        NSDictionary *errorDict = @{@"error":error};
        [self.commandDelegate sendPluginResult:[CDVPluginResult
                                                resultWithStatus:CDVCommandStatus_OK messageAsDictionary:errorDict] callbackId:command.callbackId];

    }];
}

/* Get all announcements of the site */
- (void)getAllAnnouncements:(CDVInvokedUrlCommand*)command{

    cometchat = [[CometChat alloc] init];
    [cometchat getAllAnnouncements:^(NSDictionary *response) {

        NSDictionary *successDict = @{@"success":response};
        [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:successDict] callbackId:command.callbackId];

    } failure:^(NSError *error) {

        NSDictionary *errorDict = @{@"error":error};
        [self.commandDelegate sendPluginResult:[CDVPluginResult
                                                resultWithStatus:CDVCommandStatus_OK messageAsDictionary:errorDict] callbackId:command.callbackId];

    }];
}

/* Block User */
- (void)blockUser:(CDVInvokedUrlCommand*)command{

    cometchat = [[CometChat alloc] init];
    [cometchat blockUser:[[command arguments] objectAtIndex:0] success:^(NSDictionary *response) {

        NSDictionary *successDict = @{@"success":response};
        [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:successDict] callbackId:command.callbackId];

    } failure:^(NSError *error) {

        NSDictionary *errorDict = @{@"error":error};
        [self.commandDelegate sendPluginResult:[CDVPluginResult
                                                resultWithStatus:CDVCommandStatus_OK messageAsDictionary:errorDict] callbackId:command.callbackId];

    }];
}

/* Unblock User */
- (void)unblockUser:(CDVInvokedUrlCommand*)command{

    cometchat = [[CometChat alloc] init];
    [cometchat unblockUser:[[command arguments] objectAtIndex:0] success:^(NSDictionary *response) {
        NSDictionary *successDict = @{@"success":response};
        [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:successDict] callbackId:command.callbackId];
    } failure:^(NSError *error) {
        NSDictionary *errorDict = @{@"error":error};
        [self.commandDelegate sendPluginResult:[CDVPluginResult
                                                resultWithStatus:CDVCommandStatus_OK messageAsDictionary:errorDict] callbackId:command.callbackId];
    }];
}

/* Delete User's History */
- (void)deleteUserHistory:(CDVInvokedUrlCommand*)command{

    cometchat = [[CometChat alloc] init];
    [cometchat deleteUserHistory:[[command arguments] objectAtIndex:0] success:^(NSDictionary *response) {
        NSDictionary *successDict = @{@"success":response};
        [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:successDict] callbackId:command.callbackId];
    } failure:^(NSError *error) {
        NSDictionary *errorDict = @{@"error":error};
        [self.commandDelegate sendPluginResult:[CDVPluginResult
                                                resultWithStatus:CDVCommandStatus_OK messageAsDictionary:errorDict] callbackId:command.callbackId];
    }];
}

/* Get List of blocked users */
- (void)getBlockedUsersWithResponse:(CDVInvokedUrlCommand*)command{

    cometchat = [[CometChat alloc] init];
    [cometchat getBlockedUsersWithResponse:^(NSDictionary *response) {
        NSDictionary *successDict = @{@"success":response};
        [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:successDict] callbackId:command.callbackId];
    } failure:^(NSError *error) {
        NSDictionary *errorDict = @{@"error":error};
        [self.commandDelegate sendPluginResult:[CDVPluginResult
                                                resultWithStatus:CDVCommandStatus_OK messageAsDictionary:errorDict] callbackId:command.callbackId];
    }];
}

/* Get chat history of user specified by userID */
- (void)getChatHistoryOfUser:(CDVInvokedUrlCommand*)command{

    cometchat = [[CometChat alloc] init];
    [cometchat getChatHistoryOfUser:[[command arguments] objectAtIndex:0] messageID:[[command arguments] objectAtIndex:1] success:^(NSDictionary *response) {
        NSDictionary *successDict = @{@"success":response};
        [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:successDict] callbackId:command.callbackId];
    } failure:^(NSError *error) {
        NSDictionary *errorDict = @{@"error":error};
        [self.commandDelegate sendPluginResult:[CDVPluginResult
                                                resultWithStatus:CDVCommandStatus_OK messageAsDictionary:errorDict] callbackId:command.callbackId];
    }];
}

/* Send Stickers */
- (void)sendStickers:(CDVInvokedUrlCommand*)command{

    cometchat = [[CometChat alloc] init];
    [cometchat sendStickers:[[command arguments] objectAtIndex:0] toUser:[[command arguments] objectAtIndex:1] success:^(NSDictionary *response) {

        NSDictionary *successDict = @{@"success":response};
        [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:successDict] callbackId:command.callbackId];


    } failure:^(NSError *error) {

        NSDictionary *errorDict = @{@"error":error};
        [self.commandDelegate sendPluginResult:[CDVPluginResult
                                                resultWithStatus:CDVCommandStatus_OK messageAsDictionary:errorDict] callbackId:command.callbackId];

    }];
}

/* Translate OneOnOne and Chatroom Messages */
- (void)setTranslationLanguage:(CDVInvokedUrlCommand*)command{

    cometchat = [[CometChat alloc] init];
    [cometchat setTranslationLanguage:[[[command arguments] objectAtIndex:0] integerValue] success:^(NSDictionary *response) {

        NSDictionary *successDict = @{@"success":response};
        [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:successDict] callbackId:command.callbackId];

    } failure:^(NSError *error) {

        NSDictionary *errorDict = @{@"error":error};
        [self.commandDelegate sendPluginResult:[CDVPluginResult
                                                resultWithStatus:CDVCommandStatus_OK messageAsDictionary:errorDict] callbackId:command.callbackId];

    }];
}

/* Check whether the user is logged-in */
//+ (BOOL)isLoggedIn DEPRECATED_MSG_ATTRIBUTE("This method is deprecated");

/* Unsubscribe from OneOnChat */
- (void)unsubscribe:(CDVInvokedUrlCommand*)command{

    cometchat = [[CometChat alloc] init];
    [cometchat unsubscribe];
}

/* Logout */
- (void)logoutWithSuccess:(CDVInvokedUrlCommand*)command{

    cometchat = [[CometChat alloc] init];
    [cometchat logoutWithSuccess:^(NSDictionary *response) {
        NSDictionary *successDict = @{@"success":response};
        [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:successDict] callbackId:command.callbackId];
    } failure:^(NSError *error) {
        NSDictionary *errorDict = @{@"error":error};
        [self.commandDelegate sendPluginResult:[CDVPluginResult
                                                resultWithStatus:CDVCommandStatus_OK messageAsDictionary:errorDict] callbackId:command.callbackId];
    }];
}

/* Returns the SDK version */
- (void)getSDKVersion:(CDVInvokedUrlCommand*)command{

    NSDictionary *successDict = @{@"success":[CometChat getSDKVersion]};
    [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:successDict] callbackId:command.callbackId];

}

/* Check CometChat installation directory */
- (void)isCometChatInstalled:(CDVInvokedUrlCommand*)command{

    cometchat = [[CometChat alloc] init];
    [cometchat isCometChatInstalled:[[command arguments] objectAtIndex:0] success:^(NSDictionary *response) {
        NSDictionary *successDict = @{@"success":response};
        [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:successDict] callbackId:command.callbackId];
    } failure:^(NSError *error) {
        NSDictionary *errorDict = @{@"error":error};
        [self.commandDelegate sendPluginResult:[CDVPluginResult
                                                resultWithStatus:CDVCommandStatus_OK messageAsDictionary:errorDict] callbackId:command.callbackId];
    }];
}

/* isTyping */
- (void)isTyping:(CDVInvokedUrlCommand*)command{

    cometchat = [[CometChat alloc] init];
    [cometchat isTyping:[[command arguments] objectAtIndex:0] channel:[[command arguments] objectAtIndex:1] failure:^(NSError *error) {
        NSDictionary *errorDict = @{@"error":error};
        [self.commandDelegate sendPluginResult:[CDVPluginResult
                                                resultWithStatus:CDVCommandStatus_OK messageAsDictionary:errorDict] callbackId:command.callbackId];
    }];
}

/* Deliver - Read Receipt Feature */
- (void)sendDeliverdReceipt:(CDVInvokedUrlCommand*)command{

    cometchat = [[CometChat alloc] init];
    [cometchat sendDeliverdReceipt:[[command arguments] objectAtIndex:0] channel:[[command arguments] objectAtIndex:1] failure:^(NSError *error) {
        NSDictionary *errorDict = @{@"error":error};
        [self.commandDelegate sendPluginResult:[CDVPluginResult
                                                resultWithStatus:CDVCommandStatus_OK messageAsDictionary:errorDict] callbackId:command.callbackId];
    }];
}

- (void)sendReadReceipt:(CDVInvokedUrlCommand*)command{

    cometchat = [[CometChat alloc] init];
    [cometchat sendReadReceipt:[[command arguments] objectAtIndex:0] channel:[[command arguments] objectAtIndex:1] failure:^(NSError *error) {
        NSDictionary *errorDict = @{@"error":error};
        [self.commandDelegate sendPluginResult:[CDVPluginResult
                                                resultWithStatus:CDVCommandStatus_OK messageAsDictionary:errorDict] callbackId:command.callbackId];
    }];
}

/*======== Chatroom Methods =======*/
/* Subscribe to Chatroom chat:
 BOOL mode indicating whether to strip html tags or not */
- (void)subscribeToChatroomWithMode:(CDVInvokedUrlCommand*)command{

    cometChatroom = [[CometChatChatroom alloc] init];

    [cometChatroom subscribeToChatroomWithMode:[[command arguments] objectAtIndex:0] onChatroomMessageReceived:^(NSDictionary *response) {
        NSDictionary *successDict = @{@"chatroommessagereceived":response};
        [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:successDict] callbackId:command.callbackId];
    } onActionMessageReceived:^(NSDictionary *response) {
        NSDictionary *successDict = @{@"actionmessagereceived":response};
        [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:successDict] callbackId:command.callbackId];
    } onChatroomsListReceived:^(NSDictionary *response) {
        NSDictionary *successDict = @{@"chatroomlistreceived":response};
        [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:successDict] callbackId:command.callbackId];
    } onAVChatMessageReceived:^(NSDictionary *response) {
        NSDictionary *successDict = @{@"avchatmessagereceived":response};
        [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:successDict] callbackId:command.callbackId];
    } failure:^(NSError *error) {
        NSDictionary *errorDict = @{@"error":error};
        [self.commandDelegate sendPluginResult:[CDVPluginResult
                                                resultWithStatus:CDVCommandStatus_OK messageAsDictionary:errorDict] callbackId:command.callbackId];
    }];

}

/* Join chatroom:
 specify chatroomID and password */
- (void)joinChatroom:(CDVInvokedUrlCommand*)command{

    cometChatroom = [[CometChatChatroom alloc] init];
    [cometChatroom joinChatroom:[[command arguments] objectAtIndex:0] chatroomID:[[command arguments] objectAtIndex:1] chatroomPassword:[[command arguments] objectAtIndex:2] success:^(NSDictionary *response) {
        NSDictionary *successDict = @{@"success":[CometChat getSDKVersion]};
        [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:successDict] callbackId:command.callbackId];
    } failure:^(NSError *error) {
        NSDictionary *errorDict = @{@"error":error};
        [self.commandDelegate sendPluginResult:[CDVPluginResult
                                                resultWithStatus:CDVCommandStatus_OK messageAsDictionary:errorDict] callbackId:command.callbackId];
    }];
}

/* Create Chatroom having specified type, name and password */
- (void)createChatRoom:(CDVInvokedUrlCommand*)command{

    cometChatroom = [[CometChatChatroom alloc] init];
    [cometChatroom createChatRoom:[[command arguments] objectAtIndex:0] OfType:[[[command arguments] objectAtIndex:1] integerValue] withPassword:[[command arguments] objectAtIndex:2] success:^(NSDictionary *response) {
        NSDictionary *successDict = @{@"success":[CometChat getSDKVersion]};
        [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:successDict] callbackId:command.callbackId];
    } failure:^(NSError *error) {
        NSDictionary *errorDict = @{@"error":error};
        [self.commandDelegate sendPluginResult:[CDVPluginResult
                                                resultWithStatus:CDVCommandStatus_OK messageAsDictionary:errorDict] callbackId:command.callbackId];
    }];
}

/* Get Chatroom Member list */
- (void)getChatroomMembers:(CDVInvokedUrlCommand*)command{
    cometChatroom = [[CometChatChatroom alloc] init];
    [cometChatroom getChatroomMembers:[[command arguments] objectAtIndex:0] success:^(NSDictionary *response) {
        NSDictionary *successDict = @{@"success":[CometChat getSDKVersion]};
        [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:successDict] callbackId:command.callbackId];
    } failure:^(NSError *error) {
        NSDictionary *errorDict = @{@"error":error};
        [self.commandDelegate sendPluginResult:[CDVPluginResult
                                                resultWithStatus:CDVCommandStatus_OK messageAsDictionary:errorDict] callbackId:command.callbackId];
    }];
}

/* Delete Chatroom passing chatroomID */
- (void)deleteChatRoom:(CDVInvokedUrlCommand*)command{

    cometChatroom = [[CometChatChatroom alloc] init];
    [cometChatroom deleteChatRoom:[[command arguments] objectAtIndex:0] success:^(NSDictionary *response) {
        NSDictionary *successDict = @{@"success":[CometChat getSDKVersion]};
        [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:successDict] callbackId:command.callbackId];
    } failure:^(NSError *error) {
        NSDictionary *errorDict = @{@"error":error};
        [self.commandDelegate sendPluginResult:[CDVPluginResult
                                                resultWithStatus:CDVCommandStatus_OK messageAsDictionary:errorDict] callbackId:command.callbackId];
    }];
}

/* Invite users to specified chatroom */
- (void)inviteUsers:(CDVInvokedUrlCommand*)command{

    cometChatroom = [[CometChatChatroom alloc] init];
    [cometChatroom inviteUsers:[[command arguments] objectAtIndex:0] toChatroom:[[command arguments] objectAtIndex:1] withChatroomID:[[command arguments] objectAtIndex:2] success:^(NSDictionary *response) {
        NSDictionary *successDict = @{@"success":[CometChat getSDKVersion]};
        [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:successDict] callbackId:command.callbackId];
    } failure:^(NSError *error) {
        NSDictionary *errorDict = @{@"error":error};
        [self.commandDelegate sendPluginResult:[CDVPluginResult
                                                resultWithStatus:CDVCommandStatus_OK messageAsDictionary:errorDict] callbackId:command.callbackId];
    }];

}

/* Send message to currently joined chatroom */
- (void)sendChatroomMessage:(CDVInvokedUrlCommand*)command{

    cometChatroom = [[CometChatChatroom alloc] init];
    [cometChatroom sendChatroomMessage:[[command arguments] objectAtIndex:0] toChatroom:[[command arguments] objectAtIndex:1] withChatroomID:[[command arguments] objectAtIndex:2] withsuccess:^(NSDictionary *response) {
        NSDictionary *successDict = @{@"success":[CometChat getSDKVersion]};
        [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:successDict] callbackId:command.callbackId];
    } failure:^(NSError *error) {
        NSDictionary *errorDict = @{@"error":error};
        [self.commandDelegate sendPluginResult:[CDVPluginResult
                                                resultWithStatus:CDVCommandStatus_OK messageAsDictionary:errorDict] callbackId:command.callbackId];
    }];
}

/* Send Stickers */
- (void)sendChatroomStickers:(CDVInvokedUrlCommand*)command{

    cometChatroom = [[CometChatChatroom alloc] init];
    [cometChatroom sendChatroomStickers:[[command arguments] objectAtIndex:0] toChatroom:[[command arguments] objectAtIndex:1] withChatroomID:[[command arguments] objectAtIndex:2] withsuccess:^(NSDictionary *response) {
        NSDictionary *successDict = @{@"success":[CometChat getSDKVersion]};
        [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:successDict] callbackId:command.callbackId];
    } failure:^(NSError *error) {
        NSDictionary *errorDict = @{@"error":error};
        [self.commandDelegate sendPluginResult:[CDVPluginResult
                                                resultWithStatus:CDVCommandStatus_OK messageAsDictionary:errorDict] callbackId:command.callbackId];
    }];
}

/*  Send image in chatroom with the given image path */
- (void)sendImageWithPathChatroom:(CDVInvokedUrlCommand*)command{

    cometChatroom = [[CometChatChatroom alloc] init];
    [cometChatroom sendImageWithPath:[[command arguments] objectAtIndex:0] toChatroom:[[command arguments] objectAtIndex:1] withChatroomID:[[command arguments] objectAtIndex:2] success:^(NSDictionary *response) {
        NSDictionary *successDict = @{@"success":[CometChat getSDKVersion]};
        [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:successDict] callbackId:command.callbackId];
    } failure:^(NSError *error) {
        NSDictionary *errorDict = @{@"error":error};
        [self.commandDelegate sendPluginResult:[CDVPluginResult
                                                resultWithStatus:CDVCommandStatus_OK messageAsDictionary:errorDict] callbackId:command.callbackId];
    }];
}

/*  Send image in chatroom with given image data */
- (void)sendImageWithDataChatroom:(CDVInvokedUrlCommand*)command{

    cometChatroom = [[CometChatChatroom alloc] init];
    [cometChatroom sendImageWithData:[[command arguments] objectAtIndex:0] toChatroom:[[command arguments] objectAtIndex:1] withChatroomID:[[command arguments] objectAtIndex:2] success:^(NSDictionary *response) {
        NSDictionary *successDict = @{@"success":[CometChat getSDKVersion]};
        [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:successDict] callbackId:command.callbackId];
    } failure:^(NSError *error) {
        NSDictionary *errorDict = @{@"error":error};
        [self.commandDelegate sendPluginResult:[CDVPluginResult
                                                resultWithStatus:CDVCommandStatus_OK messageAsDictionary:errorDict] callbackId:command.callbackId];
    }];
}

/*  Send audio in chatroom with the given image path */
- (void)sendAudioWithPathChatroom:(CDVInvokedUrlCommand*)command{

    cometChatroom = [[CometChatChatroom alloc] init];
    [cometChatroom sendAudioWithPath:[[command arguments] objectAtIndex:0] toChatroom:[[command arguments] objectAtIndex:1] withChatroomID:[[command arguments] objectAtIndex:2] success:^(NSDictionary *response) {
        NSDictionary *successDict = @{@"success":[CometChat getSDKVersion]};
        [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:successDict] callbackId:command.callbackId];
    } failure:^(NSError *error) {
        NSDictionary *errorDict = @{@"error":error};
        [self.commandDelegate sendPluginResult:[CDVPluginResult
                                                resultWithStatus:CDVCommandStatus_OK messageAsDictionary:errorDict] callbackId:command.callbackId];
    }];
}

/*  Send video in chatroom with the given image path */
- (void)sendVideoWithPathChatroom:(CDVInvokedUrlCommand*)command{

    cometChatroom = [[CometChatChatroom alloc] init];
    [cometChatroom sendVideoWithPath:[[command arguments] objectAtIndex:0] toChatroom:[[command arguments] objectAtIndex:1] withChatroomID:[[command arguments] objectAtIndex:2] success:^(NSDictionary *response) {
        NSDictionary *successDict = @{@"success":[CometChat getSDKVersion]};
        [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:successDict] callbackId:command.callbackId];
    } failure:^(NSError *error) {
        NSDictionary *errorDict = @{@"error":error};
        [self.commandDelegate sendPluginResult:[CDVPluginResult
                                                resultWithStatus:CDVCommandStatus_OK messageAsDictionary:errorDict] callbackId:command.callbackId];
    }];
}

/*  Send video in chatroom with given video url */
- (void)sendVideoWithURLChatroom:(CDVInvokedUrlCommand*)command{

    cometChatroom = [[CometChatChatroom alloc] init];
    [cometChatroom sendVideoWithURL:[[command arguments] objectAtIndex:0] toChatroom:[[command arguments] objectAtIndex:1] withChatroomID:[[command arguments] objectAtIndex:2] success:^(NSDictionary *response) {
        NSDictionary *successDict = @{@"success":[CometChat getSDKVersion]};
        [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:successDict] callbackId:command.callbackId];
    } failure:^(NSError *error) {
        NSDictionary *errorDict = @{@"error":error};
        [self.commandDelegate sendPluginResult:[CDVPluginResult
                                                resultWithStatus:CDVCommandStatus_OK messageAsDictionary:errorDict] callbackId:command.callbackId];
    }];
}

/*  Send file in chatroom with given file path */
- (void)sendFileWithPathChatroom:(CDVInvokedUrlCommand*)command{

    cometChatroom = [[CometChatChatroom alloc] init];
    [cometChatroom sendFileWithPath:[[command arguments] objectAtIndex:0] toChatroom:[[command arguments] objectAtIndex:1] withChatroomID:[[command arguments] objectAtIndex:2] success:^(NSDictionary *response) {
        NSDictionary *successDict = @{@"success":[CometChat getSDKVersion]};
        [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:successDict] callbackId:command.callbackId];
    } failure:^(NSError *error) {
        NSDictionary *errorDict = @{@"error":error};
        [self.commandDelegate sendPluginResult:[CDVPluginResult
                                                resultWithStatus:CDVCommandStatus_OK messageAsDictionary:errorDict] callbackId:command.callbackId];
    }];
}

/* Get chatroom list from server */
- (void)getAllChatrooms:(CDVInvokedUrlCommand*)command{

    cometChatroom = [[CometChatChatroom alloc] init];
    [cometChatroom getAllChatrooms:^(NSDictionary *chatroomList) {
        NSDictionary *successDict = @{@"success":[CometChat getSDKVersion]};
        [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:successDict] callbackId:command.callbackId];
    } failure:^(NSError *error) {
        NSDictionary *errorDict = @{@"error":error};
        [self.commandDelegate sendPluginResult:[CDVPluginResult
                                                resultWithStatus:CDVCommandStatus_OK messageAsDictionary:errorDict] callbackId:command.callbackId];
    }];
}

/* Leave currently joined chatroom */
- (void)leaveChatroom:(CDVInvokedUrlCommand*)command{

    cometChatroom = [[CometChatChatroom alloc] init];
    [cometChatroom leaveChatroom:[[command arguments] objectAtIndex:0] failure:^(NSError *error) {
        NSDictionary *errorDict = @{@"error":error};
        [self.commandDelegate sendPluginResult:[CDVPluginResult
                                                resultWithStatus:CDVCommandStatus_OK messageAsDictionary:errorDict] callbackId:command.callbackId];
    }];

}

/* Unsubscribe from chatroom */
- (void)unsubscribeFromChatRoom:(CDVInvokedUrlCommand*)command{

    cometChatroom = [[CometChatChatroom alloc] init];
    [cometChatroom unsubscribeFromChatRoom];
}

/* Get currently joined chatroom id */
- (void)getCurrentChatroom:(CDVInvokedUrlCommand*)command{

    cometChatroom = [[CometChatChatroom alloc] init];
    [cometChatroom getCurrentChatroom:^(NSDictionary *response) {
        NSDictionary *successDict = @{@"success":[CometChat getSDKVersion]};
        [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:successDict] callbackId:command.callbackId];
    } failure:^(NSError *error) {
        NSDictionary *errorDict = @{@"error":error};
        [self.commandDelegate sendPluginResult:[CDVPluginResult
                                                resultWithStatus:CDVCommandStatus_OK messageAsDictionary:errorDict] callbackId:command.callbackId];
    }];

}

/* Check whether the user is subscribed to given chatroom */
- (void)isSubscribedToChatroom:(CDVInvokedUrlCommand*)command
{

    NSDictionary *successDict = @{@"success":[NSString stringWithFormat:@"%d",[CometChatChatroom isSubscribedToChatroom:[[command arguments] objectAtIndex:0]]]};



    [self.commandDelegate sendPluginResult:[CDVPluginResult
                                            resultWithStatus:CDVCommandStatus_OK messageAsDictionary:successDict] callbackId:command.callbackId];
}

/* Gives SHA1 value of specified string */
-(void)getSHA1ValueOfString:(CDVInvokedUrlCommand*)command{

    NSDictionary *successDict = @{@"success":[CometChatChatroom getSHA1ValueOfString:[[command arguments] objectAtIndex:0]]};
    [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:successDict] callbackId:command.callbackId];

}

@end
