|
|
|
@@ -1,6 +1,5 @@ |
|
|
|
import { Component, OnInit } from '@angular/core'; |
|
|
|
import * as faker from 'faker'; |
|
|
|
import * as moment from 'moment'; |
|
|
|
|
|
|
|
type IMember = { |
|
|
|
name: string, |
|
|
|
@@ -15,6 +14,7 @@ type IMember = { |
|
|
|
}) |
|
|
|
export class ChatPage implements OnInit { |
|
|
|
isPollChecked: boolean = true; |
|
|
|
myMessage: string = ''; |
|
|
|
|
|
|
|
chatData: Array<{ |
|
|
|
over: number, |
|
|
|
@@ -37,6 +37,7 @@ export class ChatPage implements OnInit { |
|
|
|
}> = []; |
|
|
|
|
|
|
|
members: Array<IMember> = []; |
|
|
|
myAccount: IMember; |
|
|
|
|
|
|
|
constructor() { } |
|
|
|
|
|
|
|
@@ -52,6 +53,8 @@ export class ChatPage implements OnInit { |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
this.myAccount = this.members[myAccountIndex]; |
|
|
|
|
|
|
|
|
|
|
|
for (let i = 0; i < 5; i += 1) { |
|
|
|
let options = []; |
|
|
|
@@ -66,7 +69,7 @@ export class ChatPage implements OnInit { |
|
|
|
let ballChat = []; |
|
|
|
|
|
|
|
for (let balls = 0; balls < 6; balls += 1) { |
|
|
|
let randomNumber = Math.floor(Math.random() * 15); |
|
|
|
let randomNumber = Math.floor(Math.random() * 3) + 1; |
|
|
|
let chat = []; |
|
|
|
|
|
|
|
for (let k = 0; k < randomNumber; k += 1) { |
|
|
|
@@ -96,6 +99,82 @@ export class ChatPage implements OnInit { |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
setTimeout(() => { |
|
|
|
this.scrollToEnd(); |
|
|
|
}, 500); |
|
|
|
|
|
|
|
|
|
|
|
setTimeout(() => { |
|
|
|
let options = []; |
|
|
|
|
|
|
|
for (let j = 0; j < 4; j += 1) { |
|
|
|
options.push({ |
|
|
|
text: faker.lorem.word(), |
|
|
|
pollUserCount: faker.random.number() |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
this.chatData.push({ |
|
|
|
over: this.chatData.length - 1, |
|
|
|
ballChat: [{ |
|
|
|
ball: 0, |
|
|
|
chat: [], |
|
|
|
}], |
|
|
|
triviaQuestion: { |
|
|
|
question: faker.lorem.sentence(), |
|
|
|
maxUserCount: Math.max.apply(Math, options.map(function(o) { return o.pollUserCount; })), |
|
|
|
options: options, |
|
|
|
selectedAnswer: null, |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
setTimeout(() => { |
|
|
|
this.scrollToEnd(); |
|
|
|
}, 500); |
|
|
|
|
|
|
|
|
|
|
|
}, 3000); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
scrollToEnd() { |
|
|
|
try { |
|
|
|
let lastOver = this.chatData.length - 1; |
|
|
|
let lastBall = this.chatData[lastOver].ballChat? this.chatData[lastOver].ballChat.length - 1 : null; |
|
|
|
let lastChat = this.chatData[lastOver].ballChat[lastBall].chat ? this.chatData[lastOver].ballChat[lastBall].chat.length - 1 : null; |
|
|
|
|
|
|
|
document.querySelector('#chat-' + lastOver + '-' + lastBall + '-' + lastChat).scrollIntoView({ |
|
|
|
behavior: 'smooth', |
|
|
|
block: 'start' |
|
|
|
}); |
|
|
|
} catch { |
|
|
|
document.querySelector('#over-' + (this.chatData.length - 1).toString()).scrollIntoView({ |
|
|
|
behavior: 'smooth', |
|
|
|
block: 'start' |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
sendMessage() { |
|
|
|
let lastOver = this.chatData.length - 1; |
|
|
|
let lastBall = this.chatData[lastOver].ballChat.length - 1; |
|
|
|
let lastChat = this.chatData[lastOver].ballChat[lastBall].chat.length - 1; |
|
|
|
|
|
|
|
if (lastChat < 0) { |
|
|
|
lastChat = 0; |
|
|
|
} |
|
|
|
|
|
|
|
this.chatData[lastOver].ballChat[lastBall].chat.push({ |
|
|
|
user: this.myAccount, |
|
|
|
text: this.myMessage |
|
|
|
}); |
|
|
|
|
|
|
|
setTimeout(() => { |
|
|
|
this.scrollToEnd(); |
|
|
|
|
|
|
|
this.myMessage = ''; |
|
|
|
}, 100); |
|
|
|
} |
|
|
|
|
|
|
|
} |