Compare commits

..

4 commits

5 changed files with 23 additions and 7 deletions

View file

@ -28,6 +28,7 @@
.message-content { .message-content {
color: var(--foreground-color-2); color: var(--foreground-color-2);
white-space: pre-wrap;
} }
.pending { .pending {

View file

@ -44,10 +44,14 @@
}; };
const onKeydown = async (e) => { const onKeydown = async (e) => {
if (e.code !== "Enter") if (e.code === "Enter") {
if (e.shiftKey) {
return; return;
} else {
e.preventDefault();
await sendMessage(); await sendMessage();
}
}
}; };
</script> </script>
@ -82,13 +86,13 @@
</style> </style>
<div class="message-input-container"> <div class="message-input-container">
<input <textarea
placeholder={`Send something interesting to #${channel.name}`} placeholder={`Send something interesting to #${channel.name}`}
type="text" type="text"
class="message-input" class="message-input"
on:keydown={ onKeydown } on:keydown={ onKeydown }
bind:value={ messageInput } bind:value={ messageInput }
> />
{#if $smallViewport} {#if $smallViewport}
<button class="icon-button send-button" on:click="{ sendMessage }"> <button class="icon-button send-button" on:click="{ sendMessage }">
<SendIcon /> <SendIcon />

View file

@ -224,6 +224,9 @@ class MessageStore extends Store {
} }
async loadOlderMessages(beforeCommitToStore=null) { async loadOlderMessages(beforeCommitToStore=null) {
if (this.channelId === -1)
return;
const oldestMessage = this.value[0]; const oldestMessage = this.value[0];
const endpoint = oldestMessage ? `channels/${this.channelId}/messages/?before=${oldestMessage.id}` : `channels/${this.channelId}/messages`; const endpoint = oldestMessage ? `channels/${this.channelId}/messages/?before=${oldestMessage.id}` : `channels/${this.channelId}/messages`;
const res = await request("GET", apiRoute(endpoint), true, null); const res = await request("GET", apiRoute(endpoint), true, null);
@ -298,11 +301,14 @@ class OverlayStore extends Store {
toast: null, toast: null,
login: null, login: null,
createAccount: null, createAccount: null,
settings: null editMessage: null,
settings: null,
}, "OverlayStore"); }, "OverlayStore");
} }
open(name, props={}) { open(name, props={}) {
if (this.value[name] === undefined)
throw new Error(`OverlayStore.open: tried to open unknown overlay with name '${name}' (undefined in overlay map)`);
this.value[name] = props; this.value[name] = props;
this.updated(); this.updated();
} }

View file

@ -17,4 +17,5 @@ export const gatewayErrors = {
ALREADY_AUTHENTICATED: { code: 4006, message: "Already authenticated" }, ALREADY_AUTHENTICATED: { code: 4006, message: "Already authenticated" },
PAYLOAD_TOO_LARGE: { code: 4007, message: "Payload too large" }, PAYLOAD_TOO_LARGE: { code: 4007, message: "Payload too large" },
TOO_MANY_SESSIONS: { code: 4008, message: "Too many sessions" }, TOO_MANY_SESSIONS: { code: 4008, message: "Too many sessions" },
NOT_AUTHENTICATED: { code: 4009, message: "Not authenticated" },
}; };

View file

@ -245,6 +245,10 @@ export default function(server: Server) {
return closeWithBadPayload(ws, "d: expected numeric '0'"); return closeWithBadPayload(ws, "d: expected numeric '0'");
} }
if (!ws.state.ready) {
return closeWithError(ws, gatewayErrors.NOT_AUTHENTICATED);
}
// TODO: also check session here // TODO: also check session here
ws.state.alive = true; ws.state.alive = true;
break; break;