<commit_before>/// <reference path="../d.ts/DefinitelyTyped/jquery/jquery.d.ts" />
/// <reference path="../d.ts/DefinitelyTyped/angularjs/angular.d.ts" />
/// <reference path="../d.ts/DefinitelyTyped/notify.js/notify.js.d.ts" />

interface Room {
    id: number
    name: string
    owner: Member
    is_private: boolean
    latest_post: Comment
}

interface Message {
    members: Array<Member>
    error:   string
    user:    Member
    comment: Comment
    kind:    string
}

interface Member {
    id:     number
    avatarUrl: string
    firstName: string
    fullName:   string
    userSetting: UserSetting
}

interface Comment {
    id: number
    user: Member
    message: string
    created: Date
}

interface UserSetting {
    id: number
    user_id: number
    desktopNotifications: boolean
}

module Account {
    export interface  Scope extends  ng.IScope {
        userSetting: UserSetting
        get: () => void
        save: () => void
    }

    export class Controller {
        constructor($scope: Scope, $http:ng.IHttpService) {
            $scope.get = () => {
                $http.get("/account/user_setting").success((data: any) => {
                   $scope.userSetting = data
                })
            }
            $scope.get()

            $scope.save = () => {
                $http.post("/account/save", $scope.userSetting).success((data) => {
                    alert("save changed!")
                })
            }
        }
    }
}

module Rooms {
    export interface  Scope extends  ng.IScope {
        newRoom: Room
        rooms: Room[]
        list: () => void
        showCreateRoomForm: (e:MouseEvent) => void
        close: () => void
        createRoom: (e:MouseEvent) => void
    }

    export class Controller {
        constructor($scope: Scope, $http:ng.IHttpService) {
            $scope.list = () => {
                $scope.rooms = []
                $http.get("/rooms").success((result) => {
                    result.forEach((room: Room) => {
                        $scope.rooms.push(room)
                    })
                })
            }
            $scope.list()

            $("#new-room").hide()
            $scope.showCreateRoomForm = (e:MouseEvent) => {
                $("#new-room").show()
            }

            $scope.close = () => {
                $("#new-room").hide()
            }

            $scope.createRoom = (e:MouseEvent) => {
                $http.post("/room/create", $scope.newRoom).success((data) => {
                    $scope.close()
                    $scope.list()
                })
            }
        }
    }
}

module Chat {

    export interface Scope extends ng.IScope {
        roomId: number
        userId: number
        messages: Message[]
        talkBody: String
        talk: (KeyboardEvent) => void
        reply: (msg: Message) => void
        replyTo: number
        members: Member[]
        rooms: Room[]
        userSetting: UserSetting

        isSupportedNotification : boolean
        needsPermission : boolean
        requestPermission: ()=> void
        setNotification: (boolean)=> void
        notify : notify.INotify
    }

    export class Controller {
        constructor($scope:Scope, $http:ng.IHttpService) {
            $scope.replyTo = null
            $scope.messages = []
            $http.get("/recently_messages/" + $scope.roomId).success((result) => {
                result.reverse().forEach((message: Message) => {
                    $scope.messages.push(message)
                })
                setTimeout(() => {
                    $("div.messages").animate({ scrollTop: $("div.messages")[0].scrollHeight }, 1)
                }, 50)
            })

            $scope.rooms = []
            $http.get("/rooms").success((result) => {
                result.forEach((room: Room) => {
                    $scope.rooms.push(room)
                })
            })

            $http.get("/room/" + $scope.roomId + "/wspath").success((result) => {
                var chatSocket = new WebSocket(result.path)

                chatSocket.onopen = () => {
                    chatSocket.onmessage = (event) => {
                        var data:Message = JSON.parse(event.data)

                        // Handle errors
                        if (data.error) {
                            chatSocket.close()
                            console.log(data.error)
                            return
                        } else {
                            $("#onChat").show()
                        }

                        if (data.kind == "talk") {
                            $scope.messages.push(data)

                            if($scope.userSetting.desktopNotifications && data.user.id != $scope.userId) {
                                var notify = new Notify("Phantasm - " + data.user.fullName, {body : data.comment.message, icon: data.user.avatarUrl});
                                notify.show();
                            }<commit_msg>auto close desktop notifications<commit_after>/// <reference path="../d.ts/DefinitelyTyped/jquery/jquery.d.ts" />
/// <reference path="../d.ts/DefinitelyTyped/angularjs/angular.d.ts" />
/// <reference path="../d.ts/DefinitelyTyped/notify.js/notify.js.d.ts" />

interface Room {
    id: number
    name: string
    owner: Member
    is_private: boolean
    latest_post: Comment
}

interface Message {
    members: Array<Member>
    error:   string
    user:    Member
    comment: Comment
    kind:    string
}

interface Member {
    id:     number
    avatarUrl: string
    firstName: string
    fullName:   string
    userSetting: UserSetting
}

interface Comment {
    id: number
    user: Member
    message: string
    created: Date
}

interface UserSetting {
    id: number
    user_id: number
    desktopNotifications: boolean
}

module Account {
    export interface  Scope extends  ng.IScope {
        userSetting: UserSetting
        get: () => void
        save: () => void
    }

    export class Controller {
        constructor($scope: Scope, $http:ng.IHttpService) {
            $scope.get = () => {
                $http.get("/account/user_setting").success((data: any) => {
                   $scope.userSetting = data
                })
            }
            $scope.get()

            $scope.save = () => {
                $http.post("/account/save", $scope.userSetting).success((data) => {
                    alert("save changed!")
                })
            }
        }
    }
}

module Rooms {
    export interface  Scope extends  ng.IScope {
        newRoom: Room
        rooms: Room[]
        list: () => void
        showCreateRoomForm: (e:MouseEvent) => void
        close: () => void
        createRoom: (e:MouseEvent) => void
    }

    export class Controller {
        constructor($scope: Scope, $http:ng.IHttpService) {
            $scope.list = () => {
                $scope.rooms = []
                $http.get("/rooms").success((result) => {
                    result.forEach((room: Room) => {
                        $scope.rooms.push(room)
                    })
                })
            }
            $scope.list()

            $("#new-room").hide()
            $scope.showCreateRoomForm = (e:MouseEvent) => {
                $("#new-room").show()
            }

            $scope.close = () => {
                $("#new-room").hide()
            }

            $scope.createRoom = (e:MouseEvent) => {
                $http.post("/room/create", $scope.newRoom).success((data) => {
                    $scope.close()
                    $scope.list()
                })
            }
        }
    }
}

module Chat {

    export interface Scope extends ng.IScope {
        roomId: number
        userId: number
        messages: Message[]
        talkBody: String
        talk: (KeyboardEvent) => void
        reply: (msg: Message) => void
        replyTo: number
        members: Member[]
        rooms: Room[]
        userSetting: UserSetting

        isSupportedNotification : boolean
        needsPermission : boolean
        requestPermission: ()=> void
        setNotification: (boolean)=> void
        notify : notify.INotify
    }

    export class Controller {
        constructor($scope:Scope, $http:ng.IHttpService) {
            $scope.replyTo = null
            $scope.messages = []
            $http.get("/recently_messages/" + $scope.roomId).success((result) => {
                result.reverse().forEach((message: Message) => {
                    $scope.messages.push(message)
                })
                setTimeout(() => {
                    $("div.messages").animate({ scrollTop: $("div.messages")[0].scrollHeight }, 1)
                }, 50)
            })

            $scope.rooms = []
            $http.get("/rooms").success((result) => {
                result.forEach((room: Room) => {
                    $scope.rooms.push(room)
                })
            })

            $http.get("/room/" + $scope.roomId + "/wspath").success((result) => {
                var chatSocket = new WebSocket(result.path)

                chatSocket.onopen = () => {
                    chatSocket.onmessage = (event) => {
                        var data:Message = JSON.parse(event.data)

                        // Handle errors
                        if (data.error) {
                            chatSocket.close()
                            console.log(data.error)
                            return
                        } else {
                            $("#onChat").show()
                        }

                        if (data.kind == "talk") {
                            $scope.messages.push(data)

                            if($scope.userSetting.desktopNotifications && data.user.id != $scope.userId) {
                                var notify = new Notify("Phantasm - " + data.user.fullName, {body : data.comment.message, icon: data.user.avatarUrl});
                                notify.show()

                                setTimeout(() => {
                                    notify.close()
                                }, 5000)
                            }
{'fraction_non_alphanumeric': 0.13020833333333334, 'fraction_numerical': 0.0011792452830188679, 'mean_word_length': 1.314006366530241, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 70, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3171276', 'n_tokens_mistral': 2711, 'n_tokens_neox': 2609, 'n_words': 488}