<commit_before>/**
 * ContextHandler
 * Handles current contexts of the user. Each context is valid for a particular amount of time and gets invalidated after that.
 */
class ContextHandler{
    private static container: {[user:string]: Context} = {}

    static create(user:string){
        
    }

    static handleTextMessage(user:string, text:string):boolean{
        return false;
    }

    static handleQuickReply(user:string, payload:string):boolean{
        return false;
    }

}

enum ContextType {
    WaitingTaskUpdateTitle,
    WaitingTaskUpdateConfirmation
}

/**
 *  Context
 */
class Context{
    static validity:number = 5*60 //5 min
    created:number
    expires:number
    constructor(public type:string) { }

}<commit_msg>Context<commit_after>import Messenger = require("./Models/Messenger")

/**
 * ContextHandler
 * Handles current contexts of the user. Each context is valid for a particular amount of time and gets invalidated after that.
 */
class ContextHandler{
    
    private static container: {[user:string]: Context} = {}

    static createFromTextMessage(user:string){

    }

    static createFromPostback(user:string, command:string, sourceDescription:string):boolean{
        let contextType = ContextType.Unknown
        if(command === "update")
            contextType = ContextType.TaskUpdateTitle
        
        if(contextType !== ContextType.Unknown){
            let context = new Context(contextType, Source.Postback, sourceDescription);
            this.container[user] = context;
            return true
        }
        return false
    }

    static handleTextMessage(user:string, text:string):boolean{
        let context = this.container[user]
        if(context){
            if(context.isValid()){
                switch (context.type) {
                    case ContextType.TaskUpdateTitle:
                        context.info = text
                        context.updateType(ContextType.TaskUpdateConfirmation)
                        //Ask for confirmation

                        break;

                    default:
                        break;
                }
            }
        }
        return false;
    }

    static handleQuickReply(user:string, payload:string):boolean{
        return false;
    }


    private handleTaskUpdateTitle:(user:string, text:string){

    }

}

enum ContextType {
    Unknown,
    TaskUpdateTitle,
    TaskUpdateConfirmation
}

enum Source{
    Postback,
    QuickReply,
    Text
}

/**
 *  Context
 */
class Context{
    /* Validity of the context */
    static validity:number = 2*60 //2 min

    created:number
    expires:number
    info:string

    constructor(public type:ContextType, public source:Source, public sourceDescription:string) {
        const currentEpoch = Math.round(new Date().getTime() / 1000)
        this.created = currentEpoch
        this.expires = currentEpoch + Context.validity
    }

    updateType(type:ContextType){
        const currentEpoch = Math.round(new Date().getTime() / 1000)
        this.expires = currentEpoch + Context.validity
    }

    isValid():boolean{
        const currentEpoch = Math.round(new Date().getTime() / 1000)
        if(this.expires>currentEpoch)
            return true
        
        return false
    }

}

export = ContextHandler
{'fraction_non_alphanumeric': 0.09052376627308507, 'fraction_numerical': 0.006055101422948834, 'mean_word_length': 2.2974051896207586, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '5272365', 'n_tokens_mistral': 901, 'n_tokens_neox': 849, 'n_words': 211}