<commit_before>"use strict";

app.factory("Model", function($rootScope, $q, Socket){
    var LOCAL_STORAGE_ID = "mfccModel",
        modelString = localStorage[LOCAL_STORAGE_ID];

    var model = modelString ? JSON.parse(modelString) : {
        name: undefined,
        broadcasterId: undefined
    };

    $rootScope.$watch(function(){ return model;}, function(){
        localStorage[LOCAL_STORAGE_ID] = JSON.stringify(model);
    });

    function modelLookupByName(modelName) {
        var deferred =  $q.defer();

        function scanUserLookup(msg) {
            //only process userlookups
            if (msg.Type !== MFCMessageType.FCTYPE_USERNAMELOOKUP)
                return;

            //we have a userlookup message, remove the listener
            Socket.removeListener("message", scanUserLookup);

            //check if the model was found
            if (1 == msg.Arg2){
                $rootScope.$apply(function(){
                    deferred.reject("Could not find {0}.".format(modelName));
                });
                return;
            }

            //model was found, check the video state
            if (MFCVideoState.FCVIDEO_TX_IDLE != msg.Data.vs){
                $rootScope.$apply(function(){
                    deferred.reject("{0} is not in public chat.".format(modelName));
                });
                return;
            }

            $rootScope.$apply(function(){
                model = {
                    name: modelName,
                    broadcasterId: 100000000 + parseInt(msg.Arg2, 10)
                };
                deferred.resolve(model);
            });
        };

        Socket.listen("message", scanUserLookup);

        Socket.send(new MFCMessage({
            Type: MFCMessageType.FCTYPE_USERNAMELOOKUP,
            From: 0,
            To: 0,
            Arg1: 20,
            Arg2: 0,
            Data: modelName
        }));

        return deferred.promise;
    }

    return {
        getModel: function() {return model;},
        lookupModel: modelLookupByName
    }
});<commit_msg>Fixed model not found bug<commit_after>"use strict";

app.factory("Model", function($rootScope, $q, Socket){
    var LOCAL_STORAGE_ID = "mfccModel",
        modelString = localStorage[LOCAL_STORAGE_ID];

    var model = modelString ? JSON.parse(modelString) : {
        name: undefined,
        broadcasterId: undefined
    };

    $rootScope.$watch(function(){ return model;}, function(){
        localStorage[LOCAL_STORAGE_ID] = JSON.stringify(model);
    });

    function modelLookupByName(modelName) {
        var deferred =  $q.defer();

        function scanUserLookup(msg) {
            //only process userlookups
            if (msg.Type !== MFCMessageType.FCTYPE_USERNAMELOOKUP)
                return;

            //we have a userlookup message, remove the listener
            Socket.removeListener("message", scanUserLookup);

            //check if the model was found
            if (1 == msg.Arg2){
                $rootScope.$apply(function(){
                    deferred.reject("Could not find {0}.".format(modelName));
                });
                return;
            }

            //model was found, check the video state
            if (MFCVideoState.FCVIDEO_TX_IDLE == msg.Data.vs || MFCVideoState.FCVIDEO_RX_IDLE == msg.Data.vs){
                //model is in public, resolve positively
                $rootScope.$apply(function(){
                    model = {
                        name: modelName,
                        broadcasterId: 100000000 + parseInt(msg.Arg2, 10)
                    };
                    deferred.resolve(model);
                });
                return;
            }

            //model was not in public
            $rootScope.$apply(function(){
                deferred.reject("{0} is not in public chat.".format(modelName));
            });

        };

        Socket.listen("message", scanUserLookup);

        Socket.send(new MFCMessage({
            Type: MFCMessageType.FCTYPE_USERNAMELOOKUP,
            From: 0,
            To: 0,
            Arg1: 20,
            Arg2: 0,
            Data: modelName
        }));

        return deferred.promise;
    }

    return {
        getModel: function() {return model;},
        lookupModel: modelLookupByName
    }
});
{'fraction_non_alphanumeric': 0.1098239110287303, 'fraction_numerical': 0.010658016682113068, 'mean_word_length': 1.6131961259079903, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '6159834', 'n_tokens_mistral': 1219, 'n_tokens_neox': 1126, 'n_words': 249}