diff --git a/src/angularjs/abstract/abstract-users-list.ts b/src/angularjs/abstract/abstract-users-list.ts index d0914a8..5a8e2c9 100755 --- a/src/angularjs/abstract/abstract-users-list.ts +++ b/src/angularjs/abstract/abstract-users-list.ts @@ -26,7 +26,7 @@ export class AbstractUsersListController { protected RoomOpenQueue: IRoomOpenQueue, ) { - if (this.constructor == AbstractUsersListController) { + if (this.constructor === AbstractUsersListController) { throw new Error('AbstractUsersListController can\'t be instantiated.'); } @@ -69,7 +69,7 @@ export class AbstractUsersListController { let rooms = this.Cache.getPrivateRoomsWithUsers(this.UserStore.currentUser(), user); if (rooms.length) { const r = rooms[0]; - if (r.getType() == RoomType.OneToOne) { + if (r.getType() === RoomType.OneToOne) { r.flashHeader(); // The room is already open! Do nothing return; @@ -86,7 +86,7 @@ export class AbstractUsersListController { this.RoomCreator.createAndPushPrivateRoom([user]).then((room) => { this.RoomOpenQueue.addRoomWithID(room.rid()); room.open(0); - //let room = RoomStore.getOrCreateRoomWithID(rid); + // let room = RoomStore.getOrCreateRoomWithID(rid); }, (error) => { console.log(error); }); diff --git a/src/angularjs/app/app.ts b/src/angularjs/app/app.ts index 5ba7559..ff16042 100755 --- a/src/angularjs/app/app.ts +++ b/src/angularjs/app/app.ts @@ -46,7 +46,7 @@ export let myApp = angular.module('myApp', $provide.decorator('$browser', ['$delegate', ($delegate) => { $delegate.onUrlChange = () => { }; $delegate.url = () => { - return ""; + return ''; }; return $delegate; }]); diff --git a/src/angularjs/components/chat-settings.component.ts b/src/angularjs/components/chat-settings.component.ts index ff99c29..6bb8a1d 100755 --- a/src/angularjs/components/chat-settings.component.ts +++ b/src/angularjs/components/chat-settings.component.ts @@ -27,7 +27,7 @@ class ChatSettingsController { saveTranscript() { const t = this.room.transcript(); - if (DEBUG) console.log(t); + if (DEBUG) { console.log(t); } FileSaver.saveAs(new Blob([t], { type: 'text/plain;charset=utf-8' }), this.room.name + '-transcript.txt'); } diff --git a/src/angularjs/components/friends-list.component.ts b/src/angularjs/components/friends-list.component.ts index 9423940..1bc1f73 100755 --- a/src/angularjs/components/friends-list.component.ts +++ b/src/angularjs/components/friends-list.component.ts @@ -73,8 +73,8 @@ export class FriendsListController extends AbstractUsersListController { // then alphabetically this.users.sort((user1, user2) => { // Sort by who's online first then alphabetcially - let aOnline = this.OnlineConnector.onlineUsers[user1.uid()]; - let bOnline = this.OnlineConnector.onlineUsers[user2.uid()]; + const aOnline = this.OnlineConnector.onlineUsers[user1.uid()]; + const bOnline = this.OnlineConnector.onlineUsers[user2.uid()]; if (aOnline !== bOnline) { return aOnline ? 1 : -1; @@ -90,7 +90,7 @@ export class FriendsListController extends AbstractUsersListController { this.$timeout(() => { this.$scope.$digest(); }); - }; + } } diff --git a/src/angularjs/components/public-rooms-list.component.ts b/src/angularjs/components/public-rooms-list.component.ts index 8e353ff..0a2489d 100755 --- a/src/angularjs/components/public-rooms-list.component.ts +++ b/src/angularjs/components/public-rooms-list.component.ts @@ -55,7 +55,7 @@ class PublicRoomsListController { const au = Utils.unORNull(a.getMetaObject().userCreated) ? false : a.getMetaObject().userCreated; const bu = Utils.unORNull(b.getMetaObject().userCreated) ? false : b.getMetaObject().userCreated; - if (au != bu) { + if (au !== bu) { return au ? 1 : -1; } @@ -63,17 +63,16 @@ class PublicRoomsListController { const aw = Utils.unORNull(a.getMetaObject().weight) ? 100 : a.getMetaObject().weight; const bw = Utils.unORNull(b.getMetaObject().weight) ? 100 : b.getMetaObject().weight; - if (aw != bw) { + if (aw !== bw) { return aw - bw; } else { - const ac = a.getOnlineUserCount(); const bc = b.getOnlineUserCount(); - //console.log('1: ' + ac + ', 2: ' + bc); + // console.log('1: ' + ac + ', 2: ' + bc); - if (ac != bc) { + if (ac !== bc) { return bc - ac; } else { diff --git a/src/angularjs/components/room-list-box.component.ts b/src/angularjs/components/room-list-box.component.ts index 2aefa97..2f1cd42 100755 --- a/src/angularjs/components/room-list-box.component.ts +++ b/src/angularjs/components/room-list-box.component.ts @@ -56,10 +56,10 @@ class RoomListBoxController { this.rooms.sort((a, b) => { // First order by number of unread messages // Badge can be null - let ab = a.badge ? a.badge : 0; - let bb = b.badge ? b.badge : 0; + const ab = a.badge ? a.badge : 0; + const bb = b.badge ? b.badge : 0; - if (ab != bb) { + if (ab !== bb) { return bb - ab; } // Otherwise sort them by number of users @@ -68,7 +68,7 @@ class RoomListBoxController { } }); - this.moreChatsMinimized = this.rooms.length == 0; + this.moreChatsMinimized = this.rooms.length === 0; this.$timeout(() => { this.$scope.$digest(); @@ -77,23 +77,23 @@ class RoomListBoxController { roomClicked(room: IRoom) { // Get the left most room - let rooms = this.RoomPositionManager.getRooms(); + const rooms = this.RoomPositionManager.getRooms(); // Get the last box that's active for (let i = rooms.length - 1; i >= 0; i--) { if (rooms[i].active) { // Get the details of the final room - let offset = rooms[i].offset; - let width = rooms[i].width; - let height = rooms[i].height; - let slot = rooms[i].slot; + const offset = rooms[i].offset; + const width = rooms[i].width; + const height = rooms[i].height; + const slot = rooms[i].slot; // Update the old room with the position of the new room rooms[i].setOffset(room.offset); rooms[i].width = room.width; rooms[i].height = room.height; - //rooms[i].active = false; + // rooms[i].active = false; rooms[i].setActive(false); rooms[i].slot = room.slot; @@ -102,7 +102,7 @@ class RoomListBoxController { room.width = width; room.height = height; - //room.setSizeToDefault(); + // room.setSizeToDefault(); room.setActive(true); room.badge = null; room.minimized = false; diff --git a/src/angularjs/connectors/friend-connector.ts b/src/angularjs/connectors/friend-connector.ts index c2aee31..f4e3094 100755 --- a/src/angularjs/connectors/friend-connector.ts +++ b/src/angularjs/connectors/friend-connector.ts @@ -28,7 +28,7 @@ class FriendsConnector implements IFriendsConnector { ) { } on(uid: string) { - let friendsRef = this.Paths.userFriendsRef(uid); + const friendsRef = this.Paths.userFriendsRef(uid); friendsRef.on('child_added', (snapshot) => { @@ -48,7 +48,7 @@ class FriendsConnector implements IFriendsConnector { } off(uid: string) { - let friendsRef = this.Paths.userFriendsRef(uid); + const friendsRef = this.Paths.userFriendsRef(uid); friendsRef.off('child_added'); friendsRef.off('child_removed'); @@ -66,7 +66,7 @@ class FriendsConnector implements IFriendsConnector { user.removeFriend = () => { snapshot.ref.remove(); - } + }; this.addFriend(user); } @@ -77,8 +77,7 @@ class FriendsConnector implements IFriendsConnector { } addFriendsFromConfig(friends: string[]) { - for (let i = 0; i < friends.length; i++) { - const uid = friends[i]; + for (const uid of friends) { const user = this.UserStore.getOrCreateUserWithID(uid); user.ssoFriend = true; diff --git a/src/angularjs/connectors/online-connector.ts b/src/angularjs/connectors/online-connector.ts index 1b14c59..8780b2e 100755 --- a/src/angularjs/connectors/online-connector.ts +++ b/src/angularjs/connectors/online-connector.ts @@ -35,18 +35,18 @@ class OnlineConnector implements IOnlineConnector { } this.isOn = true; - let onlineUsersRef = this.Paths.onlineUsersRef(); + const onlineUsersRef = this.Paths.onlineUsersRef(); onlineUsersRef.on('child_added', (snapshot: firebase.database.DataSnapshot) => { - if (DEBUG) console.log('Online: ' + snapshot.key); + if (DEBUG) { console.log('Online: ' + snapshot.key); } // Get the UID of the added user let uid = null; if (snapshot && snapshot.val()) { uid = snapshot.key; - let user = this.UserStore.getOrCreateUserWithID(uid); + const user = this.UserStore.getOrCreateUserWithID(uid); if (this.addOnlineUser(user)) { // Update the user's rooms @@ -62,7 +62,7 @@ class OnlineConnector implements IOnlineConnector { console.log('Offline: ' + snapshot.key); - let user = this.UserStore.getOrCreateUserWithID(snapshot.key); + const user = this.UserStore.getOrCreateUserWithID(snapshot.key); user.off(); @@ -81,11 +81,11 @@ class OnlineConnector implements IOnlineConnector { this.isOn = false; - //this.onlineUsers = {}; + // this.onlineUsers = {}; // having the user.blocked is useful because it means // that the partials don't have to call a function // however when you logout you want the flags to be reset - for (let key in this.onlineUsers) { + for (const key in this.onlineUsers) { if (this.onlineUsers.hasOwnProperty(key)) { this.onlineUsers[key].blocked = false; this.onlineUsers[key].friend = false; @@ -93,7 +93,7 @@ class OnlineConnector implements IOnlineConnector { } this.onlineUsers = {}; - let onlineUsersRef = this.Paths.onlineUsersRef(); + const onlineUsersRef = this.Paths.onlineUsersRef(); onlineUsersRef.off('child_added'); onlineUsersRef.off('child_removed'); @@ -121,7 +121,7 @@ class OnlineConnector implements IOnlineConnector { removeOnlineUserWithID(uid: string) { if (uid) { - let user = this.onlineUsers[uid]; + const user = this.onlineUsers[uid]; if (user) { user.online = false; delete this.onlineUsers[uid]; @@ -132,7 +132,7 @@ class OnlineConnector implements IOnlineConnector { onlineUserCount() { let i = 0; - for (let key in this.onlineUsers) { + for (const key in this.onlineUsers) { if (this.onlineUsers.hasOwnProperty(key)) { i++; } diff --git a/src/angularjs/controllers/chat-bar.ts b/src/angularjs/controllers/chat-bar.ts index 675589c..38a5d3f 100755 --- a/src/angularjs/controllers/chat-bar.ts +++ b/src/angularjs/controllers/chat-bar.ts @@ -39,7 +39,7 @@ class ChatBarController implements IChatBarController { this.$timeout(() => { this.$scope.$digest(); - }) + }); } } diff --git a/src/angularjs/controllers/chat.ts b/src/angularjs/controllers/chat.ts index acbe61a..5d5cdae 100755 --- a/src/angularjs/controllers/chat.ts +++ b/src/angularjs/controllers/chat.ts @@ -45,7 +45,7 @@ export interface IRoomScope extends ng.IScope { enabledMessageOptions(): string[]; enabledMessageOptionsCount(): number; fileUploadFinished(): void; - getAllUsers(): IUser[] + getAllUsers(): IUser[]; getUser(): IUser; getZIndex(): number; imageUploadFinished(): void; @@ -55,7 +55,7 @@ export interface IRoomScope extends ng.IScope { minimize(): void; onSelectFile(): void; onSelectImage(): void; - searchKeyword(): string + searchKeyword(): string; sendFileMessage(): void; sendImageMessage(): void; sendMessage(): void; @@ -99,7 +99,7 @@ class ChatController implements IChatController { // $scope properties $scope.showEmojis = false; $scope.showMessageOptions = false; - //$scope.headerColor = $scope.config.headerColor; + // $scope.headerColor = $scope.config.headerColor; $scope.loginIframeURL = $sce.trustAsResourceUrl('http://ccwp/social.html'); // $scope methods @@ -164,45 +164,45 @@ class ChatController implements IChatController { }; // When the user value changes update the user interface - scope.$on(N.UserValueChanged, (event, user) => { + scope.$on(N.UserValueChanged, (event, user: IUser) => { Log.notification(N.UserValueChanged, 'ChatController'); if (scope.room.containsUser(user)) { digest(null); } }); - scope.$on(N.RoomPositionUpdated, (event, room) => { + scope.$on(N.RoomPositionUpdated, (event, room: IRoom) => { Log.notification(N.RoomPositionUpdated, 'ChatController'); - if (scope.room == room) { + if (scope.room === room) { // Update the room's active status digest(null); } }); - scope.$on(N.RoomSizeUpdated, (event, room) => { + scope.$on(N.RoomSizeUpdated, (event, room: IRoom) => { Log.notification(N.RoomSizeUpdated, 'ChatController'); - if (scope.room == room) { + if (scope.room === room) { digest(null); } }); - scope.$on(N.LazyLoadedMessages, (event, room) => { + scope.$on(N.LazyLoadedMessages, (event, room: IRoom) => { Log.notification(N.LazyLoadedMessages, 'ChatController'); - if (scope.room == room) { + if (scope.room === room) { digest(null); } }); - scope.$on(N.ChatUpdated, (event, room) => { + scope.$on(N.ChatUpdated, (event, room: IRoom) => { Log.notification(N.ChatUpdated, 'CreateRoomController'); - if (scope.room == room) { + if (scope.room === room) { digest(null); } }); } enabledMessageOptions(): string[] { - let list = []; + const list = []; if (this.Config.fileMessagesEnabled) { list.push('fileMessagesEnabled'); } @@ -219,13 +219,13 @@ class ChatController implements IChatController { onSelectImage(room: IRoom) { this.$scope.showMessageOptions = false; this.$scope.uploadingFile = true; - this.sendImageMessage((this.$window.event.target as any).files, room) + this.sendImageMessage((this.$window.event.target as any).files, room); } onSelectFile(room: IRoom) { this.$scope.showMessageOptions = false; this.$scope.uploadingFile = true; - this.sendFileMessage((this.$window.event.target as any).files, room) + this.sendFileMessage((this.$window.event.target as any).files, room); } imageUploadFinished() { @@ -245,9 +245,9 @@ class ChatController implements IChatController { return; } - let f = $files[0]; + const f = $files[0]; - if (f.type == 'image/png' || f.type == 'image/jpeg') { + if (f.type === 'image/png' || f.type === 'image/jpeg') { this.$scope.sendingImage = true; } else { @@ -257,14 +257,14 @@ class ChatController implements IChatController { } this.NetworkManager.upload.uploadFile(f).then((r: any) => { - let url = (typeof r === 'string' ? r : r.data && r.data.url); + const url = (typeof r === 'string' ? r : r.data && r.data.url); if (typeof url === 'string' && url.length > 0) { - let reader = new FileReader(); + const reader = new FileReader(); // Load the image into the canvas immediately to get the dimensions reader.onload = () => { return (e) => { - let image = new Image(); + const image = new Image(); image.onload = () => { room.sendImageMessage(this.$scope.getUser(), url, image.width, image.height); }; @@ -281,16 +281,16 @@ class ChatController implements IChatController { }); } - sendFileMessage($files, room) { + sendFileMessage($files, room: IRoom) { if (this.$scope.sendingFile || $files.length === 0) { this.fileUploadFinished(); return; } - let f = $files[0]; + const f = $files[0]; - if (f.type == 'image/png' || f.type == 'image/jpeg') { + if (f.type === 'image/png' || f.type === 'image/jpeg') { this.sendImageMessage($files, room); return; } @@ -299,7 +299,7 @@ class ChatController implements IChatController { } this.NetworkManager.upload.uploadFile(f).then((r: any) => { - let url = (typeof r === 'string' ? r : r.data && r.data.url) + const url = (typeof r === 'string' ? r : r.data && r.data.url); if (typeof url === 'string' && url.length > 0) { room.sendFileMessage(this.$scope.getUser(), f.name, f.type, url); } @@ -312,13 +312,13 @@ class ChatController implements IChatController { getZIndex() { // Make sure windows further to the right have a higher index - let z = this.$scope.room.zIndex ? this.$scope.room.zIndex : 100 * (1 - this.$scope.room.offset / this.Screen.screenWidth); + const z = this.$scope.room.zIndex ? this.$scope.room.zIndex : 100 * (1 - this.$scope.room.offset / this.Screen.screenWidth); return Math.floor(z); } sendMessage() { console.log('sendMessage()'); - let user = this.$scope.getUser(); + const user = this.$scope.getUser(); this.$scope.showEmojis = false; this.$scope.showMessageOptions = false; @@ -333,7 +333,7 @@ class ChatController implements IChatController { tabClicked(tab: string) { this.Tab.setActiveTabForRoom(this.$scope.room.getRID(), tab); - if (tab == TabKeys.MessagesTab) { + if (tab === TabKeys.MessagesTab) { this.$scope.showEmojis = false; this.$scope.showMessageOptions = false; } @@ -383,7 +383,7 @@ class ChatController implements IChatController { acceptInvitation() { // this.$scope.room.acceptInvitation(); - console.error(new Error('IRoom.acceptInvitation() is not implemented yet')) + console.error(new Error('IRoom.acceptInvitation() is not implemented yet')); } minimize() { @@ -414,7 +414,8 @@ class ChatController implements IChatController { getAllUsers(): IUser[] { if (!Utils.unORNull(this.$scope.room)) { return ArrayUtils.objectToArray(this.$scope.room.getUsers()); - } else { + } + else { return []; } } diff --git a/src/angularjs/controllers/create-room.ts b/src/angularjs/controllers/create-room.ts index 8d311a4..ac5becb 100755 --- a/src/angularjs/controllers/create-room.ts +++ b/src/angularjs/controllers/create-room.ts @@ -54,7 +54,7 @@ class CreateRoomController { })(); this.RoomOpenQueue.addRoomWithID(room.getRID()); - room.open(0) + room.open(0); this.back(); } diff --git a/src/angularjs/controllers/emoji.ts b/src/angularjs/controllers/emoji.ts index 64e3ac5..de850e4 100755 --- a/src/angularjs/controllers/emoji.ts +++ b/src/angularjs/controllers/emoji.ts @@ -4,8 +4,8 @@ import { Emoji } from '../services/emoji'; import { IRoomScope } from './chat'; export interface IEmojiController { - addEmoji(text: string): void - getEmojis(): string[] + addEmoji(text: string): void; + getEmojis(): string[]; } class EmojiController implements IEmojiController { @@ -19,18 +19,18 @@ class EmojiController implements IEmojiController { constructor(public Emoji: Emoji, $scope: IRoomScope) { this.emoji = Emoji; this.$scope = $scope; - this.emojis = this.getEmojis() + this.emojis = this.getEmojis(); } addEmoji(text: string): void { if (!this.$scope.input.text) { - this.$scope.input.text = "" + this.$scope.input.text = ''; } - this.$scope.input.text += text + this.$scope.input.text += text; } getEmojis(): string[] { - return this.emoji.getEmojis() + return this.emoji.getEmojis(); } } @@ -43,7 +43,7 @@ class EmojiComponent implements ng.IComponentOptions { public templateUrl: 'emojis.html'; constructor() { - this.controller = EmojiController + this.controller = EmojiController; } } diff --git a/src/angularjs/controllers/login.ts b/src/angularjs/controllers/login.ts index deba2f1..e0bde73 100755 --- a/src/angularjs/controllers/login.ts +++ b/src/angularjs/controllers/login.ts @@ -125,10 +125,12 @@ class LoginController implements LoginController { try { const authUser = await this.Auth.authenticate(credential); this.handleAuthData(authUser); - } catch (error) { + } + catch (error) { if (!Utils.unORNull(error)) { this.handleLoginError(error); - } else { + } + else { this.$scope.showLoginBox(this.getLoginMode()); } } @@ -136,7 +138,7 @@ class LoginController implements LoginController { getLoginMode(): LoginMode { let loginMode = LoginMode.Simple; - let lastVisited = this.LocalStorage.getLastVisited(); + const lastVisited = this.LocalStorage.getLastVisited(); // We don't want to load the messenger straightaway to save bandwidth. // This will check when they last accessed the chat. If it was less than the timeout time ago, @@ -210,7 +212,8 @@ class LoginController implements LoginController { try { const authData = await this.Auth.authenticate(credential); this.handleAuthData(authData); - } catch (error) { + } + catch (error) { this.$scope.hideNotification(); this.handleLoginError(error); @@ -225,7 +228,8 @@ class LoginController implements LoginController { await this.Auth.resetPasswordByEmail(email); this.$scope.showNotification(NotificationType.Alert, 'Email sent', 'Instructions have been sent. Please check your Junk folder!', 'ok'); this.setError(null); - } catch (error) { + } + catch (error) { this.handleLoginError(error); } } @@ -251,7 +255,8 @@ class LoginController implements LoginController { this.$scope.email = email; this.$scope.password = password; this.loginWithPassword(); - } catch (error) { + } + catch (error) { this.handleLoginError(error); } } @@ -302,29 +307,29 @@ class LoginController implements LoginController { let message = error.message || 'An unknown error occurred'; - if (error.code == 'AUTHENTICATION_DISABLED') { + if (error.code === 'AUTHENTICATION_DISABLED') { message = 'This authentication method is currently disabled.'; } - if (error.code == 'EMAIL_TAKEN') { + if (error.code === 'EMAIL_TAKEN') { message = 'Email address unavailable.'; } - if (error.code == 'INVALID_EMAIL') { + if (error.code === 'INVALID_EMAIL') { message = 'Please enter a valid email.'; } - if (error.code == 'INVALID_ORIGIN') { + if (error.code === 'INVALID_ORIGIN') { message = 'Login is not available from this domain.'; } - if (error.code == 'INVALID_PASSWORD') { + if (error.code === 'INVALID_PASSWORD') { message = 'Please enter a valid password.'; } - if (error.code == 'INVALID_USER') { + if (error.code === 'INVALID_USER') { message = 'Invalid email or password.'; } - if (error.code == 'INVALID_USER') { + if (error.code === 'INVALID_USER') { message = 'Invalid email or password.'; } - if (error.code == 'ALREADY_AUTHENTICATING') { - message = 'Already Authenticating' + if (error.code === 'ALREADY_AUTHENTICATING') { + message = 'Already Authenticating'; } this.setError(message); diff --git a/src/angularjs/controllers/main-app.ts b/src/angularjs/controllers/main-app.ts index 0ada80a..bfbd651 100755 --- a/src/angularjs/controllers/main-app.ts +++ b/src/angularjs/controllers/main-app.ts @@ -158,7 +158,7 @@ class MainAppController implements IMainAppController { // Check to see if the user wants the chat to // load on this page. We look at the showOnPaths variable // in the options - //CC_OPTIONS.showOnPaths = '*ccwp, *p*'; + // CC_OPTIONS.showOnPaths = '*ccwp, *p*'; if (Environment.showOnPaths()) { const paths = Environment.showOnPaths(); if (!PathAnalyser.shouldShowChatOnPath(paths)) { @@ -176,9 +176,9 @@ class MainAppController implements IMainAppController { Partials.load(); - //API.getOnlineUserCount().then(function (count) { + // API.getOnlineUserCount().then(function (count) { // $scope.totalUserCount = count; - //}); + // }); // Show the waiting overlay $scope.notification = { @@ -297,7 +297,7 @@ class MainAppController implements IMainAppController { } imgForFileType(type: MessageType): string { - return this.$rootScope['img_file_' + type] || this.$rootScope['img_file']; + return this.$rootScope['img_file_' + type] || this.$rootScope.img_file; } getUser(): IUser { @@ -475,8 +475,8 @@ class MainAppController implements IMainAppController { } /** - * @return number of online users - */ + * @return number of online users + */ updateTotalUserCount() { this.$scope.totalUserCount = this.OnlineConnector.onlineUserCount(); } @@ -492,7 +492,7 @@ class MainAppController implements IMainAppController { let rooms = this.Cache.getPrivateRoomsWithUsers(this.UserStore.currentUser(), user); if (rooms.length) { const r = rooms[0]; - if (r.getType() == RoomType.RoomType.OneToOne) { + if (r.getType() === RoomType.RoomType.OneToOne) { r.flashHeader(); // The room is already open! Do nothing return; @@ -509,7 +509,7 @@ class MainAppController implements IMainAppController { this.RoomCreator.createAndPushPrivateRoom([user]).then((room) => { this.RoomOpenQueue.addRoomWithID(room.rid()); room.open(0); - //let room = RoomStore.getOrCreateRoomWithID(rid); + // let room = RoomStore.getOrCreateRoomWithID(rid); }, (error) => { console.log(error); }); @@ -517,8 +517,8 @@ class MainAppController implements IMainAppController { } /** - * - */ + * + */ logout() { // Now we need to @@ -546,7 +546,7 @@ class MainAppController implements IMainAppController { // Allow the user to log back in // Handled by callback - //$scope.showLoginBox(); + // $scope.showLoginBox(); // Set all current rooms off @@ -568,9 +568,10 @@ class MainAppController implements IMainAppController { shutdown($event: any) { - if (typeof $event.stopPropagation != 'undefined') { + if (typeof $event.stopPropagation !== 'undefined') { $event.stopPropagation(); - } else { + } + else { $event.cancelBubble = true; } @@ -605,7 +606,7 @@ class MainAppController implements IMainAppController { return; } - if (f.type == 'image/png' || f.type == 'image/jpeg') { + if (f.type === 'image/png' || f.type === 'image/jpeg') { } else { @@ -618,16 +619,16 @@ class MainAppController implements IMainAppController { this.getUser().updateImageURL(path); }); - //Parse.uploadFile($files[0]).then((function(r) { + // Parse.uploadFile($files[0]).then((function(r) { // // if(r.data && r.data.url) { // // $scope.getUser().updateImageURL(r.data.url); // } // - //}).bind(this), (function (error) { + // }).bind(this), (function (error) { // - //}).bind(this)); + // }).bind(this)); } const reader = new FileReader(); @@ -642,26 +643,27 @@ class MainAppController implements IMainAppController { image.onload = (() => { // Resize the image - const canvas = document.createElement('canvas'), - max_size = 100, - width = image.width, - height = image.height; + const canvas = document.createElement('canvas'); + const maxSize = 100; + const width = image.width; + const height = image.height; let x = 0; let y = 0; if (width > height) { x = (width - height) / 2; - } else { + } + else { y = (height - width) / 2; } - //let size = width - 2 * x; + // let size = width - 2 * x; // First rescale the image to be square - canvas.width = max_size; - canvas.height = max_size; - canvas.getContext('2d').drawImage(image, x, y, width - 2 * x, height - 2 * y, 0, 0, max_size, max_size); + canvas.width = maxSize; + canvas.height = maxSize; + canvas.getContext('2d').drawImage(image, x, y, width - 2 * x, height - 2 * y, 0, 0, maxSize, maxSize); const imageDataURL = canvas.toDataURL('image/jpeg'); @@ -690,7 +692,7 @@ class MainAppController implements IMainAppController { this.$scope.notification.show = true; this.$timeout.bind(this)(() => { this.$scope.$digest(); - }) + }); } } diff --git a/src/angularjs/controllers/main-box.ts b/src/angularjs/controllers/main-box.ts index 6b43b99..fdab0e2 100755 --- a/src/angularjs/controllers/main-box.ts +++ b/src/angularjs/controllers/main-box.ts @@ -157,7 +157,7 @@ class MainBoxController implements IMainBoxController { this.$timeout(() => { this.$scope.$digest(); - }) + }); } numberOfTabs(): number { @@ -206,16 +206,16 @@ class MainBoxController implements IMainBoxController { // Save current search text // this.$scope.search - if (tab == UsersTab) { + if (tab === UsersTab) { this.$scope.title = 'Who\'s online'; } - if (tab == RoomsTab) { + if (tab === RoomsTab) { this.$scope.title = 'Chat rooms'; } - if (tab == FriendsTab) { + if (tab === FriendsTab) { this.$scope.title = 'My friends'; } - if (tab == InboxTab) { + if (tab === InboxTab) { this.$scope.title = 'Inbox'; } } diff --git a/src/angularjs/controllers/notification.ts b/src/angularjs/controllers/notification.ts index 055f0e2..3223427 100755 --- a/src/angularjs/controllers/notification.ts +++ b/src/angularjs/controllers/notification.ts @@ -16,7 +16,7 @@ class NotificationController implements INotificationController { constructor( private $scope: INotificationScope, ) { - $scope.submit = this.submit.bind(this)() + $scope.submit = this.submit.bind(this)(); } submit() { diff --git a/src/angularjs/controllers/profile-settings.ts b/src/angularjs/controllers/profile-settings.ts index bfe15cb..6059501 100755 --- a/src/angularjs/controllers/profile-settings.ts +++ b/src/angularjs/controllers/profile-settings.ts @@ -28,7 +28,7 @@ export interface IProfileSettingsScope extends ng.IScope { validateLocation(): boolean; validateName(): boolean; validateProfileLink(): boolean; - validateString(key: string, string: string): boolean; + validateString(key: string, str: string): boolean; } export interface IProfileSettingsController { @@ -94,7 +94,7 @@ class ProfileSettingsController implements IProfileSettingsController { validateLocation(): boolean { return true; // return this.$scope.validation[UserKeys.Location].valid; - }; + } validateProfileLink(): boolean { return this.$scope.validation[UserKeys.ProfileLink].valid; @@ -117,75 +117,74 @@ class ProfileSettingsController implements IProfileSettingsController { isValidURL(url: string): boolean {// wrapped in self calling function to prevent global pollution - //URL pattern based on rfc1738 and rfc3986 - let rg_pctEncoded = "%[0-9a-fA-F]{2}"; - let rg_protocol = "(http|https):\\/\\/"; + // URL pattern based on rfc1738 and rfc3986 + const rgPctEncoded = '%[0-9a-fA-F]{2}'; + const rgProtocol = '(http|https):\\/\\/'; - let rg_userinfo = "([a-zA-Z0-9$\\-_.+!*'(),;:&=]|" + rg_pctEncoded + ")+" + "@"; + const rgUserinfo = '([a-zA-Z0-9$\\-_.+!*\'(),;:&=]|' + rgPctEncoded + ')+' + '@'; - let rg_decOctet = "(25[0-5]|2[0-4][0-9]|[0-1][0-9][0-9]|[1-9][0-9]|[0-9])"; // 0-255 - let rg_ipv4address = "(" + rg_decOctet + "(\\." + rg_decOctet + "){3}" + ")"; - let rg_hostname = "([a-zA-Z0-9\\-\\u00C0-\\u017F]+\\.)+([a-zA-Z]{2,})"; - let rg_port = "[0-9]+"; + const rgDecOctet = '(25[0-5]|2[0-4][0-9]|[0-1][0-9][0-9]|[1-9][0-9]|[0-9])'; // 0-255 + const rgIpv4address = '(' + rgDecOctet + '(\\.' + rgDecOctet + '){3}' + ')'; + const rgHostname = '([a-zA-Z0-9\\-\\u00C0-\\u017F]+\\.)+([a-zA-Z]{2,})'; + const rgPort = '[0-9]+'; - let rg_hostport = "(" + rg_ipv4address + "|localhost|" + rg_hostname + ")(:" + rg_port + ")?"; + const rgHostport = '(' + rgIpv4address + '|localhost|' + rgHostname + ')(:' + rgPort + ')?'; // chars sets // safe = "$" | "-" | "_" | "." | "+" // extra = "!" | "*" | "'" | "(" | ")" | "," // hsegment = *[ alpha | digit | safe | extra | ";" | ":" | "@" | "&" | "=" | escape ] - let rg_pchar = "a-zA-Z0-9$\\-_.+!*'(),;:@&="; - let rg_segment = "([" + rg_pchar + "]|" + rg_pctEncoded + ")*"; - - let rg_path = rg_segment + "(\\/" + rg_segment + ")*"; - let rg_query = "\\?" + "([" + rg_pchar + "/?]|" + rg_pctEncoded + ")*"; - let rg_fragment = "\\#" + "([" + rg_pchar + "/?]|" + rg_pctEncoded + ")*"; - - let rgHttpUrl = new RegExp( - "^" - + rg_protocol - + "(" + rg_userinfo + ")?" - + rg_hostport - + "(\\/" - + "(" + rg_path + ")?" - + "(" + rg_query + ")?" - + "(" + rg_fragment + ")?" - + ")?" - + "$" + const rgPChar = 'a-zA-Z0-9$\\-_.+!*\'(),;:@&='; + const rgSegment = '([' + rgPChar + ']|' + rgPctEncoded + ')*'; + + const rgPath = rgSegment + '(\\/' + rgSegment + ')*'; + const rgQuery = '\\?' + '([' + rgPChar + '/?]|' + rgPctEncoded + ')*'; + const rgFragment = '\\#' + '([' + rgPChar + '/?]|' + rgPctEncoded + ')*'; + + const rgHttpUrl = new RegExp( + '^' + + rgProtocol + + '(' + rgUserinfo + ')?' + + rgHostport + + '(\\/' + + '(' + rgPath + ')?' + + '(' + rgQuery + ')?' + + '(' + rgFragment + ')?' + + ')?' + + '$' ); // export public function if (rgHttpUrl.test(url)) { return true; - } else { + } + else { return false; } } validate(): boolean { - let user = this.$scope.getUser(); + const user = this.$scope.getUser(); // Validate the user - let nameValid = this.$scope.validateString(UserKeys.Name, user.getName()); + const nameValid = this.$scope.validateString(UserKeys.Name, user.getName()); - let profileLinkValid = !this.Config.userProfileLinkEnabled || this.$scope.validateString(UserKeys.ProfileLink, user.getProfileLink()); + const profileLinkValid = !this.Config.userProfileLinkEnabled || this.$scope.validateString(UserKeys.ProfileLink, user.getProfileLink()); return nameValid && profileLinkValid; } - validateString(key: string, string: string): boolean { + validateString(key: string, str: string): boolean { let valid = true; - if (Utils.unORNull(string)) { + if (Utils.unORNull(str)) { valid = false; } - - else if (string.length < this.$scope.validation[key].minLength) { + else if (str.length < this.$scope.validation[key].minLength) { valid = false; } - - else if (string.length > this.$scope.validation[key].maxLength) { + else if (str.length > this.$scope.validation[key].maxLength) { valid = false; } @@ -213,13 +212,13 @@ class ProfileSettingsController implements IProfileSettingsController { } else { if (!this.$scope.validation[UserKeys.Name].valid) { - this.$rootScope.showNotification(NotificationType.Alert, "Validation failed", "The name must be between " + this.$scope.validation[UserKeys.Name].minLength + " - " + this.$scope.validation[UserKeys.Name].maxLength + " characters long ", "Ok"); + this.$rootScope.showNotification(NotificationType.Alert, 'Validation failed', 'The name must be between ' + this.$scope.validation[UserKeys.Name].minLength + ' - ' + this.$scope.validation[UserKeys.Name].maxLength + ' characters long ', 'Ok'); } // if (!this.$scope.validation[UserKeys.Location].valid) { - // this.$scope.showNotification(NotificationType.Alert, "Validation failed", "The location must be between "+this.$scope.validation[UserKeys.Location].minLength+" - "+this.$scope.validation[UserKeys.Location].maxLength+" characters long", "Ok"); + // this.$scope.showNotification(NotificationType.Alert, 'Validation failed', 'The location must be between '+this.$scope.validation[UserKeys.Location].minLength+' - '+this.$scope.validation[UserKeys.Location].maxLength+' characters long', 'Ok'); // } if (!this.$scope.validation[UserKeys.ProfileLink].valid) { - this.$rootScope.showNotification(NotificationType.Alert, "Validation failed", "The profile link must be a valid URL", "Ok"); + this.$rootScope.showNotification(NotificationType.Alert, 'Validation failed', 'The profile link must be a valid URL', 'Ok'); } } } diff --git a/src/angularjs/directives/animate-room.ts b/src/angularjs/directives/animate-room.ts index 2d01c6b..748b15d 100755 --- a/src/angularjs/directives/animate-room.ts +++ b/src/angularjs/directives/animate-room.ts @@ -21,11 +21,11 @@ class AnimateRoom implements IAnimateRoom { ) { } link(scope: IRoomScope, element: JQLite) { - scope.$on(N.AnimateRoom, (event, args) => { + scope.$on(N.AnimateRoom, (_, args) => { Log.notification(N.AnimateRoom, 'animateRoom'); - if (args.room == scope.room) { + if (args.room === scope.room) { if (!Utils.unORNull(args.slot)) { scope.room.slot = args.slot; @@ -37,7 +37,7 @@ class AnimateRoom implements IAnimateRoom { // Stop the previous animation $(element).stop(true, false); - let completion = function () { + const completion = () => { scope.room.setOffset(toOffset); scope.room.zIndex = null; @@ -49,9 +49,10 @@ class AnimateRoom implements IAnimateRoom { }); }; - if (!Utils.unORNull(args.duration) && args.duration == 0) { + if (!Utils.unORNull(args.duration) && args.duration === 0) { completion(); - } else { + } + else { // Animate the chat room into position $(element).animate({ right: toOffset }, !Utils.unORNull(args.duration) ? args.duration : 300, () => { completion.bind(this)(); diff --git a/src/angularjs/directives/cc-flash.ts b/src/angularjs/directives/cc-flash.ts index fb86334..394c557 100755 --- a/src/angularjs/directives/cc-flash.ts +++ b/src/angularjs/directives/cc-flash.ts @@ -18,13 +18,13 @@ class CCFlash implements ICCFlash { ) { } link(scope: IRoomScope, element: JQLite) { + const originalTag = element.attr('data-cc-flash'); let originalColor = element.css('background-color'); - let originalTag = element.attr('data-cc-flash'); let animating = false; scope.$on(N.RoomFlashHeader, (event, room, color, period, tag) => { - if (scope.room == room && color && period && !animating) { - if (!tag || tag == originalTag) { + if (scope.room === room && color && period && !animating) { + if (!tag || tag === originalTag) { animating = true; element.css('background-color', color); @@ -35,7 +35,7 @@ class CCFlash implements ICCFlash { // Set another timeout this.$timeout(() => { - if (tag == 'room-header') { + if (tag === 'room-header') { originalColor = this.Config.headerColor; } element.css('background-color', originalColor); diff --git a/src/angularjs/directives/center-mouse-y.ts b/src/angularjs/directives/center-mouse-y.ts index 54d65be..8633158 100755 --- a/src/angularjs/directives/center-mouse-y.ts +++ b/src/angularjs/directives/center-mouse-y.ts @@ -28,7 +28,7 @@ class CenterMouseY implements ICenterMouseY { }); $(document).mousemove((e) => { - //!element.is(':hover') + // !element.is(':hover') if (scope.currentUser && !scope.hover) { // Keep the center of this box level with the mouse y element.css({ bottom: (this.Screen.screenHeight - e.clientY - $(element).height() / 2) + 'px' }); diff --git a/src/angularjs/directives/draggable-room.ts b/src/angularjs/directives/draggable-room.ts index 8d1fcba..54bdae8 100755 --- a/src/angularjs/directives/draggable-room.ts +++ b/src/angularjs/directives/draggable-room.ts @@ -57,13 +57,13 @@ class DraggableRoom implements IDraggableRoom { return false; }); - $(document).mousemove((e) => { + $(document).mousemove((e: MouseEvent) => { if (scope.dragging && !this.$rootScope.disableDrag) { Utils.stopDefault(e); - let dx = lastClientX - e.clientX; + const dx = lastClientX - e.clientX; // We must be moving in either a positive direction if (dx === 0) { diff --git a/src/angularjs/directives/draggable-user.ts b/src/angularjs/directives/draggable-user.ts index 56dc19f..8f876d5 100755 --- a/src/angularjs/directives/draggable-user.ts +++ b/src/angularjs/directives/draggable-user.ts @@ -36,7 +36,7 @@ export class UserDragAction { } distanceMoved(x: number, y: number): number { - return Math.sqrt(Math.pow(x - this.x0, 2) + Math.pow(y - this.y0, 2)) + return Math.sqrt(Math.pow(x - this.x0, 2) + Math.pow(y - this.y0, 2)); } } diff --git a/src/angularjs/directives/enter-submit.ts b/src/angularjs/directives/enter-submit.ts index 2ce92c4..89ca8d3 100755 --- a/src/angularjs/directives/enter-submit.ts +++ b/src/angularjs/directives/enter-submit.ts @@ -9,8 +9,8 @@ class EnterSubmit implements IEnterSubmit { restrict = 'A'; link(scope: ng.IScope, element: JQLite, attrs: ng.IAttributes) { - element.bind('keydown', function (event) { - let code = event.keyCode || event.which; + element.bind('keydown', (event) => { + const code = event.keyCode || event.which; if (code === 13) { if (!event.shiftKey) { diff --git a/src/angularjs/directives/fit-text.ts b/src/angularjs/directives/fit-text.ts index 6aaee7e..6b2d5e0 100755 --- a/src/angularjs/directives/fit-text.ts +++ b/src/angularjs/directives/fit-text.ts @@ -9,9 +9,9 @@ export interface IFitText extends ng.IDirective { class FitText implements IFitText { link(scope: IRoomScope, element: JQLite, attr: ng.IAttributes) { - element.bind('keyup', function (e) { - //jQuery(element).height(0); - //let height = jQuery(element)[0].scrollHeight; + element.bind('keyup', () => { + // jQuery(element).height(0); + // let height = jQuery(element)[0].scrollHeight; let height = element.prop('scrollHeight'); // 8 is for the padding @@ -20,11 +20,12 @@ class FitText implements IFitText { } // If we go over the max height - let maxHeight = eval(attr.fitText); + const maxHeight = eval(attr.fitText); if (height > maxHeight) { height = maxHeight; element.css({ overflow: 'auto' }); - } else { + } + else { element.css({ overflow: 'hidden' }); } @@ -33,7 +34,7 @@ class FitText implements IFitText { }); element.css({ 'max-height': height + 'px' }); - element.css({ 'height': height + 'px' }); + element.css({ height: height + 'px' }); }); } diff --git a/src/angularjs/directives/infinite-scroll.ts b/src/angularjs/directives/infinite-scroll.ts index 2e094db..9aa2f35 100755 --- a/src/angularjs/directives/infinite-scroll.ts +++ b/src/angularjs/directives/infinite-scroll.ts @@ -23,15 +23,15 @@ class InfiniteScroll implements ng.IDirective { link(scope: IRoomScope, element: JQLite) { element.on('scroll', () => { - this.onScroll(scope, element) + this.onScroll(scope, element); }); scope.$on('$destroy', () => { return element.off('scroll', () => { - this.onScroll(scope, element) + this.onScroll(scope, element); }); }); - }; + } loadMoreMessages(scope: IRoomScope, elem) { this.loading = true; @@ -46,11 +46,11 @@ class InfiniteScroll implements ng.IDirective { scope.room.loadMoreMessages().then(messages => { this.$timeout(() => { - let top = elem.prop('scrollHeight'); + const top = elem.prop('scrollHeight'); // console.log('3 - Height: ' + $elem.height() + ', Scroll height: ' + top + ', top: ' + $elem.scrollTop()); - if (messages && messages.length && $elem.scrollTop() == 0) { + if (messages && messages.length && $elem.scrollTop() === 0) { $elem.stop(); this.setScrollTopSilent(elem, top - scrollHeight); } @@ -76,7 +76,7 @@ class InfiniteScroll implements ng.IDirective { } this.timer = this.$timeout(() => { - this.onScrollFinished(scope, elem) + this.onScrollFinished(scope, elem); }, 100); this.scrollHeight = elem.prop('scrollHeight'); @@ -96,7 +96,7 @@ class InfiniteScroll implements ng.IDirective { // For Mobile or negative scrolling this.lastScrollTop = this.scrollTop <= 0 ? 0 : this.scrollTop; - }; + } onScrollFinished(scope: IRoomScope, elem): void { this.$timeout.cancel(this.timer); @@ -104,7 +104,7 @@ class InfiniteScroll implements ng.IDirective { const $elem = $(elem); // this.silent = false; - if ($elem.scrollTop() == 0) { + if ($elem.scrollTop() === 0) { this.loadMoreMessages(scope, elem); @@ -131,7 +131,7 @@ class InfiniteScroll implements ng.IDirective { setScrollTopSilent(elem, position: number): void { this.silent = true; - $(elem).scrollTop(position) + $(elem).scrollTop(position); } static factory(): ng.IDirectiveFactory { diff --git a/src/angularjs/directives/on-edit-message.ts b/src/angularjs/directives/on-edit-message.ts index fdf4162..353ee18 100755 --- a/src/angularjs/directives/on-edit-message.ts +++ b/src/angularjs/directives/on-edit-message.ts @@ -11,7 +11,7 @@ class OnEditMessage implements IOnEditMessage { link(scope: IMessageScope, element: JQLite) { scope.$on(N.EditMessage, (event, mid, newText) => { - if (mid == scope.message.meta.mid) { + if (mid === scope.message.meta.mid) { element.text(newText); } }); diff --git a/src/angularjs/directives/resize-room.ts b/src/angularjs/directives/resize-room.ts index cb1d658..2e9e647 100755 --- a/src/angularjs/directives/resize-room.ts +++ b/src/angularjs/directives/resize-room.ts @@ -8,6 +8,7 @@ import { Utils } from '../services/utils'; import { IScreen } from '../services/screen'; import { IRoomPositionManager } from '../services/room-position-manager'; import { IRootScope } from '../interfaces/root-scope'; +import { IRoom } from '../entities/room'; export interface IResizeRoom extends ng.IDirective { @@ -64,13 +65,13 @@ class ResizeRoom implements IResizeRoom { this.RoomPositionManager.setDirty(); // Update the rooms to the left - let rooms = this.RoomPositionManager.getRooms(); + const rooms = this.RoomPositionManager.getRooms(); // Only loop from this room's position onwards - let room; + let room: IRoom; for (let i = rooms.indexOf(scope.room); i < rooms.length; i++) { room = rooms[i]; - if (room != scope.room) { + if (room !== scope.room) { room.setOffset(this.RoomPositionManager.offsetForSlot(i)); this.$rootScope.$broadcast(N.RoomPositionUpdated, room); this.RoomPositionManager.updateAllRoomActiveStatus(); @@ -81,7 +82,7 @@ class ResizeRoom implements IResizeRoom { } }); - $(document).mouseup((e) => { + $(document).mouseup((e: MouseEvent) => { if (scope.resizing) { scope.resizing = false; } diff --git a/src/angularjs/directives/scroll-glue.ts b/src/angularjs/directives/scroll-glue.ts index 5b215d7..624bec7 100755 --- a/src/angularjs/directives/scroll-glue.ts +++ b/src/angularjs/directives/scroll-glue.ts @@ -37,7 +37,7 @@ class ScrollGlue implements IScroolGlue { element.bind('scroll', () => { didScroll = true; - let activate = shouldActivateAutoScroll(); + const activate = shouldActivateAutoScroll(); if (activate !== scope.autoScroll) { scope.autoScroll = activate; } diff --git a/src/angularjs/directives/social-iframe.ts b/src/angularjs/directives/social-iframe.ts index 71d91d5..f124c4b 100755 --- a/src/angularjs/directives/social-iframe.ts +++ b/src/angularjs/directives/social-iframe.ts @@ -23,7 +23,7 @@ class SocialIFrame implements ISocialIFrame { link(scope: ng.IScope, element: JQLite) { this.$rootScope.$on(N.StartSocialLogin, (event, data, callback) => { - //element.load(function () { + // element.load(function () { // let data = { // action: 'github', @@ -31,14 +31,14 @@ class SocialIFrame implements ISocialIFrame { // }; // Add the event listener - let eventMethod = this.$window.addEventListener ? 'addEventListener' : 'attachEvent'; - let eventer = this.$window[eventMethod]; - let messageEvent = eventMethod == 'attachEvent' ? 'onmessage' : 'message'; + const eventMethod = this.$window.addEventListener ? 'addEventListener' : 'attachEvent'; + const eventer = this.$window[eventMethod]; + const messageEvent = eventMethod === 'attachEvent' ? 'onmessage' : 'message'; eventer(messageEvent, (e) => { if (e.data) { - let data = JSON.parse(e.data); - if (data.provider == 'chatcat') { + const data = JSON.parse(e.data); + if (data.provider === 'chatcat') { callback(data); } } @@ -47,9 +47,9 @@ class SocialIFrame implements ISocialIFrame { // } }); - //TODO Check this + // TODO Check this ($(element).get(0) as any).contentWindow.postMessage(JSON.stringify(data), '*'); - //}); + // }); }); } diff --git a/src/angularjs/entities/entity.ts b/src/angularjs/entities/entity.ts index 9b35cd6..91dcf31 100755 --- a/src/angularjs/entities/entity.ts +++ b/src/angularjs/entities/entity.ts @@ -50,11 +50,12 @@ export class Entity implements IEntity { // been turned on if (this.pathIsOn[key]) { resolve(); - } else { + } + else { this.pathIsOn[key] = true; // Start listening to the state - let stateRef = this.stateRef(key); + const stateRef = this.stateRef(key); stateRef.off('value'); @@ -62,10 +63,10 @@ export class Entity implements IEntity { // when we call push this method is called twice stateRef.on('value', (snapshot) => { - let time = snapshot.val(); + const time = snapshot.val(); - if (Defines.DEBUG) console.log('Entity ID: ' + this._id + ' Key: ' + key); - if (Defines.DEBUG) console.log('Date: ' + time + ' State time: ' + this.state[key]); + if (Defines.DEBUG) { console.log('Entity ID: ' + this._id + ' Key: ' + key); } + if (Defines.DEBUG) { console.log('Date: ' + time + ' State time: ' + this.state[key]); } // If the state isn't set either locally or remotely // or if it is set but the timestamp is lower than the remove value @@ -78,7 +79,7 @@ export class Entity implements IEntity { this.state[key] = time; // Get the ref - let ref = this.pathRef(key); + const ref = this.pathRef(key); // Add the value listener // TODO: Check this @@ -103,7 +104,7 @@ export class Entity implements IEntity { // This method strips the root of the Firebase reference to give a relative // path for batch writes relativeFirebasePath(ref: firebase.database.Reference): string { - return ref.toString().replace(this.Paths.firebase().toString(), ""); + return ref.toString().replace(this.Paths.firebase().toString(), ''); } pathOff(key: string) { @@ -137,7 +138,8 @@ export class Entity implements IEntity { setMeta(meta: Map | IStringAnyObject): void { if (meta instanceof Map) { this.meta = meta; - } else { + } + else { this.meta = new Map(Object.entries(meta)); } } @@ -155,15 +157,15 @@ export class Entity implements IEntity { return this.getMeta().get(key); } return null; - }; + } getMetaValue(key: string) { return this.metaValue(key); - }; + } setMetaValue(key: string, value: any) { this.getMeta().set(key, value); - }; + } serialize(): IStringAnyObject { return { @@ -171,7 +173,7 @@ export class Entity implements IEntity { _id: this._id, state: this.state, meta: this.getMetaObject() - } + }; } deserialize(se: IStringAnyObject) { diff --git a/src/angularjs/entities/message.ts b/src/angularjs/entities/message.ts index e7639e5..61810c1 100755 --- a/src/angularjs/entities/message.ts +++ b/src/angularjs/entities/message.ts @@ -35,6 +35,11 @@ export interface IMessage { updateDisplay(): void; } +export enum MessageSide { + Right = 'right', + Left = 'left' +} + export class Message implements IMessage { public read = false; @@ -71,16 +76,16 @@ export class Message implements IMessage { this.setType(MessageType.Text); } - if (this.type() == MessageType.Image || this.type() == MessageType.File) { + if (this.type() === MessageType.Image || this.type() === MessageType.File) { // Get the image and thumbnail URLs - let json = meta[MessageKeys.JSONv2]; + const json = meta[MessageKeys.JSONv2]; if (json) { - if (this.type() == MessageType.Image) { + if (this.type() === MessageType.Image) { this.thumbnailURL = this.CloudImage.cloudImage(json[MessageKeys.ImageURL], 200, 200); this.imageURL = json[MessageKeys.ImageURL]; } - if (this.type() == MessageType.File) { + if (this.type() === MessageType.File) { this.fileURL = json[MessageKeys.FileURL]; } } @@ -88,7 +93,7 @@ export class Message implements IMessage { // Our messages are on the right - other user's messages are // on the left - this.side = this.uid() == this.UserStore.currentUser().uid() ? MessageSide.Right : MessageSide.Left; + this.side = this.uid() === this.UserStore.currentUser().uid() ? MessageSide.Right : MessageSide.Left; this.timeString = this.Time.formatTimestamp(this.time(), this.Config.clockType); @@ -96,7 +101,7 @@ export class Message implements IMessage { if (this.uid()) { // We need to set the user here - if (this.uid() == this.UserStore.currentUser().uid()) { + if (this.uid() === this.UserStore.currentUser().uid()) { this.user = this.UserStore.currentUser(); } else { @@ -120,7 +125,7 @@ export class Message implements IMessage { hideTime: this.hideTime, hideName: this.hideName, side: this.side, - } + }; } updateDisplay() { @@ -129,7 +134,7 @@ export class Message implements IMessage { let hideDate = true; if (this.nextMessage) { - hideName = hideName || this.uid() == this.nextMessage.uid(); + hideName = hideName || this.uid() === this.nextMessage.uid(); } if (this.previousMessage) { hideDate = Utils.sameMinute(this.date(), this.previousMessage.date()); @@ -138,7 +143,7 @@ export class Message implements IMessage { this.hideName = hideName; this.hideTime = hideDate; - //console.log("Message: " + this.text() + ", user: " + this.uid() + ", h: " + this.date().getHours() + " m:" + this.date().getMinutes() + " hideName: " + hideName + ", hideDate: " + hideDate); + // console.log("Message: " + this.text() + ", user: " + this.uid() + ", h: " + this.date().getHours() + " m:" + this.date().getMinutes() + " hideName: " + hideName + ", hideDate: " + hideDate); } deserialize(sm: IStringAnyObject) { @@ -168,19 +173,19 @@ export class Message implements IMessage { } text(): string { - if (this.type() == MessageType.Text) { + if (this.type() === MessageType.Text) { return this.getMetaValue(MessageKeys.Text); } - else if (this.type() == MessageType.Image) { - return "Image"; + else if (this.type() === MessageType.Image) { + return 'Image'; } - else if (this.type() == MessageType.File) { - return "File"; + else if (this.type() === MessageType.File) { + return 'File'; } - else if (this.type() == MessageType.Location) { - return "Location"; + else if (this.type() === MessageType.Location) { + return 'Location'; } - return ""; + return ''; } sender(): IUser { @@ -234,11 +239,6 @@ export class Message implements IMessage { } -export enum MessageSide { - Right = 'right', - Left = 'left' -} - export interface IMessageFactory { buildFileMeta(fileName: string, mimeType: string, fileURL: string): Map; buildImageMeta(url: string, width: number, height: number): Map; @@ -301,12 +301,10 @@ class MessageFactory implements IMessageFactory { message[MessageKeys.Date] = database.ServerValue.TIMESTAMP; message[MessageKeys.Type] = type; - let read = new Map(); + const read = new Map(); - for (let i = 0; i < to.length; i++) { - const status = {}; - status[MessageKeys.Status] = 0; - read.set(to[i], status); + for (const t of to) { + read.set(t, { [MessageKeys.Status]: 0 }); } // Set my read status to read diff --git a/src/angularjs/entities/room.ts b/src/angularjs/entities/room.ts index 08838e1..7d96f9c 100755 --- a/src/angularjs/entities/room.ts +++ b/src/angularjs/entities/room.ts @@ -80,6 +80,7 @@ export interface IRoom extends IEntity { open(slot: number, duration?: number): void; removeUserUpdate(user: IUser): {}; rid(): string; + sendFileMessage(user: IUser, fileName: string, mimeType: string, fileURL: string): Promise; sendImageMessage(user: IUser, url: string, width: number, height: number): Promise; sendTextMessage(user: IUser, text: string): Promise; setActive(active: boolean): void; @@ -191,8 +192,6 @@ export class Room extends Entity implements IRoom { /** * If silent is true then this will not broadcast to update the UI. * Primarily this is used when deserializing - * - * @param silent */ update(silent = false) { this.updateName(); @@ -208,9 +207,9 @@ export class Room extends Entity implements IRoom { let i = 0; let name = null; - for (let key in this.typing) { + for (const key in this.typing) { if (this.typing.hasOwnProperty(key)) { - if (key == this.UserStore.currentUser().uid()) { + if (key === this.UserStore.currentUser().uid()) { continue; } name = this.typing[key]; @@ -219,7 +218,7 @@ export class Room extends Entity implements IRoom { } let typing = null; - if (i == 1) { + if (i === 1) { typing = name + '...'; } else if (i > 1) { @@ -244,9 +243,9 @@ export class Room extends Entity implements IRoom { // Otherwise build a room based on the users' names this.name = ''; - for (let key in this.users) { + for (const key in this.users) { if (this.users.hasOwnProperty(key)) { - let user = this.users[key]; + const user = this.users[key]; if (!user.isMe() && user.getName() && user.getName().length) { this.name += user.getName() + ', '; } @@ -262,10 +261,10 @@ export class Room extends Entity implements IRoom { if (this.isPublic()) { this.name = RoomDefaultNamePublic; } - else if (this.userCount() == 1) { + else if (this.userCount() === 1) { this.name = RoomDefaultNameEmpty; } - else if (this.getType() == RoomType.Group) { + else if (this.getType() === RoomType.Group) { this.name = RoomDefaultNameGroup; } else { @@ -283,7 +282,7 @@ export class Room extends Entity implements IRoom { if (!this.isOn && this.rid()) { this.isOn = true; - let on = () => { + const on = () => { // When a user changes online state update the room this.userOnlineStateChangedNotificationOff = this.$rootScope.$on(N.UserOnlineStateChanged, (event, user: IUser) => { Log.notification(N.UserOnlineStateChanged, 'Room'); @@ -328,7 +327,8 @@ export class Room extends Entity implements IRoom { } }); - } else { + } + else { resolve(); } }); @@ -370,11 +370,10 @@ export class Room extends Entity implements IRoom { this.typingOff(); this.messagesOff(); - let type = this.getType(); + const type = this.getType(); switch (type) { - case RoomType.Public: - { + case RoomType.Public: { this.RoomFactory.removeUserFromRoom(this.UserStore.currentUser(), this); } } @@ -420,7 +419,7 @@ export class Room extends Entity implements IRoom { if (this.userCount() <= 1) { type = RoomType.Invalid; } - else if (this.userCount() == 2) { + else if (this.userCount() === 2) { type = RoomType.OneToOne; } else { @@ -433,9 +432,9 @@ export class Room extends Entity implements IRoom { updateType() { const type = this.calculatedType(); - if (type != this.getType()) { + if (type !== this.getType()) { // One important thing is that we can't go from group -> 1to1 - if (this.getType() != RoomType.Group) { + if (this.getType() !== RoomType.Group) { this.RoomFactory.updateRoomType(this.rid(), type); } } @@ -487,7 +486,7 @@ export class Room extends Entity implements IRoom { } isPublic(): boolean { - return this.getType() == RoomType.Public; + return this.getType() === RoomType.Public; } rid(): string { @@ -547,7 +546,6 @@ export class Room extends Entity implements IRoom { /** * Add the user to the room and add the room to the * user in Firebase - * @param status */ join(status: UserStatus): Promise { return this.RoomFactory.addUserToRoom(this.UserStore.currentUser(), this, status); @@ -601,17 +599,17 @@ export class Room extends Entity implements IRoom { } getUserStatus(user: IUser): UserStatus { - let info = this.getUserInfo(user); + const info = this.getUserInfo(user); return info ? info[UserKeys.Status] : null; } getUsers(): { [uid: string]: IUser } { - let users = {}; - for (let key in this.users) { + const users = {}; + for (const key in this.users) { if (this.users.hasOwnProperty(key)) { - let user = this.users[key]; + const user = this.users[key]; if (user.meta && this.UserStore.currentUser() && this.UserStore.currentUser().meta) { - if (user.uid() != this.UserStore.currentUser().uid()) { + if (user.uid() !== this.UserStore.currentUser().uid()) { users[user.uid()] = user; } } @@ -622,7 +620,7 @@ export class Room extends Entity implements IRoom { getUserIDs(): Array { const users = new Array(); - for (let key in this.users) { + for (const key in this.users) { if (this.users.hasOwnProperty(key)) { users.push(key); } @@ -639,10 +637,10 @@ export class Room extends Entity implements IRoom { // get the owner's ID let data = null; - for (let key in this.usersMeta) { + for (const key in this.usersMeta) { if (this.usersMeta.hasOwnProperty(key)) { data = this.usersMeta[key]; - if (data.status == UserStatus.Owner) { + if (data.status === UserStatus.Owner) { break; } } @@ -678,11 +676,11 @@ export class Room extends Entity implements IRoom { getOnlineUserCount() { let i = 0; - for (let key in this.usersMeta) { + for (const key in this.usersMeta) { if (this.usersMeta.hasOwnProperty(key)) { - let user = this.usersMeta[key]; + const user = this.usersMeta[key]; if (this.UserStore.currentUser() && this.UserStore.currentUser().meta) { - if ((this.UserStore.users[user.uid].online || this.UserStore.currentUser().uid() == user.uid)) { + if ((this.UserStore.users[user.uid].online || this.UserStore.currentUser().uid() === user.uid)) { i++; } } @@ -693,7 +691,7 @@ export class Room extends Entity implements IRoom { userCount() { let i = 0; - for (let key in this.users) { + for (const key in this.users) { if (this.users.hasOwnProperty(key)) { i++; } @@ -705,12 +703,12 @@ export class Room extends Entity implements IRoom { let usersInRoom = 0; const totalUsers = this.userCount(); - for (let i = 0; i < users.length; i++) { - if (this.users[users[i].uid()]) { + for (const user of users) { + if (this.users[user.uid()]) { usersInRoom++; } } - return usersInRoom == users.length && usersInRoom == totalUsers; + return usersInRoom === users.length && usersInRoom === totalUsers; } /*********************************** @@ -772,8 +770,8 @@ export class Room extends Entity implements IRoom { return this.sendMessage(messageMeta, user); } - sendMessage(messageMeta: {}, user): Promise { - let innerSendMessage = ((message, user) => { + sendMessage(messageMeta: {}, user: IUser): Promise { + const innerSendMessage = (() => { // Get a ref to the room const ref = this.Paths.roomMessagesRef(this.rid()); @@ -796,16 +794,16 @@ export class Room extends Entity implements IRoom { }); - return innerSendMessage(messageMeta, user).catch((error) => { + return innerSendMessage().catch((error) => { this.Presence.update().then(() => { - return innerSendMessage(messageMeta, user); + return innerSendMessage(); }); }); } addMessagesFromSerialization(sm) { - for (let i = 0; i < sm.length; i++) { - this.addMessageFromSerialization(sm[i]); + for (const s of sm) { + this.addMessageFromSerialization(s); } // Now update all the message displays @@ -821,12 +819,11 @@ export class Room extends Entity implements IRoom { return this.MessageFactory.createMessage(mid, metaValue); } - getMessagesNewerThan(date: Date = null, number: number = null): Array { + getMessagesNewerThan(date: Date = null, amount: number = null): Array { const messages = new Array(); - for (let i = 0; i < this.messages.length; i++) { - const message = this.messages[i]; + for (const message of this.messages) { if (!date || message.date() > date) { - messages.push(this.messages[i]); + messages.push(message); } } return messages; @@ -878,34 +875,33 @@ export class Room extends Entity implements IRoom { } } - getMessagesOlderThan(date: Date = null, number: number = null): Array { + getMessagesOlderThan(date: Date = null, amount: number = null): Array { const messages = new Array(); - for (let i = 0; i < this.messages.length; i++) { - const message = this.messages[i]; + for (const message of this.messages) { if (!date || message.date() < date) { - messages.push(this.messages[i]); + messages.push(message); } } return messages; } - loadLocalMessages(fromDate: Date, number: number): Array { + loadLocalMessages(fromDate: Date, amount: number): Array { const messages = new Array(); return messages; } // Load m - loadMessagesOlderThan(date: Date = null, number: number): Promise> { + loadMessagesOlderThan(date: Date = null, amount: number): Promise> { - let ref = this.Paths.roomMessagesRef(this.rid()); - let query = ref.orderByChild(MessageKeys.Date).limitToLast(number); + const ref = this.Paths.roomMessagesRef(this.rid()); + let query = ref.orderByChild(MessageKeys.Date).limitToLast(amount); if (date) { query = query.endAt(date.getTime() - 1, MessageKeys.Date); } - return >>query.once('value').then((snapshot: firebase.database.DataSnapshot) => { + return query.once('value').then((snapshot: firebase.database.DataSnapshot) => { const data = snapshot.val(); const messages = new Array(); if (data) { @@ -916,7 +912,7 @@ export class Room extends Entity implements IRoom { return messages; }).catch((e) => { console.log(e.message); - }); + }) as Promise>; } loadMoreMessages(numberOfMessages: number = 10): Promise> { @@ -967,15 +963,15 @@ export class Room extends Entity implements IRoom { } deduplicateMessages() { - let uniqueMessages = []; + const uniqueMessages = []; // Deduplicate list let lastMID = null; - for (let i = 0; i < this.messages.length; i++) { - if (this.messages[i].mid != lastMID) { - uniqueMessages.push(this.messages[i]); + for (const message of this.messages) { + if (message.mid !== lastMID) { + uniqueMessages.push(message); } - lastMID = this.messages[i].mid; + lastMID = message.mid; } this.messages = uniqueMessages; @@ -997,11 +993,11 @@ export class Room extends Entity implements IRoom { markRead() { - let messages = this.unreadMessages; + const messages = this.unreadMessages; if (messages && messages.length > 0) { - for (let i in messages) { + for (const i in messages) { if (messages.hasOwnProperty(i)) { messages[i].markRead(); } @@ -1016,14 +1012,15 @@ export class Room extends Entity implements IRoom { this.sendBadgeChangedNotification(); // Mark the date when the thread was read - if (!this.isPublic()) + if (!this.isPublic()) { this.UserStore.currentUser().markRoomReadTime(this.rid()); + } } updateImageURL(imageURL) { // Compare to the old URL - let imageChanged = imageURL != this.metaValue(RoomKeys.Image); + const imageChanged = imageURL !== this.metaValue(RoomKeys.Image); if (imageChanged) { this.setMetaValue(RoomKeys.Image, imageURL); this.setImage(imageURL, false); @@ -1033,13 +1030,13 @@ export class Room extends Entity implements IRoom { setImage(image, isData = false) { - this.showImage = this.getType() == RoomType.Public; + this.showImage = this.getType() === RoomType.Public; if (!image) { image = this.Environment.defaultRoomPictureURL(); } else { - if (isData || image == this.Environment.defaultRoomPictureURL()) { + if (isData || image === this.Environment.defaultRoomPictureURL()) { this.thumbnail = image; } else { @@ -1061,11 +1058,11 @@ export class Room extends Entity implements IRoom { transcript(): string { - let transcript: string = ''; + let transcript = ''; - for (let i in this.messages) { + for (const i in this.messages) { if (this.messages.hasOwnProperty(i)) { - let m = this.messages[i]; + const m = this.messages[i]; transcript += this.Time.formatTimestamp(m.time()) + ' ' + m.user.getName() + ': ' + m.text() + '\n'; } } @@ -1101,19 +1098,19 @@ export class Room extends Entity implements IRoom { const superData = super.serialize(); const m = []; - for (let i = 0; i < this.messages.length; i++) { - m.push(this.messages[i].serialize()); + for (const message of this.messages) { + m.push(message.serialize()); } const data = { minimized: this.minimized, width: this.width, height: this.height, - //offset: this.offset, + // offset: this.offset, messages: m, usersMeta: this.usersMeta, deleted: this.deleted, isOpen: this.isOpen, - //badge: this.badge, + // badge: this.badge, associatedUserID: this.associatedUserID, offset: this.offset, readTimestamp: this.readTimestamp, @@ -1129,19 +1126,19 @@ export class Room extends Entity implements IRoom { this.height = sr.height; this.deleted = sr.deleted; this.isOpen = sr.isOpen; - //this.badge = sr.badge; + // this.badge = sr.badge; this.associatedUserID = sr.associatedUserID; this.offset = sr.offset; this.readTimestamp = sr.readTimestamp; - //this.setUsersMeta(sr.usersMeta); + // this.setUsersMeta(sr.usersMeta); - for (let key in sr.usersMeta) { + for (const key in sr.usersMeta) { if (sr.usersMeta.hasOwnProperty(key)) { this.addUserMeta(sr.usersMeta[key]); } } - //this.offset = sr.offset; + // this.offset = sr.offset; this.addMessagesFromSerialization(sr.messages); @@ -1176,7 +1173,7 @@ export class Room extends Entity implements IRoom { this.usersMeta[meta[userUID]] = meta; // Add the user object - let user = this.UserStore.getOrCreateUserWithID(meta[userUID]); + const user = this.UserStore.getOrCreateUserWithID(meta[userUID]); this.users[user.uid()] = user; this.update(false); @@ -1191,11 +1188,11 @@ export class Room extends Entity implements IRoom { usersMetaOn() { - let roomUsersRef = this.Paths.roomUsersRef(this.rid()); + const roomUsersRef = this.Paths.roomUsersRef(this.rid()); roomUsersRef.on('child_added', (snapshot) => { if (snapshot.val() && snapshot.val()) { - let meta = snapshot.val(); + const meta = snapshot.val(); meta.uid = snapshot.key; this.addUserMeta(meta); } @@ -1203,7 +1200,7 @@ export class Room extends Entity implements IRoom { roomUsersRef.on('child_removed', (snapshot) => { if (snapshot.val()) { - let meta = snapshot.val(); + const meta = snapshot.val(); meta.uid = snapshot.key; this.removeUserMeta(meta); } @@ -1217,8 +1214,8 @@ export class Room extends Entity implements IRoom { userDeletedDate(): Promise { const ref = this.Paths.roomUsersRef(this.rid()).child(this.UserStore.currentUser().uid()); return ref.once('value').then((snapshot) => { - let val = snapshot.val(); - if (val && val.status == UserStatus.Closed) { + const val = snapshot.val(); + if (val && val.status === UserStatus.Closed) { return val.time; } return null; @@ -1244,7 +1241,7 @@ export class Room extends Entity implements IRoom { } shouldIncrementUnreadMessageBadge() { - return (!this.active || this.minimized || !this.RoomPositionManager.roomIsOpen(this));// && !this.isPublic(); + return (!this.active || this.minimized || !this.RoomPositionManager.roomIsOpen(this)); // && !this.isPublic(); } messagesOn(timestamp) { @@ -1298,8 +1295,8 @@ export class Room extends Entity implements IRoom { if (this.Visibility.getIsHidden()) { // Only make a sound for messages that were received less than // 30 seconds ago - if (DEBUG) console.log('Now: ' + new Date().getTime() + ', Date now: ' + this.Time.now() + ', Message: ' + snapshot.val()[MessageKeys.Date]); - if (DEBUG) console.log('Diff: ' + Math.abs(this.Time.now() - snapshot.val().time)); + if (DEBUG) { console.log('Now: ' + new Date().getTime() + ', Date now: ' + this.Time.now() + ', Message: ' + snapshot.val()[MessageKeys.Date]); } + if (DEBUG) { console.log('Diff: ' + Math.abs(this.Time.now() - snapshot.val().time)); } if (Math.abs(this.Time.now() - snapshot.val()[MessageKeys.Date]) / 1000 < 30) { this.SoundEffects.messageReceived(); } @@ -1311,13 +1308,13 @@ export class Room extends Entity implements IRoom { ref.on('child_removed', (snapshot) => { if (snapshot.val()) { for (let i = 0; i < this.messages.length; i++) { - let message = this.messages[i]; + const message = this.messages[i]; if (message.mid == snapshot.key) { this.messages.splice(i, 1); break; } } - //this.$rootScope.$broadcast(DeleteMessageNotification, snapshot.val().meta.mid); + // this.$rootScope.$broadcast(DeleteMessageNotification, snapshot.val().meta.mid); this.update(false); } }); @@ -1328,7 +1325,7 @@ export class Room extends Entity implements IRoom { this.sortMessages(); this.deduplicateMessages(); - let toRemove = this.messages.length - 100; + const toRemove = this.messages.length - 100; if (toRemove > 0) { for (let j = 0; j < toRemove; j++) { this.messages.shift(); @@ -1350,7 +1347,7 @@ export class Room extends Entity implements IRoom { typingOn() { // Handle typing - let ref = this.Paths.roomTypingRef(this.rid()); + const ref = this.Paths.roomTypingRef(this.rid()); ref.on('child_added', (snapshot) => { this.typing[snapshot.key] = snapshot.val().name; @@ -1405,7 +1402,6 @@ export class Room extends Entity implements IRoom { /** * Remove a public room - * @returns {promise} */ removeFromPublicRooms(): Promise { const ref = this.Paths.publicRoomRef(this.getRID()); @@ -1413,8 +1409,8 @@ export class Room extends Entity implements IRoom { } userIsMember(user) { - let userStatus = this.getUserStatus(user); - return userStatus == UserStatus.Member || userStatus == UserStatus.Owner; + const userStatus = this.getUserStatus(user); + return userStatus === UserStatus.Member || userStatus === UserStatus.Owner; } addUserUpdate(user: IUser, status: UserStatus): {} { @@ -1427,7 +1423,7 @@ export class Room extends Entity implements IRoom { removeUserUpdate(user: IUser): {} { const update = {}; let data = null; - if (this.getType() == RoomType.OneToOne) { + if (this.getType() === RoomType.OneToOne) { data = {}; data[RoomKeys.Deleted] = database.ServerValue.TIMESTAMP; data[RoomKeys.Name] = user.getName(); diff --git a/src/angularjs/entities/user.ts b/src/angularjs/entities/user.ts index 29ffe50..fb25391 100755 --- a/src/angularjs/entities/user.ts +++ b/src/angularjs/entities/user.ts @@ -87,7 +87,8 @@ class User extends Entity implements IUser { name(value: string): string { if (Utils.unORNull(value)) { return this.getName(); - } else { + } + else { this.setName(value); } } @@ -104,7 +105,8 @@ class User extends Entity implements IUser { status(value: string) { if (Utils.unORNull(value)) { return this.getStatus(); - } else { + } + else { this.setStatus(value); } } @@ -120,7 +122,8 @@ class User extends Entity implements IUser { location(value) { if (Utils.unORNull(value)) { return this.getLocation(); - } else { + } + else { this.setLocation(value); } } @@ -136,7 +139,8 @@ class User extends Entity implements IUser { countryCode(value: string) { if (Utils.unORNull(value)) { return this.getCountryCode(); - } else { + } + else { this.setCountryCode(value); } } @@ -152,7 +156,8 @@ class User extends Entity implements IUser { gender(value: string) { if (Utils.unORNull(value)) { return this.getGender(); - } else { + } + else { this.setGender(value); } } @@ -168,7 +173,8 @@ class User extends Entity implements IUser { profileLink(value: string) { if (Utils.unORNull(value)) { return this.getProfileLink(); - } else { + } + else { this.setProfileLink(value); } } @@ -184,7 +190,8 @@ class User extends Entity implements IUser { homepageLink(value: string) { if (Utils.unORNull(value)) { return this.getHomepageLink(); - } else { + } + else { this.setHomepageLink(value); } } @@ -200,7 +207,8 @@ class User extends Entity implements IUser { homepageText(value: string) { if (Utils.unORNull(value)) { return this.getHomepageText(); - } else { + } + else { this.setHomepageText(value); } } @@ -216,7 +224,8 @@ class User extends Entity implements IUser { profileHTML(value: string) { if (Utils.unORNull(value)) { return this.getProfileHTML(); - } else { + } + else { this.setProfileHTML(value); } } @@ -232,7 +241,8 @@ class User extends Entity implements IUser { allowInvites(value?: UserAllowInvites) { if (Utils.unORNull(value)) { return this.getAllowInvites(); - } else { + } + else { this.setAllowInvites(value); } } @@ -252,7 +262,8 @@ class User extends Entity implements IUser { imageURL(value?: string) { if (Utils.unORNull(value)) { return this.getImageURL(); - } else { + } + else { this.setImageURL(value); } } @@ -315,7 +326,7 @@ class User extends Entity implements IUser { // This function should only ever be called on the root user if (!this.isMe()) { - console.log("Can be invited should only be called on the root user"); + console.log('Can be invited should only be called on the root user'); return false; } @@ -323,17 +334,17 @@ class User extends Entity implements IUser { return true; } - let allowInvites = this.allowInvites(); - return Utils.unORNull(allowInvites) || allowInvites == UserAllowInvites.Everyone; + const allowInvites = this.allowInvites(); + return Utils.unORNull(allowInvites) || allowInvites === UserAllowInvites.Everyone; } allowInvitesFrom(type: UserAllowInvites): boolean { - return this.allowInvites() == type; + return this.allowInvites() === type; } updateImageURL(imageURL: string): Promise { // Compare to the old URL - let imageChanged = imageURL != this.imageURL(); + const imageChanged = imageURL !== this.imageURL(); if (imageChanged) { this.setMetaValue(UserKeys.ImageURL, imageURL); this.setImageURL(imageURL); @@ -347,7 +358,7 @@ class User extends Entity implements IUser { // TODO: Improve this this.image = this.Environment.defaultProfilePictureURL(); } - else if (isData || image == this.Environment.defaultProfilePictureURL()) { + else if (isData || image === this.Environment.defaultProfilePictureURL()) { this.image = image; } else { @@ -367,7 +378,7 @@ class User extends Entity implements IUser { } hasImage(): boolean { - return this.image && this.image != this.Environment.defaultProfilePictureURL(); + return this.image && this.image !== this.Environment.defaultProfilePictureURL(); } addRoomUpdate(room: IRoom): { [path: string]: string } { @@ -392,7 +403,7 @@ class User extends Entity implements IUser { async addFriendWithUID(uid: string): Promise { const ref = this.Paths.userFriendsRef(this.uid()); - const data = { [uid]: { uid: uid } }; + const data = { [uid]: { uid } }; await ref.update(data); return this.updateState(PathKeys.FriendsPath); @@ -414,7 +425,6 @@ class User extends Entity implements IUser { * Remove a specified user as a friend * @package friend - the user to be removed as a friend */ - removeFriend(friend: IUser): void; removeFriend(friend?: IUser) { // This method is added to the object when the friend is // added initially @@ -425,7 +435,7 @@ class User extends Entity implements IUser { blockUserWithUID(uid: string) { const ref = this.Paths.userBlockedRef(this.uid()); - const data = { [uid]: { uid: uid } }; + const data = { [uid]: { uid } }; ref.update(data).then(() => { return this.updateState(PathKeys.BlockedPath); diff --git a/src/angularjs/network/auto-login.ts b/src/angularjs/network/auto-login.ts index 367ee42..20b3089 100755 --- a/src/angularjs/network/auto-login.ts +++ b/src/angularjs/network/auto-login.ts @@ -86,10 +86,12 @@ class AutoLogin implements IAutoLogin { if (this.autoLoginEnabled()) { if (this.token != '') { return this.Credential.customToken(this.token); - } else { + } + else { return this.Credential.emailAndPassword(this.username, this.password); } - } else { + } + else { return null; } } diff --git a/src/angularjs/persistence/user-store.ts b/src/angularjs/persistence/user-store.ts index c2a18bb..d90afa8 100755 --- a/src/angularjs/persistence/user-store.ts +++ b/src/angularjs/persistence/user-store.ts @@ -59,7 +59,8 @@ class UserStore implements IUserStore, IBeforeUnloadListener { getUserWithID(uid: string): IUser { if (uid !== null) { return this.users[uid]; - } else { + } + else { return null; } } diff --git a/src/angularjs/services/before-unload.ts b/src/angularjs/services/before-unload.ts index d9eab8d..8fbd97a 100755 --- a/src/angularjs/services/before-unload.ts +++ b/src/angularjs/services/before-unload.ts @@ -30,7 +30,8 @@ class BeforeUnload implements IBeforeUnload { if ($window.addEventListener) { $window.addEventListener('beforeunload', beforeUnloadHandler); - } else { + } + else { $window.onbeforeunload = beforeUnloadHandler; } } diff --git a/src/angularjs/services/log.ts b/src/angularjs/services/log.ts index 994c3b7..2d3ecdf 100755 --- a/src/angularjs/services/log.ts +++ b/src/angularjs/services/log.ts @@ -6,7 +6,8 @@ export class Log { if (DEBUG) { if (!context) { context = '' - } else { + } + else { context = ', context: ' + context } console.log('Notification: ' + notification + context) diff --git a/src/angularjs/services/room-position-manager.ts b/src/angularjs/services/room-position-manager.ts index b463d3b..2fb63bf 100755 --- a/src/angularjs/services/room-position-manager.ts +++ b/src/angularjs/services/room-position-manager.ts @@ -18,7 +18,7 @@ export interface IRoomPositionManager { closeAllRooms(): void; closeRoom(room: IRoom): void; effectiveScreenWidth(): number; - getRooms(): any[]; + getRooms(): IRoom[]; insertRoom(room: IRoom, slot: number, duration: number): void; offsetForSlot(slot: number): number; roomDragged(room: IRoom): void; diff --git a/tslint.json b/tslint.json index f0adae9..0afbbf5 100644 --- a/tslint.json +++ b/tslint.json @@ -27,10 +27,7 @@ ], "interface-name": false, "max-classes-per-file": false, - "max-line-length": [ - true, - 140 - ], + "max-line-length": false, "member-access": false, "member-ordering": [ true, @@ -81,12 +78,18 @@ "no-output-on-prefix": true, "no-output-rename": true, "no-outputs-metadata-property": true, + "no-shadowed-variable": false, "template-banana-in-box": true, "template-no-negated-async": true, "use-lifecycle-interface": true, - "use-pipe-transform-interface": true + "use-pipe-transform-interface": true, + "one-line": [ + true, + "check-open-brace", + "check-whitespace" + ] }, "rulesDirectory": [ "codelyzer" ] -} \ No newline at end of file +}