<commit_before>#import "MPNotificationController.h"
#import "MPIConstants.h"
#import "MPPersistenceController.h"
#import "MPIUserDefaults.h"
#include "MPHasher.h"
#import "MParticle.h"
#import "MPBackendController.h"
#import "MPApplication.h"
#import "MPStateMachine.h"

@interface MPNotificationController() {
}

@end

@interface MParticle ()

@property (nonatomic, strong, nonnull) MPBackendController *backendController;

@end

#if TARGET_OS_IOS == 1
static NSData *deviceToken = nil;
#endif

@implementation MPNotificationController

#if TARGET_OS_IOS == 1

- (instancetype)init {
    self = [super init];
    if (!self) {
        return nil;
    }

    return self;
}

#pragma mark Public static methods
+ (NSData *)deviceToken {
#ifndef MP_UNIT_TESTING
    MPIUserDefaults *userDefaults = [MPIUserDefaults standardUserDefaults];
    deviceToken = userDefaults[kMPDeviceTokenKey];
#else
    deviceToken = [@"<0<PASSWORD>>" dataUsingEncoding:NSUTF8StringEncoding];
#endif
    
    return deviceToken;
}

+ (void)setDeviceToken:(NSData *)devToken {
    if ([MPNotificationController deviceToken] && [[MPNotificationController deviceToken] isEqualToData:devToken]) {
        return;
    }
    
    NSData *newDeviceToken = [devToken copy];
    NSData *oldDeviceToken = [deviceToken copy];
    
    deviceToken = devToken;
    
    dispatch_async(dispatch_get_main_queue(), ^{
        NSMutableDictionary *deviceTokenDictionary = [[NSMutableDictionary alloc] initWithCapacity:2];
        NSString *newTokenString = nil;
        NSString *oldTokenString = nil;
        if (newDeviceToken) {
            deviceTokenDictionary[kMPRemoteNotificationDeviceTokenKey] = newDeviceToken;
            newTokenString = [MPIUserDefaults stringFromDeviceToken:newDeviceToken];
        }
        
        if (oldDeviceToken) {
            deviceTokenDictionary[kMPRemoteNotificationOldDeviceTokenKey] = oldDeviceToken;
            oldTokenString = [[NSString alloc] initWithData:oldDeviceToken encoding:NSUTF8StringEncoding];
        }

        [[NSNotificationCenter defaultCenter] postNotificationName:kMPRemoteNotificationDeviceTokenNotification
                                                            object:nil
                                                          userInfo:deviceTokenDictionary];
        
        if (oldTokenString && newTokenString) {
            [[MParticle sharedInstance].backendController.networkCommunication modifyDeviceID:@"push_token"
                                                                                        value:newTokenString
                                                                                     oldValue:oldTokenString];
        }
        
#ifndef MP_UNIT_TESTING
        MPIUserDefaults *userDefaults = [MPIUserDefaults standardUserDefaults];
        userDefaults[kMPDeviceTokenKey] = deviceToken;
        [userDefaults synchronize];
#endif
    });
}

#endif

@end
<commit_msg>Set DeviceToken on Message Queue<commit_after>#import "MPNotificationController.h"
#import "MPIConstants.h"
#import "MPPersistenceController.h"
#import "MPIUserDefaults.h"
#include "MPHasher.h"
#import "MParticle.h"
#import "MPBackendController.h"
#import "MPApplication.h"
#import "MPStateMachine.h"

@interface MPNotificationController() {
}

@end

@interface MParticle ()

+ (dispatch_queue_t)messageQueue;
@property (nonatomic, strong, nonnull) MPBackendController *backendController;

@end

#if TARGET_OS_IOS == 1
static NSData *deviceToken = nil;
#endif

@implementation MPNotificationController

#if TARGET_OS_IOS == 1

- (instancetype)init {
    self = [super init];
    if (!self) {
        return nil;
    }

    return self;
}

#pragma mark Public static methods
+ (NSData *)deviceToken {
#ifndef MP_UNIT_TESTING
    MPIUserDefaults *userDefaults = [MPIUserDefaults standardUserDefaults];
    deviceToken = userDefaults[kMPDeviceTokenKey];
#else
    deviceToken = [@"<000000000000000000000000000000>" dataUsingEncoding:NSUTF8StringEncoding];
#endif
    
    return deviceToken;
}

+ (void)setDeviceToken:(NSData *)devToken {
    if ([MPNotificationController deviceToken] && [[MPNotificationController deviceToken] isEqualToData:devToken]) {
        return;
    }
    
    NSData *newDeviceToken = [devToken copy];
    NSData *oldDeviceToken = [deviceToken copy];
    
    deviceToken = devToken;

    dispatch_async([MParticle messageQueue], ^{
        NSMutableDictionary *deviceTokenDictionary = [[NSMutableDictionary alloc] initWithCapacity:2];
        NSString *newTokenString = nil;
        NSString *oldTokenString = nil;
        if (newDeviceToken) {
            deviceTokenDictionary[kMPRemoteNotificationDeviceTokenKey] = newDeviceToken;
            newTokenString = [MPIUserDefaults stringFromDeviceToken:newDeviceToken];
        }
        
        if (oldDeviceToken) {
            deviceTokenDictionary[kMPRemoteNotificationOldDeviceTokenKey] = oldDeviceToken;
            oldTokenString = [[NSString alloc] initWithData:oldDeviceToken encoding:NSUTF8StringEncoding];
        }

        [[NSNotificationCenter defaultCenter] postNotificationName:kMPRemoteNotificationDeviceTokenNotification
                                                            object:nil
                                                          userInfo:deviceTokenDictionary];
        
        if (oldTokenString && newTokenString) {
            [[MParticle sharedInstance].backendController.networkCommunication modifyDeviceID:@"push_token"
                                                                                        value:newTokenString
                                                                                     oldValue:oldTokenString];
        }
        
#ifndef MP_UNIT_TESTING
        MPIUserDefaults *userDefaults = [MPIUserDefaults standardUserDefaults];
        userDefaults[kMPDeviceTokenKey] = deviceToken;
        [userDefaults synchronize];
#endif
    });
}

#endif

@end

{'fraction_non_alphanumeric': 0.08273078863292416, 'fraction_numerical': 0.006894232386077013, 'mean_word_length': 2.7175, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 22, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5450108', 'n_tokens_mistral': 1588, 'n_tokens_neox': 1509, 'n_words': 302}