Refactor/chat history #17

Merged
KevinMidboe merged 4 commits from refactor/chat-history into master 2020-06-26 11:28:59 +00:00
Showing only changes of commit 1e0a76757a - Show all commits

View File

@@ -43,9 +43,11 @@
<Chat
class="outer-chat"
:chatHistory="chatHistory"
:historyPageSize="historyPageSize"
:usernameAllowed="usernameAllowed"
v-on:message="sendMessage"
v-on:username="setUsername"
@loadMoreHistory="loadMoreHistory"
@message="sendMessage"
@username="setUsername"
/>
</div>
<Vipps class="vipps" :amount="1" />
@@ -74,6 +76,9 @@ export default {
attendeesFetched: false,
winnersFetched: false,
chatHistory: [],
historyPage: 0,
historyPageSize: 100,
lastHistoryPage: false,
usernameAccepted: false,
username: null,
wasDisconnected: false,
@@ -158,6 +163,15 @@ export default {
sendMessage: function(msg) {
this.socket.emit("chat", { message: msg });
},
loadMoreHistory: function() {
const { historyPage, historyPageSize } = this;
const page = historyPage + 1;
getChatHistory(page * historyPageSize, historyPageSize).then(messages => {
this.chatHistory = messages.concat(this.chatHistory);
this.historyPage = page;
});
},
getWinners: async function() {
let response = await winners();
if (response) {