<commit_before>let React = require('react-native')

let {
    NativeModules,
    NativeAppEventEmitter
} = React

let {
    TwilioIPMessagingClient,
    TwilioIPMessagingChannels,
    TwilioIPMessagingMessages
} = NativeModules

let Channel = require('./Channel')
let Message = require('./Message')
let UserInfo = require('./UserInfo')

let {Constants} = TwilioIPMessagingClient

class Client {
    constructor(accessManager, synchronizationStrategy, initialMessageCount) {        
        // properties
        this.accessManager = accessManager
        this.userInfo = {}
                        
        // initial event handlers
        this.onSynchronizationStatusChanged = null
        this.onChannelAdded = null
        this.onChannelChanged = null
        this.onChannelDeleted = null
        this.onChannelSynchronizationStatusChanged = null
        this.onMemberJoined = null
        this.onMemberChanged = null
        this.onMemberLeft = null
        this.onMessageAdded = null
        this.onMessageChanged = null
        this.onMessageDeleted = null
        this.onError = null
        this.onTypingStarted = null
        this.onTypingEnded = null
        
        this.onToastSubscribed = null
        this.onToastReceived = null
        this.onToastRegistrationFailed = null
                
        this.onClientSynchronized = null 
        
        if (synchronizationStrategy || initialMessageCount) {
            this._properties = {synchronizationStrategy, initialMessageCount}
        }
        
        // event handlers
        this._synchronizationStatusChangedSubscription = NativeAppEventEmitter.addListener(
            'ipMessagingClient:synchronizationStatusChanged',
            (status) => {
                this.synchronizationStatus = status
                if (status == Constants.TWMClientSynchronizationStatus.Completed) {
                    TwilioIPMessagingClient.userInfo()
                    .then((userInfo) => this.userInfo = new UserInfo(userInfo))
                    .then(() => {
                        if (this.onClientSynchronized) this.onClientSynchronized()
                    })
                }
                if (this.onSynchronizationStatusChanged) this.onSynchronizationStatusChanged(status)
            }
        )
        
        this._channelAddedSubscription = NativeAppEventEmitter.addListener(
            'ipMessagingClient:channelAdded',
            (channel) => {
                if (this.onChannelAdded) this.onChannelAdded(channel)
            }
        )
        
        this._channelChangedSubscription = NativeAppEventEmitter.addListener(
            'ipMessagingClient:channelChanged',
            (channel) => {
                if (this.onChannelChanged) this.onChannelChanged(channel)
            }
        )
        
        this._channelDeletedSubscription = NativeAppEventEmitter.addListener(
            'ipMessagingClient:channelDeleted',
            (channel) => {
                if (this.onChannelDeleted) this.onChannelDeleted(channel)
            }
        )
        
        this._channelSynchronizationStatusChangedSubscription = NativeAppEventEmitter.addListener(
            'ipMessagingClient:channel:synchronizationStatusChanged',
            ({channelSid, status}) => {
                if (this.onChannelSynchronizationStatusChanged) this.onChannelSynchronizationStatusChanged({channelSid, status})
            }
        )
        
        this._channelMemberJoinedSubscription = NativeAppEventEmitter.addListener(
            'ipMessagingClient:channel:memberJoined',
            ({channelSid, member}) => {
                if (this.onMemberJoined) this.onMemberJoined({channelSid, member})
            }
        )
        
        this._channelMemberChangedSubscription = NativeAppEventEmitter.addListener(
            'ipMessagingClient:channel:memberChanged',
            ({channelSid, member}) => {
                if (this.onMemberChanged) this.onMemberChanged({channelSid, member})
            }
        )
        
        this._channelMemberLeftSubscription = NativeAppEventEmitter.addListener(
            'ipMessagingClient:channel:memberLeft',
            ({channelSid, member}) => {
                if (this.onMemberLeft) this.onMemberLeft({channelSid, member})
            }
        )
        
        this._channelMessageAddedSubscription = NativeAppEventEmitter.addListener(
            'ipMessagingClient:channel:messageAdded',
            ({channelSid, message}) => {
                if (this.onMessageAdded) this.onMessageAdded({channelSid, message: new Message(message, channelSid)})
            }
        )
        
        this._channelMessageChangedSubscription = NativeAppEventEmitter.addListener(
            'ipMessagingClient:channel:messageChanged',
            ({channelSid, message}) => {
                if (this.onMessageChanged) this.onMessageChanged({channelSid, message: new Message(message, channelSid)})
            }
        )
        
        this._channelMessageDeletedSubscription = NativeAppEventEmitter.addListener(
            'ipMessagingClient:channel:messageDeleted',
            ({channelSid, message}) => {
                if (this.onMessageDeleted) this.onMessageDeleted({channelSid, message: new Message(message, channelSid)})
            }
        )
        
        this._ErrorReceivedSubscription = NativeAppEventEmitter.addListener(
            'ipMessagingClient:errorReceived',
            ({error, userInfo}) => {
                if (this.onError) this.onError({error, userInfo})
            }
        )
        
        this._typingChannelStartedSubscription = NativeAppEventEmitter.addListener(
            'ipMessagingClient:typingStartedOnChannel',
            ({channelSid, member}) => {
                if (this.onTypingStarted) this.onTypingStarted({channelSid, member})
            }
        )
        
        this._typingChannelEndedSubscription = NativeAppEventEmitter.addListener(
            'ipMessagingClient:typingEndedOnChannel',
            ({channelSid, member}) => {
                if (this.onTypingEnded) this.onTypingEnded({channelSid, member})
            }
        )
        
        this._toastSubscribedSubscription = NativeAppEventEmitter.addListener(
            'ipMessagingClient:toastSubscribed',
            () => {
                if (this.onToastSubscribed) this.onToastSubscribed()
            }
        )
        
        this._toastReceivedChannelSubscription = NativeAppEventEmitter.addListener(
            'ipMessagingClient:toastReceivedOnChannel',
            ({channelSid, message}) => {
                if (this.onToastReceived) this.onToastReceived({channelSid, message: new Message(message, channelSid)})
            }
        )
        
        this._toastRegistrationFailedSubscription = NativeAppEventEmitter.addListener(
            'ipMessagingClient:toastRegistrationFailedWithError',
            ({error, userInfo}) => {
                if (this.onToastRegistrationFailed) this.onToastRegistrationFailed({error, userInfo})
            }
        )
        
        this._userInfoUpdatedSubscription = NativeAppEventEmitter.addListener(
            'ipMessagingClient:userInfoUpdated',
            ({updated, userInfo}) => {
                this.userInfo = new UserInfo(userInfo)
                if (this.onUserInfoUpdated) this.onUserInfoUpdated({updated, userInfo})<commit_msg>Made it so channel events return a Channel instance, and userInfo returns a UserInfo instance<commit_after>let React = require('react-native')

let {
    NativeModules,
    NativeAppEventEmitter
} = React

let {
    TwilioIPMessagingClient,
    TwilioIPMessagingChannels,
    TwilioIPMessagingMessages
} = NativeModules

let Channel = require('./Channel')
let Message = require('./Message')
let UserInfo = require('./UserInfo')

let {Constants} = TwilioIPMessagingClient

class Client {
    constructor(accessManager, synchronizationStrategy, initialMessageCount) {        
        // properties
        this.accessManager = accessManager
        this.userInfo = {}
                        
        // initial event handlers
        this.onSynchronizationStatusChanged = null
        this.onChannelAdded = null
        this.onChannelChanged = null
        this.onChannelDeleted = null
        this.onChannelSynchronizationStatusChanged = null
        this.onMemberJoined = null
        this.onMemberChanged = null
        this.onMemberLeft = null
        this.onMessageAdded = null
        this.onMessageChanged = null
        this.onMessageDeleted = null
        this.onError = null
        this.onTypingStarted = null
        this.onTypingEnded = null
        
        this.onToastSubscribed = null
        this.onToastReceived = null
        this.onToastRegistrationFailed = null
                
        this.onClientSynchronized = null 
        
        if (synchronizationStrategy || initialMessageCount) {
            this._properties = {synchronizationStrategy, initialMessageCount}
        }
        
        // event handlers
        this._synchronizationStatusChangedSubscription = NativeAppEventEmitter.addListener(
            'ipMessagingClient:synchronizationStatusChanged',
            (status) => {
                this.synchronizationStatus = status
                if (status == Constants.TWMClientSynchronizationStatus.Completed) {
                    TwilioIPMessagingClient.userInfo()
                    .then((userInfo) => this.userInfo = new UserInfo(userInfo))
                    .then(() => {
                        if (this.onClientSynchronized) this.onClientSynchronized()
                    })
                }
                if (this.onSynchronizationStatusChanged) this.onSynchronizationStatusChanged(status)
            }
        )
        
        this._channelAddedSubscription = NativeAppEventEmitter.addListener(
            'ipMessagingClient:channelAdded',
            (channel) => {
                if (this.onChannelAdded) this.onChannelAdded(new Channel(channel))
            }
        )
        
        this._channelChangedSubscription = NativeAppEventEmitter.addListener(
            'ipMessagingClient:channelChanged',
            (channel) => {
                if (this.onChannelChanged) this.onChannelChanged(new Channel(channel))
            }
        )
        
        this._channelDeletedSubscription = NativeAppEventEmitter.addListener(
            'ipMessagingClient:channelDeleted',
            (channel) => {
                if (this.onChannelDeleted) this.onChannelDeleted(new Channel(channel))
            }
        )
        
        this._channelSynchronizationStatusChangedSubscription = NativeAppEventEmitter.addListener(
            'ipMessagingClient:channel:synchronizationStatusChanged',
            ({channelSid, status}) => {
                if (this.onChannelSynchronizationStatusChanged) this.onChannelSynchronizationStatusChanged({channelSid, status})
            }
        )
        
        this._channelMemberJoinedSubscription = NativeAppEventEmitter.addListener(
            'ipMessagingClient:channel:memberJoined',
            ({channelSid, member}) => {
                if (this.onMemberJoined) this.onMemberJoined({channelSid, member})
            }
        )
        
        this._channelMemberChangedSubscription = NativeAppEventEmitter.addListener(
            'ipMessagingClient:channel:memberChanged',
            ({channelSid, member}) => {
                if (this.onMemberChanged) this.onMemberChanged({channelSid, member})
            }
        )
        
        this._channelMemberLeftSubscription = NativeAppEventEmitter.addListener(
            'ipMessagingClient:channel:memberLeft',
            ({channelSid, member}) => {
                if (this.onMemberLeft) this.onMemberLeft({channelSid, member})
            }
        )
        
        this._channelMessageAddedSubscription = NativeAppEventEmitter.addListener(
            'ipMessagingClient:channel:messageAdded',
            ({channelSid, message}) => {
                if (this.onMessageAdded) this.onMessageAdded({channelSid, message: new Message(message, channelSid)})
            }
        )
        
        this._channelMessageChangedSubscription = NativeAppEventEmitter.addListener(
            'ipMessagingClient:channel:messageChanged',
            ({channelSid, message}) => {
                if (this.onMessageChanged) this.onMessageChanged({channelSid, message: new Message(message, channelSid)})
            }
        )
        
        this._channelMessageDeletedSubscription = NativeAppEventEmitter.addListener(
            'ipMessagingClient:channel:messageDeleted',
            ({channelSid, message}) => {
                if (this.onMessageDeleted) this.onMessageDeleted({channelSid, message: new Message(message, channelSid)})
            }
        )
        
        this._ErrorReceivedSubscription = NativeAppEventEmitter.addListener(
            'ipMessagingClient:errorReceived',
            ({error, userInfo}) => {
                if (this.onError) this.onError({error, userInfo})
            }
        )
        
        this._typingChannelStartedSubscription = NativeAppEventEmitter.addListener(
            'ipMessagingClient:typingStartedOnChannel',
            ({channelSid, member}) => {
                if (this.onTypingStarted) this.onTypingStarted({channelSid, member})
            }
        )
        
        this._typingChannelEndedSubscription = NativeAppEventEmitter.addListener(
            'ipMessagingClient:typingEndedOnChannel',
            ({channelSid, member}) => {
                if (this.onTypingEnded) this.onTypingEnded({channelSid, member})
            }
        )
        
        this._toastSubscribedSubscription = NativeAppEventEmitter.addListener(
            'ipMessagingClient:toastSubscribed',
            () => {
                if (this.onToastSubscribed) this.onToastSubscribed()
            }
        )
        
        this._toastReceivedChannelSubscription = NativeAppEventEmitter.addListener(
            'ipMessagingClient:toastReceivedOnChannel',
            ({channelSid, message}) => {
                if (this.onToastReceived) this.onToastReceived({channelSid, message: new Message(message, channelSid)})
            }
        )
        
        this._toastRegistrationFailedSubscription = NativeAppEventEmitter.addListener(
            'ipMessagingClient:toastRegistrationFailedWithError',
            ({error, userInfo}) => {
                if (this.onToastRegistrationFailed) this.onToastRegistrationFailed({error, userInfo})
            }
        )
        
        this._userInfoUpdatedSubscription = NativeAppEventEmitter.addListener(
            'ipMessagingClient:userInfoUpdated',
            ({updated, userInfo}) => {
                this.userInfo = new UserInfo(userInfo)
                if (this.onUserInfoUpdated) this.onUserInfoUpdated({updated, userInfo: this.userInfo})
{'fraction_non_alphanumeric': 0.0847309808130954, 'fraction_numerical': 0.0, 'mean_word_length': 2.146264246517518, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3251282', 'n_tokens_mistral': 3751, 'n_tokens_neox': 3729, 'n_words': 537}