finish dms
This commit is contained in:
parent
909d47f331
commit
fabc1e51cb
3 changed files with 58 additions and 29 deletions
|
@ -53,7 +53,8 @@
|
||||||
align-items: center;
|
align-items: center;
|
||||||
font-weight: 1000;
|
font-weight: 1000;
|
||||||
font-size: 1.5rem;
|
font-size: 1.5rem;
|
||||||
}
|
|
||||||
|
right: 0;}
|
||||||
|
|
||||||
.room-name {
|
.room-name {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
@ -71,6 +72,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.roomDisplayCenter {
|
.roomDisplayCenter {
|
||||||
|
position: relative;
|
||||||
display: flex;
|
display: flex;
|
||||||
width: calc(100% - 25em);
|
width: calc(100% - 25em);
|
||||||
height: 100%;
|
height: 100%;
|
||||||
|
@ -170,3 +172,9 @@
|
||||||
.message-content {
|
.message-content {
|
||||||
flex-grow: 0;
|
flex-grow: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.loadMessages {
|
||||||
|
position: absolute;
|
||||||
|
right: 0;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
|
@ -70,12 +70,12 @@ const data = {
|
||||||
rooms: {},
|
rooms: {},
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadRoomPage(room_id) {
|
async function loadRoomPage(room) {
|
||||||
let room = data.rooms[room_id]
|
|
||||||
let request = (await chatload (
|
let request = (await chatload (
|
||||||
room.newest_msg,
|
room.newest_msg,
|
||||||
room.page,
|
room.page,
|
||||||
room_id
|
room.room_id
|
||||||
))
|
))
|
||||||
|
|
||||||
if (request.json == undefined) {
|
if (request.json == undefined) {
|
||||||
|
@ -83,17 +83,28 @@ async function loadRoomPage(room_id) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let messages = room.display.getElementsByClassName('messages')[0]
|
||||||
for (const msg of request.json) {
|
for (const msg of request.json) {
|
||||||
room.messages.push(msg)
|
room.messages.push(msg)
|
||||||
|
messages.appendChild(await parseMessageImpl(msg))
|
||||||
}
|
}
|
||||||
|
|
||||||
room.page++
|
room.page++
|
||||||
|
|
||||||
|
return request.json.length > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadRoom(room_id) {
|
async function loadRoom(room_id) {
|
||||||
let room = data.rooms[room_id]
|
let room = data.rooms[room_id]
|
||||||
|
|
||||||
let request = (await loadusers(room.users))
|
let batch = []
|
||||||
|
for (const user_id of room.users) {
|
||||||
|
if (data.users[user_id]) continue
|
||||||
|
batch.push(user_id)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (batch.length > 1) {
|
||||||
|
let request = (await loadusers(batch))
|
||||||
if (request.status != 200) {
|
if (request.status != 200) {
|
||||||
location.href = '/login'
|
location.href = '/login'
|
||||||
} else {
|
} else {
|
||||||
|
@ -101,18 +112,9 @@ async function loadRoom(room_id) {
|
||||||
data.users[user.user_id] = user
|
data.users[user.user_id] = user
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
room.page = 0
|
room.display = createRoomDisplay(room, loadRoomPage)
|
||||||
room.messages = []
|
|
||||||
if (room.newest_msg == undefined || room.newest_msg < 0)
|
|
||||||
room.newest_msg = Number.MAX_SAFE_INTEGER
|
|
||||||
await loadRoomPage(room_id)
|
|
||||||
room.newest_msg = Math.max(
|
|
||||||
...room.messages.map(m => m.message_id)
|
|
||||||
)
|
|
||||||
room.page = 0
|
|
||||||
|
|
||||||
room.display = createRoomDisplay(room)
|
|
||||||
|
|
||||||
let displays = document.getElementById("center")
|
let displays = document.getElementById("center")
|
||||||
displays.appendChild(room.display)
|
displays.appendChild(room.display)
|
||||||
|
@ -125,15 +127,20 @@ async function loadRoom(room_id) {
|
||||||
button.classList.add('current')
|
button.classList.add('current')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
room.page = 0
|
||||||
|
room.messages = []
|
||||||
|
if (room.newest_msg == undefined || room.newest_msg < 0)
|
||||||
|
room.newest_msg = Number.MAX_SAFE_INTEGER
|
||||||
|
await loadRoomPage(room)
|
||||||
|
room.newest_msg = Math.min(
|
||||||
|
...room.messages.map(m => m.message_id)
|
||||||
|
)
|
||||||
|
room.page = 0
|
||||||
|
|
||||||
let sidebar = document.getElementById("sidebar")
|
let sidebar = document.getElementById("sidebar")
|
||||||
sidebar.appendChild(button)
|
sidebar.appendChild(button)
|
||||||
room.button = button
|
room.button = button
|
||||||
|
|
||||||
let messages = room.display.getElementsByClassName('messages')[0]
|
|
||||||
for (const message of room.messages) {
|
|
||||||
messages.appendChild(await parseMessageImpl(message))
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!room.people) room.people = room.people = {}
|
if (!room.people) room.people = room.people = {}
|
||||||
|
|
||||||
let people = room.display.getElementsByClassName("roomDisplayPeople")[0]
|
let people = room.display.getElementsByClassName("roomDisplayPeople")[0]
|
||||||
|
@ -186,6 +193,7 @@ async function onMessage(message) {
|
||||||
if (event.user_id == data.self.user_id) {
|
if (event.user_id == data.self.user_id) {
|
||||||
room.display.remove()
|
room.display.remove()
|
||||||
room.button.remove()
|
room.button.remove()
|
||||||
|
delete data.rooms[event.room_id]
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -202,13 +210,13 @@ async function onMessage(message) {
|
||||||
async function init() {
|
async function init() {
|
||||||
|
|
||||||
let request = (await loadself());
|
let request = (await loadself());
|
||||||
data.self = request.json
|
|
||||||
|
|
||||||
if (request.json == undefined) {
|
if (request.json == undefined) {
|
||||||
location.href = '/login'
|
location.href = '/login'
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data.self = request.json
|
||||||
data.users[data.self.user_id] = data.self
|
data.users[data.self.user_id] = data.self
|
||||||
|
|
||||||
render()
|
render()
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { div, a, pfp, span, i, parse, parseDate, p, form, input, svg, path, parseMonth, g } from './main.js'
|
import { div, a, pfp, span, i, parse, parseDate, p, form, input, svg, path, parseMonth, g, button } from './main.js'
|
||||||
import { postlike, postcomment, loadcommentspage, chatsend, chatadd, chatleave } from './api.js';
|
import { postlike, postcomment, loadcommentspage, chatsend, chatadd, chatleave } from './api.js';
|
||||||
|
|
||||||
window.parse = parse;
|
window.parse = parse;
|
||||||
|
@ -370,10 +370,23 @@ export function createSingleLineInput(attributes, onSubmit) {
|
||||||
return area
|
return area
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createRoomDisplay(room) {
|
export function createRoomDisplay(room, loadMessageCallback) {
|
||||||
|
let buttonEl = button({
|
||||||
|
class: 'loadMessages input',
|
||||||
|
style: 'flex-grow: 0',
|
||||||
|
onclick: async () => {
|
||||||
|
if (!await loadMessageCallback(room)) {
|
||||||
|
buttonEl.remove()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
parse('Load Previous')
|
||||||
|
)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
div({class: 'roomDisplay'},
|
div({class: 'roomDisplay'},
|
||||||
div({class: 'roomDisplayCenter'},
|
div({class: 'roomDisplayCenter'},
|
||||||
|
buttonEl,
|
||||||
div({class: 'messages'}),
|
div({class: 'messages'}),
|
||||||
createMultiLineInput(
|
createMultiLineInput(
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue