98 Commits

Author SHA1 Message Date
Juan Cruz Orioli
c547a32282 components: Use onInput instead of onChange
This is one of the differences between React and Preact:
https://preactjs.com/guide/v10/differences-to-react/#use-oninput-instead-of-onchange

Closes: https://todo.sr.ht/~emersion/gamja/128
2023-01-10 18:14:53 +01:00
delthas
081f5743be Fix stripping hex color formatting
Hex colors can be set with the same formats as the regular colors:
<CODE>, <CODE><COLOR>, or <CODE><COLOR>,<COLOR>.

Previously we only supporteed <CODE><COLOR>.

This patch enables stripping colors for all valid color formats.

Co-authored-by: Simon Ser <contact@emersion.fr>
2022-12-02 16:03:14 +01:00
Simon Ser
3f059567c5 Skip regular chat message handling for infinite scroll
Infinite scroll is special: it shouldn't trigger notifications.
Additionally we need to avoid sending on MARKREAD command per
message in the chathistory batch.

Split chat message handling into separate functions.
2022-11-30 12:23:12 +01:00
Simon Ser
4b306305bf Move msg.tags fallback to client 2022-11-30 11:30:46 +01:00
Simon Ser
a172c810e9 Make first server check more robust when disconnecting
A disconnect/reconnect cycle will bump the server ID.
2022-11-30 11:21:54 +01:00
Simon Ser
ab3569e104 Close settings dialog when disconnecting 2022-11-30 11:18:23 +01:00
Simon Ser
dc5e64aaac lib/client: unify checks for chathistory end 2022-11-30 10:17:50 +01:00
Simon Ser
2d27168529 Use ratified extended-monitor cap name
References: https://github.com/ircv3/ircv3-specifications/pull/508
2022-11-06 20:40:00 +01:00
Simon Ser
24ba3f5189 Remove unnecessary whoChannelBuffer() call
switchBuffer() will do that already, no need to do it manually here.
We risk sending two duplicate WHO commands.
2022-10-23 20:21:27 +02:00
Simon Ser
90a2c91651 Load initial members state via WHO when channel is selected
Closes: https://todo.sr.ht/~emersion/gamja/13
2022-10-23 20:18:33 +02:00
Simon Ser
e815295503 Add support for OAuth 2.0 authentication 2022-10-14 10:52:44 +02:00
Simon Ser
bbc94c88c0 Upgrade dependencies 2022-09-18 20:08:13 +02:00
Simon Ser
84ca0a4408 components/connect-form: autofocus username field 2022-09-12 13:43:58 +02:00
Simon Ser
84b68308b9 components/app: switch off loading state atomically
Set connectParams together with loading, to avoid intermediate
state where loading = false but connectParams isn't set yet.
2022-09-12 13:42:44 +02:00
Simon Ser
4964782c30 Display error in loading state 2022-09-12 13:41:23 +02:00
Simon Ser
54e1fc93d9 Add config option to generate random nickname
Closes: https://todo.sr.ht/~emersion/gamja/136
2022-09-12 13:04:59 +02:00
Simon Ser
34d3bd6df9 Remove unnecessary if in App.handleConfig
config.json is merged with baseConfig. The latter is guaranteed
to contain a "server" field.
2022-09-12 09:54:38 +02:00
Simon Ser
a13f74d466 Disallow server.{autoconnect,auth} mismatch in config.json
This combination doesn't make sense.
2022-09-12 09:48:49 +02:00
Simon Ser
a603b79e33 components/buffer-list: show buffers with errors in red 2022-09-05 14:00:52 +02:00
Nolan Prescott
096fcbf829 Sort lists with localeCompare
The difference in case sensitivity is the most obvious change with
servers like soju that support CASEMAPPING ascii and
rfc1459. Currently the list:
  'Alpha', 'aardvark', 'Charlie', 'comma'
currently sorts to:
  'Alpha', 'Charlie', 'aardvark', 'comma'
with this change it will instead become:
  'aardvark', 'Alpha', 'Charlie', 'comma'

If something like RFC 7613 gets broader support then there are a few
more differences for a list like:
  'éclair', 'ecstatic, 'aardvark', 'zed', 'Gamma'
currently sorts to:
  'Gamma', 'aardvark', 'ecstatic', 'zed', 'éclair'
with this patch would instead sort to:
  'aardvark', 'éclair', 'ecstatic', 'Gamma', 'zed'

The above examples were run with a locale unspecified which fell back
to my browser/host default of 'en'.
2022-09-05 09:03:42 +02:00
Simon Ser
a2d2a11d44 Drop support for soju.im/read
It's been superseded by draft/read-marker.
2022-09-03 14:41:53 +02:00
Simon Ser
e6618c8a1f Fix draft/read-marker cap not negotiated
Fixes: 1428ec4d49 ("Add support for draft/read-marker")
2022-09-03 14:40:54 +02:00
Simon Ser
aa9aa78d71 Fix ignored MARKREAD messages
The prefix is a remnant of the soju extension. The IRCv3 one
doesn't have it.

Fixes: 1428ec4d49 ("Add support for draft/read-marker")
2022-09-03 14:40:46 +02:00
Simon Ser
4780b9c709 Fetch read marker before backlog for user targets 2022-09-03 14:31:56 +02:00
Simon Ser
e7b69cec9a Limit composer length
Often times IRC servers will truncate messages which are too big.
2022-08-28 19:16:41 +02:00
xse
cfbd91d257 Make use of destBuffers when fetching history.
Fixes an issue where messages intended to go on the server's buffer end up on their own
2022-08-22 12:46:03 +02:00
Simon Ser
7138e43710 Ignore RPL_CHANNEL_URL 2022-08-22 10:35:50 +02:00
Simon Ser
89647472ae components/app: don't open buffer for CTCP messages
These are usually completely uninteresting messages, e.g. CTCP
VERSION or whatever.
2022-08-22 10:30:56 +02:00
Simon Ser
e2dc32c0d3 Update dependencies 2022-07-11 21:02:12 +02:00
Simon Ser
1bcd9d3607 ci: deploy to new server 2022-07-09 12:26:39 +02:00
Simon Ser
e4ebf5eb80 ci: fix deploy host
emersion.fr is now an alias for the new server. gamja hasn't been
migrated yet.
2022-07-08 21:24:09 +02:00
Simon Ser
1428ec4d49 Add support for draft/read-marker
References: https://github.com/ircv3/ircv3-specifications/pull/489
2022-07-01 13:35:27 +02:00
Arik
839e46360e Use monospace on <input> too
It looks like having "font-family: monospace" on <body> doesn't set it
for <input> too.
2022-07-01 13:34:22 +02:00
Simon Ser
d0064dd647 components/buffer: show disclaimer for +draft/channel-context messages 2022-06-28 15:55:35 +02:00
delthas
b9693d53ec Support @+draft/channel-context
See: https://github.com/ircv3/ircv3-specifications/pull/498
2022-06-28 15:33:38 +02:00
Simon Ser
f6ba40046f components/buffer-header: fix duplicate settings button 2022-06-28 15:11:48 +02:00
Simon Ser
54453c5f44 Fix invalid relative import
Worked locally because it's served at the root…
2022-06-27 17:16:33 +02:00
Simon Ser
fa80a56516 Add button to enable protocol handler in settings 2022-06-27 17:01:15 +02:00
Simon Ser
7cabb6f85b Add a setting for seconds in timestamps 2022-06-27 16:34:41 +02:00
Simon Ser
505a6fd5ab Workaround the sad state of base64 web APIs
This is necessary to make usernames/passwords with UTF-8 in them
work correctly.
2022-06-24 23:59:18 +02:00
Simon Ser
8e30806fec Upgrade dependencies 2022-06-14 19:58:50 +02:00
Simon Ser
f0c398a10c components/buffer-header: print bouncer network error if any 2022-06-09 15:54:29 +02:00
Simon Ser
baaf576d82 Add a settings dialog
Add an option to hide chat events or always expand them.

Closes: https://todo.sr.ht/~emersion/gamja/73
2022-06-08 16:57:16 +02:00
Simon Ser
e3c2d85a94 Fix ping config lost in ConnectForm
Reported-by: xse <xse@riseup.net>
References: https://lists.sr.ht/~emersion/public-inbox/patches/32126
2022-06-08 15:14:06 +02:00
Umar Getagazov
576b9d51eb components/app: switch to server buffer on close only if active
If the buffer that's being closed is not the active one, there's no
point in switching the user away to another buffer.
2022-06-08 15:05:26 +02:00
Simon Ser
6b04cb1417 Add support for bot mode
References: https://ircv3.net/specs/extensions/bot-mode
2022-06-08 15:04:27 +02:00
Simon Ser
8507500d74 components/scroll-manager: don't crash when Buffer is empty 2022-04-22 12:32:54 +02:00
Simon Ser
aaef4e1629 store: use lower-case for buffer keys 2022-04-22 12:04:11 +02:00
Simon Ser
cdd2da90a9 Update webpage title when switching buffer 2022-04-22 11:49:23 +02:00
Simon Ser
4a981997f0 Handle CHATHISTORY messages when reaching end of batch
Closes: https://todo.sr.ht/~emersion/gamja/115
2022-04-22 11:25:41 +02:00
Simon Ser
f45b51d981 commands: fix TypeError in kickban
The ban variable was undefined.
2022-04-14 10:53:35 +02:00
Simon Ser
73db1a888e Upgrade dependencies 2022-02-26 10:47:55 +01:00
Simon Ser
3dc98ec797 Convert remaining simple quotes to double quotes 2022-02-26 09:54:31 +01:00
Simon Ser
e37d5f363b lib/irc: fix bound check in isHighlight
Doesn't seem like this was causing any issues, but let's fix the
logic regardless.
2022-02-25 11:38:00 +01:00
Simon Ser
221b1b6356 lib/irc: remove unnecessary non-breaking-space case
Handled by the default case already.
2022-02-25 11:37:18 +01:00
Simon Ser
86b1030b7a lib/irc: add missing num range to alphaNum regexp 2022-02-25 11:36:43 +01:00
Simon Ser
08578c9a21 components/app: fix missing semicolons 2022-02-21 15:26:12 +01:00
Simon Ser
26cc073f41 store: save buffer state when user navigates away
Avoids loosing some state on page unload.
2022-02-18 18:22:00 +01:00
Simon Ser
9e703698ca lib/irc: drop outdated CapRegistry TODO 2022-02-16 15:46:22 +01:00
Simon Ser
37d7f4a1c5 Refactor backlog fetching into function 2022-02-13 15:34:11 +01:00
Simon Ser
962c05c066 Prevent hole in history when reconnecting 2022-02-13 15:26:04 +01:00
Simon Ser
f2c9fd1d7f Update stored unread status on READ message 2022-02-12 10:24:56 +01:00
Simon Ser
a3eec9a351 store: add note about comparison in Buffer.put 2022-02-12 10:24:34 +01:00
Simon Ser
2ac7be6218 state: add isReceiptBefore 2022-02-12 10:21:11 +01:00
Simon Ser
5f8cd976e6 keybindings: fix error on alt+h
Fixes the following JS error:

    TypeError: e.setReceipt is not a function
2022-02-12 10:05:58 +01:00
Simon Ser
fbc42b6dab components/app: move lastErrorID declaration down
Move it right before App, rather than drown in-between unrelated
functions.
2022-02-11 21:17:35 +01:00
Simon Ser
dc398baa3b components/app: stop updating prevReadReceipt on READ message
prevReadReceipt is used for the unread marker. Let's not update it
before the user switches the current buffer.
2022-02-11 21:09:11 +01:00
Simon Ser
6a9a8e88f1 store: fix no-op read receipt update detection
If the old and new times are equal, the update is a no-op.
2022-02-11 21:07:49 +01:00
Simon Ser
f47d93af8a Don't fetch backlog before read receipt 2022-02-11 21:02:34 +01:00
Simon Ser
fce0936c20 components/app: introduce getReceipt 2022-02-11 20:59:31 +01:00
Simon Ser
0636544c40 components/app: close notifications when receiving READ message 2022-02-11 19:32:30 +01:00
Simon Ser
7c6f334dbf components/app: close notifications when switching buffer 2022-02-11 19:32:30 +01:00
Simon Ser
7ddd783150 components/app: make showNotification return null on error
We'll do more involved stuff with notifications soon, and don't
want to deal with buggy notification objects.
2022-02-11 19:32:30 +01:00
Simon Ser
bb42ff6a07 components/app: include server ID in notification tags 2022-02-11 19:32:30 +01:00
Simon Ser
db0ef39c6b Add support for soju.im/read 2022-02-11 19:32:26 +01:00
Simon Ser
77f54080e7 Make delivery receipts follow read receipts
If a message has been read, it's been delivered.

Fixes #23 at least partially.

References: https://todo.sr.ht/~emersion/gamja/23
2022-02-11 19:29:55 +01:00
Simon Ser
065b3f21fc Refactor receipts
They are now saved in the buffer store to allow for proper server
separation.
2022-02-11 19:29:55 +01:00
Simon Ser
d2bcea8c86 Introduce isMessageBeforeReceipt 2022-02-11 16:37:58 +01:00
Simon Ser
3d81466788 components/app: introduce receiptFromMessage 2022-02-11 16:30:46 +01:00
Simon Ser
f2923452c1 store: debounce buffer store saves 2022-02-11 16:24:32 +01:00
Simon Ser
39c36e7a7b Fix unread marker going back
Receipts must never go back in time.

Fixes: c428e504fe ("Don't show unread marker for outgoing messages")
2022-02-11 16:06:06 +01:00
Simon Ser
e91b044134 components/app: make switchBuffer state changes atomic
Instead of calling App.setBufferState inside the App.setState
callback invoked when the update is done, call State.updateBuffer.
2022-02-11 15:48:56 +01:00
delthas
4cb3abfa72 components/connect-form: make the server password field password-typed 2022-02-11 12:58:26 +01:00
Simon Ser
0063a5a372 Set min node version in package.json
v14.13.0 is required for CommonJS named imports to work properly.
2022-02-10 14:46:42 +01:00
Дамјан Георгиевски
1142145c6d fix ping after reconnect
client.setPingInterval was only called once in app.connect(),
but client.disconnect() disables it, and the ping timer is never again set,
even though the client can reconnect.

the change passes the ping time as a parameter to the client, and the
client calls setPingInterval() after a successful WS open event.
2022-02-04 15:54:23 +01:00
Simon Ser
f465e24adf components/buffer-header: fix dead space above description 2022-02-04 14:38:28 +01:00
Simon Ser
7f7a7c1aac components/buffer-list: remove pointless temporary variable 2022-02-04 14:32:29 +01:00
Simon Ser
e1bbe34ff2 state: add bouncerNetworks helpers 2022-02-04 14:22:50 +01:00
delthas
fab42ba2ee commands: add password param to /join 2022-02-02 20:45:18 +01:00
Simon Ser
9f93e200ed commands: add comment param to /kick usage 2022-01-31 18:30:48 +01:00
Simon Ser
bd48f36ade lib/irc: add missing Isupport.chanModes
It was called by forEachChannelModeUpdate, but wasn't implemented.
2022-01-31 18:24:34 +01:00
xse
393fd93253 components/buffer: use browser locale for date-separator 2022-01-14 23:26:05 +01:00
Simon Ser
a0f8f1f52f components/buffer: fix INVITE link
It was throwing a TypeError.
2022-01-10 10:32:37 +01:00
Simon Ser
5d6de11a4c commands: simplify /who usage string
As per https://modern.ircdocs.horse/#who-message
2022-01-09 19:30:01 +01:00
Simon Ser
6692ed0035 components/help: use bold for command name only 2022-01-09 19:28:23 +01:00
Simon Ser
5e34067d38 components/help: remove "/" keybinding, document middle mouse click 2022-01-09 19:20:44 +01:00
Isaac Freund
690845c2af Better handle long topics on small screen sizes
Currently long topics will cause the buffer header to take up an
arbitrarily large percentage of the screen on mobile. Additionaly, long
words like URLS are not broken and may cause the buffer header to extend
outside of the viewport in the x direction, rendering the buffer content
unreadable.

This patch fixes these two issues by limiting the buffer header size to
20% of the viewport and breaking long words such as URLs if they would
overflow.

Fixes: https://todo.sr.ht/~emersion/gamja/129
2022-01-07 16:02:33 +01:00
Noelle Leigh
0b59cf92b9 Display persistant command input on server buffer
This commit changes the composer to not be read-only on the server
buffer, which tells the user that they can send commands from that view.

On the server buffer, the placeholder is changed to
"Type a command (see /help)", which indicates to the user that this buffer
only accepts commands, and gives them a hint for how to learn what
commands are available.

Implements: https://todo.sr.ht/~emersion/gamja/38
2021-12-21 10:44:24 +01:00
29 changed files with 3142 additions and 12071 deletions

View File

@@ -5,7 +5,7 @@ packages:
sources:
- https://git.sr.ht/~emersion/gamja
secrets:
- 5874ac5a-905e-4596-a117-fed1401c60ce # deploy SSH key
- 77c7956b-003e-44f7-bb5c-2944b2047654 # deploy SSH key
tasks:
- setup: |
cd gamja
@@ -16,4 +16,4 @@ tasks:
[ "$(git rev-parse HEAD)" = "$(git rev-parse origin/master)" ] || complete-build
rsync --rsh="ssh -o StrictHostKeyChecking=no" -rP \
--delete --exclude=config.json \
. deploy@emersion.fr:/srv/http/gamja
. deploy@sheeta.emersion.fr:/srv/http/gamja

View File

@@ -103,10 +103,12 @@ gamja default settings can be set using a `config.json` file at the root:
"autojoin": "#gamja",
// Controls how the password UI is presented to the user. Set to
// "mandatory" to require a password, "optional" to accept one but not
// require it, "disabled" to never ask for a password, or "external" to
// use SASL EXTERNAL. Defaults to "optional".
// require it, "disabled" to never ask for a password, "external" to
// use SASL EXTERNAL, "oauth2" to use SASL OAUTHBEARER. Defaults to
// "optional".
"auth": "optional",
// Default nickname (string).
// Default nickname (string). If it contains a "*" character, it will
// be replaced with a random string.
"nick": "asdf",
// Don't display the login UI, immediately connect to the server
// (boolean).
@@ -115,6 +117,19 @@ gamja default settings can be set using a `config.json` file at the root:
// disable. Enabling PINGs can have an impact on client power usage and
// should only be enabled if necessary.
"ping": 60
},
// OAuth 2.0 settings.
"oauth2": {
// OAuth 2.0 server URL (string). The server must support OAuth 2.0
// Authorization Server Metadata (RFC 8414) or OpenID Connect
// Discovery.
"url": "https://auth.example.org",
// OAuth 2.0 client ID (string).
"client_id": "asdf",
// OAuth 2.0 client secret (string).
"client_secret": "ghjk",
// OAuth 2.0 scope (string).
"scope": "profile"
}
}
```

View File

@@ -54,19 +54,23 @@ function markServerBufferUnread(app) {
}
const join = {
usage: "<name>",
usage: "<name> [password]",
description: "Join a channel",
execute: (app, args) => {
let channel = args[0];
if (!channel) {
throw new Error("Missing channel name");
}
app.open(channel);
if (args.length > 1) {
app.open(channel, null, args[1]);
} else {
app.open(channel);
}
},
};
const kick = {
usage: "<nick>",
usage: "<nick> [comment]",
description: "Remove a user from the channel",
execute: (app, args) => {
let nick = args[0];
@@ -79,6 +83,22 @@ const kick = {
},
};
const ban = {
usage: "[nick]",
description: "Ban a user from the channel, or display the current ban list",
execute: (app, args) => {
if (args.length == 0) {
let activeChannel = getActiveChannel(app);
getActiveClient(app).send({
command: "MODE",
params: [activeChannel, "+b"],
});
} else {
return setUserHostMode(app, args, "+b");
}
},
};
function givemode(app, args, mode) {
// TODO: Handle several users at once
let nick = args[0];
@@ -104,21 +124,7 @@ export default {
getActiveClient(app).send({command: "AWAY", params});
},
},
"ban": {
usage: "[nick]",
description: "Ban a user from the channel, or display the current ban list",
execute: (app, args) => {
if (args.length == 0) {
let activeChannel = getActiveChannel(app);
getActiveClient(app).send({
command: "MODE",
params: [activeChannel, "+b"],
});
} else {
return setUserHostMode(app, args, "+b");
}
},
},
"ban": ban,
"buffer": {
usage: "<name>",
description: "Switch to a buffer",
@@ -393,7 +399,7 @@ export default {
execute: (app, args) => givemode(app, args, "+v"),
},
"who": {
usage: "[<mask> [o]]",
usage: "<mask>",
description: "Retrieve a list of users",
execute: (app, args) => {
getActiveClient(app).send({ command: "WHO", params: args });

File diff suppressed because it is too large Load Diff

View File

@@ -9,7 +9,7 @@ export default class NetworkForm extends Component {
constructor(props) {
super(props);
this.handleChange = this.handleChange.bind(this);
this.handleInput = this.handleInput.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
if (props.username) {
@@ -17,7 +17,7 @@ export default class NetworkForm extends Component {
}
}
handleChange(event) {
handleInput(event) {
let target = event.target;
let value = target.type == "checkbox" ? target.checked : target.value;
this.setState({ [target.name]: value });
@@ -31,7 +31,7 @@ export default class NetworkForm extends Component {
render() {
return html`
<form onChange=${this.handleChange} onSubmit=${this.handleSubmit}>
<form onInput=${this.handleInput} onSubmit=${this.handleSubmit}>
<label>
Username:<br/>
<input type="username" name="username" value=${this.state.username} required/>

View File

@@ -44,6 +44,9 @@ export default function BufferHeader(props) {
switch (props.bouncerNetwork.state) {
case "disconnected":
description = "Bouncer disconnected from network";
if (props.bouncerNetwork.error) {
description += ": " + props.bouncerNetwork.error;
}
break;
case "connecting":
description = "Bouncer connecting to network...";
@@ -74,6 +77,12 @@ export default function BufferHeader(props) {
onClick=${props.onReconnect}
>Reconnect</button>
`;
let settingsButton = html`
<button
key="settings"
onClick="${props.onOpenSettings}"
>Settings</button>
`;
if (props.server.isBouncer) {
if (props.server.bouncerNetID) {
@@ -99,13 +108,7 @@ export default function BufferHeader(props) {
} else if (props.server.status === ServerStatus.DISCONNECTED) {
actions.push(reconnectButton);
}
actions.push(html`
<button
key="disconnect"
class="danger"
onClick=${props.onClose}
>Disconnect</button>
`);
actions.push(settingsButton);
}
} else {
if (fullyConnected) {
@@ -113,13 +116,7 @@ export default function BufferHeader(props) {
} else if (props.server.status === ServerStatus.DISCONNECTED) {
actions.push(reconnectButton);
}
actions.push(html`
<button
key="disconnect"
class="danger"
onClick=${props.onClose}
>Disconnect</button>
`);
actions.push(settingsButton);
}
break;
case BufferType.CHANNEL:
@@ -189,6 +186,10 @@ export default function BufferHeader(props) {
let desc = "This user is a server operator, they have administrator privileges.";
details.push(html`<abbr title=${desc}>server operator</abbr>`);
}
if (props.user.bot) {
let desc = "This user is an automated bot.";
details.push(html`<abbr title=${desc}>bot</abbr>`);
}
details = details.map((item, i) => {
if (i === 0) {
return item;

View File

@@ -1,6 +1,6 @@
import * as irc from "../lib/irc.js";
import { html, Component } from "../lib/index.js";
import { BufferType, Unread, getBufferURL, getServerName } from "../state.js";
import { BufferType, Unread, ServerStatus, getBufferURL, getServerName } from "../state.js";
function BufferItem(props) {
function handleClick(event) {
@@ -26,6 +26,15 @@ function BufferItem(props) {
if (props.buffer.unread != Unread.NONE) {
classes.push("unread-" + props.buffer.unread);
}
if (props.buffer.type === BufferType.SERVER) {
let isError = props.server.status === ServerStatus.DISCONNECTED;
if (props.bouncerNetwork && props.bouncerNetwork.error) {
isError = true;
}
if (isError) {
classes.push("error");
}
}
return html`
<li class="${classes.join(" ")}">
@@ -44,9 +53,8 @@ export default function BufferList(props) {
let server = props.servers.get(buf.server);
let bouncerNetwork = null;
let bouncerNetID = server.bouncerNetID;
if (bouncerNetID) {
bouncerNetwork = props.bouncerNetworks.get(bouncerNetID);
if (server.bouncerNetID) {
bouncerNetwork = props.bouncerNetworks.get(server.bouncerNetID);
}
return html`

View File

@@ -2,7 +2,7 @@ import { html, Component } from "../lib/index.js";
import linkify from "../lib/linkify.js";
import * as irc from "../lib/irc.js";
import { strip as stripANSI } from "../lib/ansi.js";
import { BufferType, ServerStatus, getNickURL, getChannelURL, getMessageURL } from "../state.js";
import { BufferType, ServerStatus, BufferEventsDisplayMode, getNickURL, getChannelURL, getMessageURL, isMessageBeforeReceipt, SettingsContext } from "../state.js";
import * as store from "../store.js";
import Membership from "./membership.js";
@@ -27,15 +27,22 @@ function Nick(props) {
`;
}
function Timestamp({ date, url }) {
function _Timestamp({ date, url, showSeconds }) {
if (!date) {
return html`<spam class="timestamp">--:--:--</span>`;
let timestamp = "--:--";
if (showSeconds) {
timestamp += ":--";
}
return html`<spam class="timestamp">${timestamp}</span>`;
}
let hh = date.getHours().toString().padStart(2, "0");
let mm = date.getMinutes().toString().padStart(2, "0");
let ss = date.getSeconds().toString().padStart(2, "0");
let timestamp = `${hh}:${mm}:${ss}`;
let timestamp = `${hh}:${mm}`;
if (showSeconds) {
let ss = date.getSeconds().toString().padStart(2, "0");
timestamp += ":" + ss;
}
return html`
<a
href=${url}
@@ -48,6 +55,16 @@ function Timestamp({ date, url }) {
`;
}
function Timestamp(props) {
return html`
<${SettingsContext.Consumer}>
${(settings) => html`
<${_Timestamp} ...${props} showSeconds=${settings.secondsInTimestamps}/>
`}
</>
`;
}
/**
* Check whether a message can be folded.
*
@@ -85,12 +102,8 @@ class LogLine extends Component {
`;
}
function createChannel(channel) {
function onClick(event) {
event.preventDefault();
onChannelClick(channel);
}
return html`
<a href=${getChannelURL(channel)} onClick=${onClick}>
<a href=${getChannelURL(channel)} onClick=${onChannelClick}>
${channel}
</a>
`;
@@ -133,6 +146,10 @@ class LogLine extends Component {
}
}
if (msg.tags["+draft/channel-context"]) {
content = html`<em>(only visible to you)</em> ${content}`;
}
if (msg.isHighlight) {
lineClass += " highlight";
}
@@ -531,10 +548,7 @@ class DateSeparator extends Component {
render() {
let date = this.props.date;
let YYYY = date.getFullYear().toString().padStart(4, "0");
let MM = (date.getMonth() + 1).toString().padStart(2, "0");
let DD = date.getDate().toString().padStart(2, "0");
let text = `${YYYY}-${MM}-${DD}`;
let text = date.toLocaleDateString([], { year: "numeric", month: "2-digit", day: "2-digit" });
return html`
<div class="separator date-separator">
${text}
@@ -553,7 +567,8 @@ function sameDate(d1, d2) {
export default class Buffer extends Component {
shouldComponentUpdate(nextProps) {
return this.props.buffer !== nextProps.buffer;
return this.props.buffer !== nextProps.buffer ||
this.props.settings !== nextProps.settings;
}
render() {
@@ -564,6 +579,7 @@ export default class Buffer extends Component {
let server = this.props.server;
let bouncerNetwork = this.props.bouncerNetwork;
let settings = this.props.settings;
let serverName = server.name;
let children = [];
@@ -640,7 +656,11 @@ export default class Buffer extends Component {
buf.messages.forEach((msg) => {
let sep = [];
if (!hasUnreadSeparator && buf.type != BufferType.SERVER && buf.prevReadReceipt && msg.tags.time > buf.prevReadReceipt.time) {
if (settings.bufferEvents === BufferEventsDisplayMode.HIDE && canFoldMessage(msg)) {
return;
}
if (!hasUnreadSeparator && buf.type != BufferType.SERVER && !isMessageBeforeReceipt(msg, buf.prevReadReceipt)) {
sep.push(html`<${UnreadSeparator} key="unread"/>`);
hasUnreadSeparator = true;
}
@@ -658,7 +678,7 @@ export default class Buffer extends Component {
}
// TODO: consider checking the time difference too
if (canFoldMessage(msg)) {
if (settings.bufferEvents === BufferEventsDisplayMode.FOLD && canFoldMessage(msg)) {
foldMessages.push(msg);
return;
}

View File

@@ -143,7 +143,7 @@ export default class Composer extends Component {
return;
}
if (this.props.readOnly && event.key !== "/") {
if (this.props.readOnly || (this.props.commandOnly && event.key !== "/")) {
return;
}
@@ -167,7 +167,7 @@ export default class Composer extends Component {
return;
}
let text = event.clipboardData.getData('text');
let text = event.clipboardData.getData("text");
event.preventDefault();
event.stopImmediatePropagation();
@@ -201,6 +201,11 @@ export default class Composer extends Component {
className = "read-only";
}
let placeholder = "Type a message";
if (this.props.commandOnly) {
placeholder = "Type a command (see /help)";
}
return html`
<form
id="composer"
@@ -214,9 +219,10 @@ export default class Composer extends Component {
ref=${this.textInput}
value=${this.state.text}
autocomplete="off"
placeholder="Type a message"
placeholder=${placeholder}
enterkeyhint="send"
onKeyDown=${this.handleInputKeyDown}
maxlength=${this.props.maxLen}
/>
</form>
`;

View File

@@ -17,7 +17,7 @@ export default class ConnectForm extends Component {
constructor(props) {
super(props);
this.handleChange = this.handleChange.bind(this);
this.handleInput = this.handleInput.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
if (props.params) {
@@ -32,7 +32,7 @@ export default class ConnectForm extends Component {
}
}
handleChange(event) {
handleInput(event) {
let target = event.target;
let value = target.type == "checkbox" ? target.checked : target.value;
this.setState({ [target.name]: value });
@@ -63,6 +63,8 @@ export default class ConnectForm extends Component {
};
} else if (this.props.auth === "external") {
params.saslExternal = true;
} else if (this.props.auth === "oauth2") {
params.saslOauthBearer = this.props.params.saslOauthBearer;
}
if (this.state.autojoin) {
@@ -110,7 +112,7 @@ export default class ConnectForm extends Component {
}
let auth = null;
if (this.props.auth !== "disabled" && this.props.auth !== "external") {
if (this.props.auth !== "disabled" && this.props.auth !== "external" && this.props.auth !== "oauth2") {
auth = html`
<label>
Password:<br/>
@@ -138,14 +140,14 @@ export default class ConnectForm extends Component {
name="autojoin"
checked=${this.state.autojoin}
/>
Auto-join channel${s} <strong>${channels.join(', ')}</strong>
Auto-join channel${s} <strong>${channels.join(", ")}</strong>
</label>
<br/><br/>
`;
}
return html`
<form onChange=${this.handleChange} onSubmit=${this.handleSubmit}>
<form onInput=${this.handleInput} onSubmit=${this.handleSubmit}>
<h2>Connect to IRC</h2>
<label>
@@ -157,6 +159,7 @@ export default class ConnectForm extends Component {
disabled=${disabled}
ref=${this.nickInput}
required
autofocus
/>
</label>
<br/><br/>
@@ -210,7 +213,7 @@ export default class ConnectForm extends Component {
<label>
Server password:<br/>
<input
type="text"
type="password"
name="pass"
value=${this.state.pass}
disabled=${disabled}

View File

@@ -26,27 +26,27 @@ function KeyBindingsHelp() {
`;
});
return html`
<dl>
<dt><kbd>/</kbd></dt>
<dd>Start writing a command</dd>
if (!window.matchMedia("(pointer: none)").matches) {
l.push(html`
<dt><strong>Middle mouse click</strong></dt>
<dd>Close buffer</dd>
`);
}
${l}
</dl>
`;
return html`<dl>${l}</dl>`;
}
function CommandsHelp() {
let l = Object.keys(commands).map((name) => {
let cmd = commands[name];
let usage = "/" + name;
let usage = [html`<strong>/${name}</strong>`];
if (cmd.usage) {
usage += " " + cmd.usage;
usage.push(" " + cmd.usage);
}
return html`
<dt><strong><code>${usage}</code></strong></dt>
<dt><code>${usage}</code></dt>
<dd>${cmd.description}</dd>
`;
});

View File

@@ -8,7 +8,7 @@ export default class JoinForm extends Component {
constructor(props) {
super(props);
this.handleChange = this.handleChange.bind(this);
this.handleInput = this.handleInput.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
if (props.channel) {
@@ -16,7 +16,7 @@ export default class JoinForm extends Component {
}
}
handleChange(event) {
handleInput(event) {
let target = event.target;
let value = target.type == "checkbox" ? target.checked : target.value;
this.setState({ [target.name]: value });
@@ -34,7 +34,7 @@ export default class JoinForm extends Component {
render() {
return html`
<form onChange=${this.handleChange} onSubmit=${this.handleSubmit}>
<form onInput=${this.handleInput} onSubmit=${this.handleSubmit}>
<label>
Channel:<br/>
<input type="text" name="channel" value=${this.state.channel} autofocus required/>

View File

@@ -101,7 +101,7 @@ function sortMembers(a, b) {
return i - j;
}
return nickA < nickB ? -1 : 1;
return nickA.localeCompare(nickB);
}
export default class MemberList extends Component {

View File

@@ -22,7 +22,7 @@ export default class NetworkForm extends Component {
this.prevParams = { ...defaultParams };
this.handleChange = this.handleChange.bind(this);
this.handleInput = this.handleInput.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
if (props.params) {
@@ -35,7 +35,7 @@ export default class NetworkForm extends Component {
}
}
handleChange(event) {
handleInput(event) {
let target = event.target;
let value = target.type == "checkbox" ? target.checked : target.value;
this.setState({ [target.name]: value });
@@ -85,7 +85,7 @@ export default class NetworkForm extends Component {
}
return html`
<form onChange=${this.handleChange} onSubmit=${this.handleSubmit}>
<form onInput=${this.handleInput} onSubmit=${this.handleSubmit}>
<label>
Hostname:<br/>
<input type="text" name="host" value=${this.state.host} autofocus required/>

View File

@@ -9,11 +9,11 @@ export default class RegisterForm extends Component {
constructor(props) {
super(props);
this.handleChange = this.handleChange.bind(this);
this.handleInput = this.handleInput.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}
handleChange(event) {
handleInput(event) {
let target = event.target;
let value = target.type == "checkbox" ? target.checked : target.value;
this.setState({ [target.name]: value });
@@ -27,7 +27,7 @@ export default class RegisterForm extends Component {
render() {
return html`
<form onChange=${this.handleChange} onSubmit=${this.handleSubmit}>
<form onInput=${this.handleInput} onSubmit=${this.handleSubmit}>
<label>
E-mail:<br/>
<input

View File

@@ -34,6 +34,9 @@ export default class ScrollManager extends Component {
restoreScrollPosition() {
let target = this.props.target.current;
if (!target.firstChild) {
return;
}
let stickToKey = store.get(this.props.scrollKey);
if (!stickToKey) {

112
components/settings-form.js Normal file
View File

@@ -0,0 +1,112 @@
import { html, Component } from "../lib/index.js";
export default class SettingsForm extends Component {
state = {};
constructor(props) {
super(props);
this.state.secondsInTimestamps = props.settings.secondsInTimestamps;
this.state.bufferEvents = props.settings.bufferEvents;
this.handleInput = this.handleInput.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}
handleInput(event) {
let target = event.target;
let value = target.type == "checkbox" ? target.checked : target.value;
this.setState({ [target.name]: value }, () => {
this.props.onChange(this.state);
});
}
handleSubmit(event) {
event.preventDefault();
this.props.onClose();
}
registerProtocol() {
let url = window.location.origin + window.location.pathname + "?open=%s";
try {
navigator.registerProtocolHandler("irc", url);
navigator.registerProtocolHandler("ircs", url);
} catch (err) {
console.error("Failed to register protocol handler: ", err);
}
}
render() {
let protocolHandler = null;
if (this.props.showProtocolHandler) {
protocolHandler = html`
<div class="protocol-handler">
<div class="left">
Set gamja as your default IRC client for this browser.
IRC links will be automatically opened here.
</div>
<div class="right">
<button type="button" onClick=${() => this.registerProtocol()}>
Enable
</button>
</div>
</div>
<br/><br/>
`;
}
return html`
<form onInput=${this.handleInput} onSubmit=${this.handleSubmit}>
<label>
<input
type="checkbox"
name="secondsInTimestamps"
checked=${this.state.secondsInTimestamps}
/>
Show seconds in time indicator
</label>
<br/><br/>
<label>
<input
type="radio"
name="bufferEvents"
value="fold"
checked=${this.state.bufferEvents === "fold"}
/>
Show and fold chat events
</label>
<br/>
<label>
<input
type="radio"
name="bufferEvents"
value="expand"
checked=${this.state.bufferEvents === "expand"}
/>
Show and expand chat events
</label>
<br/>
<label>
<input
type="radio"
name="bufferEvents"
value="hide"
checked=${this.state.bufferEvents === "hide"}
/>
Hide chat events
</label>
<br/><br/>
${protocolHandler}
<button type="button" class="danger" onClick=${() => this.props.onDisconnect()}>
Disconnect
</button>
<button>
Close
</button>
</form>
`;
}
}

View File

@@ -9,11 +9,11 @@ export default class RegisterForm extends Component {
constructor(props) {
super(props);
this.handleChange = this.handleChange.bind(this);
this.handleInput = this.handleInput.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}
handleChange(event) {
handleInput(event) {
let target = event.target;
let value = target.type == "checkbox" ? target.checked : target.value;
this.setState({ [target.name]: value });
@@ -27,7 +27,7 @@ export default class RegisterForm extends Component {
render() {
return html`
<form onChange=${this.handleChange} onSubmit=${this.handleSubmit}>
<form onInput=${this.handleInput} onSubmit=${this.handleSubmit}>
<p>Your account <strong>${this.props.account}</strong> has been created, but a verification code is required to complete the registration.</p>
<p>${linkify(this.props.message)}</p>

View File

@@ -1,4 +1,4 @@
import { ReceiptType, Unread, BufferType, SERVER_BUFFER } from "./state.js";
import { ReceiptType, Unread, BufferType, SERVER_BUFFER, receiptFromMessage } from "./state.js";
function getSiblingBuffer(buffers, bufID, delta) {
let bufList = Array.from(buffers.values());
@@ -19,22 +19,24 @@ export const keybindings = [
app.setState((state) => {
let buffers = new Map();
state.buffers.forEach((buf) => {
if (buf.messages.length > 0) {
let lastMsg = buf.messages[buf.messages.length - 1];
app.setReceipt(buf.name, ReceiptType.READ, lastMsg);
}
buffers.set(buf.id, {
...buf,
unread: Unread.NONE,
prevReadReceipt: null,
});
let receipts = {};
if (buf.messages.length > 0) {
let lastMsg = buf.messages[buf.messages.length - 1];
receipts[ReceiptType.READ] = receiptFromMessage(lastMsg);
}
let client = app.clients.get(buf.server);
app.bufferStore.put({
name: buf.name,
server: client.params,
unread: Unread.NONE,
receipts,
});
});
return { buffers };

View File

@@ -10,10 +10,26 @@ const COLOR_HEX = "\x04";
const REVERSE_COLOR = "\x16";
const RESET = "\x0F";
const HEX_COLOR_LENGTH = 6;
function isDigit(ch) {
return ch >= "0" && ch <= "9";
}
function isHexColor(text) {
if (text.length < HEX_COLOR_LENGTH) {
return false;
}
for (let i = 0; i < HEX_COLOR_LENGTH; i++) {
let ch = text[i].toUpperCase();
let ok = (ch >= "0" && ch <= "9") || (ch >= "A" && ch <= "F");
if (!ok) {
return false;
}
}
return true;
}
export function strip(text) {
let out = "";
for (let i = 0; i < text.length; i++) {
@@ -43,7 +59,13 @@ export function strip(text) {
}
break;
case COLOR_HEX:
i += 6;
if (!isHexColor(text.slice(i + 1))) {
break;
}
i += HEX_COLOR_LENGTH;
if (text[i + 1] == "," && isHexColor(text.slice(i + 2))) {
i += 1 + HEX_COLOR_LENGTH;
}
break;
default:
out += ch;

42
lib/base64.js Normal file
View File

@@ -0,0 +1,42 @@
const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
/* The JS world is still in the stone age. We're in 2022 and we still don't
* have the technology to correctly base64-encode a UTF-8 string. Can't wait
* the next industrial revolution.
*
* For more info, see:
* https://developer.mozilla.org/en-US/docs/Glossary/Base64#the_unicode_problem
*/
export function encode(data) {
if (!window.TextEncoder) {
return btoa(data);
}
var encoder = new TextEncoder();
var bytes = encoder.encode(data);
var trailing = bytes.length % 3;
var out = "";
for (var i = 0; i < bytes.length - trailing; i += 3) {
var u24 = (bytes[i] << 16) + (bytes[i + 1] << 8) + bytes[i + 2];
out += alphabet[(u24 >> 18) & 0x3F];
out += alphabet[(u24 >> 12) & 0x3F];
out += alphabet[(u24 >> 6) & 0x3F];
out += alphabet[u24 & 0x3F];
}
if (trailing == 1) {
var u8 = bytes[bytes.length - 1];
out += alphabet[u8 >> 2];
out += alphabet[(u8 << 4) & 0x3F];
out += "==";
} else if (trailing == 2) {
var u16 = (bytes[bytes.length - 2] << 8) + bytes[bytes.length - 1];
out += alphabet[u16 >> 10];
out += alphabet[(u16 >> 4) & 0x3F];
out += alphabet[(u16 << 2) & 0x3F];
out += "=";
}
return out;
}

View File

@@ -1,4 +1,5 @@
import * as irc from "./irc.js";
import * as base64 from "./base64.js";
// Static list of capabilities that are always requested when supported by the
// server
@@ -9,6 +10,7 @@ const permanentCaps = [
"chghost",
"echo-message",
"extended-join",
"extended-monitor",
"invite-notify",
"labeled-response",
"message-tags",
@@ -19,8 +21,8 @@ const permanentCaps = [
"draft/account-registration",
"draft/chathistory",
"draft/event-playback",
"draft/extended-monitor",
"draft/read-marker",
"soju.im/bouncer-networks",
];
@@ -121,7 +123,10 @@ export default class Client extends EventTarget {
pass: null,
saslPlain: null,
saslExternal: false,
saslOauthBearer: null,
bouncerNetwork: null,
ping: 0,
eventPlayback: true,
};
debug = false;
batches = new Map();
@@ -244,6 +249,7 @@ export default class Client extends EventTarget {
this.setStatus(Client.Status.REGISTERING);
this.reconnectBackoff.reset();
this.setPingInterval(this.params.ping);
this.nick = this.params.nick;
@@ -289,6 +295,9 @@ export default class Client extends EventTarget {
if (!msg.prefix) {
msg.prefix = this.serverPrefix;
}
if (!msg.tags) {
msg.tags = {};
}
let msgBatch = null;
if (msg.tags["batch"]) {
@@ -457,11 +466,15 @@ export default class Client extends EventTarget {
let initialResp = null;
switch (mechanism) {
case "PLAIN":
let respStr = btoa("\0" + params.username + "\0" + params.password);
let respStr = base64.encode("\0" + params.username + "\0" + params.password);
initialResp = { command: "AUTHENTICATE", params: [respStr] };
break;
case "EXTERNAL":
initialResp = { command: "AUTHENTICATE", params: [btoa("")] };
initialResp = { command: "AUTHENTICATE", params: [base64.encode("")] };
break;
case "OAUTHBEARER":
let raw = "n,,\x01auth=Bearer " + params.token + "\x01\x01";
initialResp = { command: "AUTHENTICATE", params: [base64.encode(raw)] };
break;
default:
throw new Error(`Unknown authentication mechanism '${mechanism}'`);
@@ -621,6 +634,9 @@ export default class Client extends EventTarget {
if (!this.params.bouncerNetwork) {
wantCaps.push("soju.im/bouncer-networks-notify");
}
if (this.params.eventPlayback) {
wantCaps.push("draft/event-playback");
}
let msg = this.caps.requestAvailable(wantCaps);
if (msg) {
@@ -651,6 +667,8 @@ export default class Client extends EventTarget {
promise = this.authenticate("PLAIN", this.params.saslPlain);
} else if (this.params.saslExternal) {
promise = this.authenticate("EXTERNAL");
} else if (this.params.saslOauthBearer) {
promise = this.authenticate("OAUTHBEARER", this.params.saslOauthBearer);
}
(promise || Promise.resolve()).catch((err) => {
this.dispatchError(err);
@@ -713,6 +731,11 @@ export default class Client extends EventTarget {
return chanTypes.indexOf(name[0]) >= 0;
}
isNick(name) {
// A dollar sign is used for server-wide broadcasts
return !this.isServer(name) && !this.isChannel(name) && !name.startsWith('$');
}
setPingInterval(sec) {
clearInterval(this.pingIntervalID);
this.pingIntervalID = null;
@@ -802,10 +825,14 @@ export default class Client extends EventTarget {
});
}
join(channel) {
join(channel, password) {
let params = [channel];
if (password) {
params.push(password);
}
let msg = {
command: "JOIN",
params: [channel],
params: params,
};
return this.roundtrip(msg, (msg) => {
switch (msg.command) {
@@ -879,7 +906,7 @@ export default class Client extends EventTarget {
let max = Math.min(limit, this.isupport.chatHistory());
let params = ["BEFORE", target, "timestamp=" + before, max];
return this.roundtripChatHistory(params).then((messages) => {
return { more: messages.length >= max };
return { messages, more: messages.length >= max };
});
}
@@ -892,12 +919,12 @@ export default class Client extends EventTarget {
if (limit <= 0) {
throw new Error("Cannot fetch all chat history: too many messages");
}
if (messages.length == max) {
if (messages.length >= max) {
// There are still more messages to fetch
after.time = messages[messages.length - 1].tags.time;
return this.fetchHistoryBetween(target, after, before, limit);
}
return null;
return { messages };
});
}
@@ -1004,4 +1031,22 @@ export default class Client extends EventTarget {
return { message: msg.params[2] };
});
}
supportsReadMarker() {
return this.caps.enabled.has("draft/read-marker");
}
fetchReadMarker(target) {
this.send({
command: "MARKREAD",
params: [target],
});
}
setReadMarker(target, t) {
this.send({
command: "MARKREAD",
params: [target, "timestamp="+t],
});
}
}

View File

@@ -52,6 +52,7 @@ export const ERR_BADCHANNELKEY = "475";
// RFC 2812
export const ERR_UNAVAILRESOURCE = "437";
// Other
export const RPL_CHANNEL_URL = "328";
export const RPL_CREATIONTIME = "329";
export const RPL_QUIETLIST = "728";
export const RPL_ENDOFQUIETLIST = "729";
@@ -73,7 +74,6 @@ export const ERR_SASLALREADY = "907";
export const STD_MEMBERSHIPS = "~&@%+";
export const STD_CHANTYPES = "#&+!";
export const STD_CHANMODES = "beI,k,l,imnst";
const tagEscapeMap = {
";": "\\:",
@@ -259,7 +259,7 @@ export function parseTargetPrefix(s, allowedPrefixes = STD_MEMBERSHIPS) {
const alphaNum = (() => {
try {
return new RegExp(/^\p{L}$/, "u");
return new RegExp(/^[\p{L}0-9]$/, "u");
} catch (e) {
return new RegExp(/^[a-zA-Z0-9]$/, "u");
}
@@ -271,8 +271,6 @@ function isWordBoundary(ch) {
case "_":
case "|":
return false;
case "\u00A0":
return true;
default:
return !alphaNum.test(ch);
}
@@ -301,7 +299,7 @@ export function isHighlight(msg, nick, cm) {
if (i > 0) {
left = text[i - 1];
}
if (i < text.length) {
if (i + nick.length < text.length) {
right = text[i + nick.length];
}
if (isWordBoundary(left) && isWordBoundary(right)) {
@@ -464,6 +462,53 @@ export class Isupport {
bouncerNetID() {
return this.raw.get("BOUNCER_NETID");
}
chanModes() {
const stdChanModes = ["beI", "k", "l", "imnst"];
if (!this.raw.has("CHANMODES")) {
return stdChanModes;
}
let chanModes = this.raw.get("CHANMODES").split(",");
if (chanModes.length != 4) {
console.error("Invalid CHANMODES: ", this.raw.get("CHANMODES"));
return stdChanModes;
}
return chanModes;
}
bot() {
return this.raw.get("BOT");
}
userLen() {
if (!this.raw.has("USERLEN")) {
return 20;
}
return parseInt(this.raw.get("USERLEN"), 10);
}
hostLen() {
if (!this.raw.has("HOSTLEN")) {
return 63;
}
return parseInt(this.raw.get("HOSTLEN"), 10);
}
lineLen() {
if (!this.raw.has("LINELEN")) {
return 512;
}
return parseInt(this.raw.get("LINELEN"), 10);
}
}
export function getMaxPrivmsgLen(isupport, nick, target) {
let user = "_".repeat(isupport.userLen());
let host = "_".repeat(isupport.hostLen());
let prefix = { name: nick, user, host };
let msg = { prefix, command: "PRIVMSG", params: [target, ""] };
let raw = formatMessage(msg) + "\r\n";
return isupport.lineLen() - raw.length;
}
export const CaseMapping = {
@@ -672,11 +717,10 @@ export function getMessageLabel(msg) {
}
export function forEachChannelModeUpdate(msg, isupport, callback) {
let chanmodes = isupport.chanModes();
let [a, b, c, d] = isupport.chanModes();
let prefix = isupport.prefix();
let typeByMode = new Map();
let [a, b, c, d] = chanmodes.split(",");
Array.from(a).forEach((mode) => typeByMode.set(mode, "A"));
Array.from(b).forEach((mode) => typeByMode.set(mode, "B"));
Array.from(c).forEach((mode) => typeByMode.set(mode, "C"));
@@ -834,7 +878,6 @@ export class CapRegistry {
});
break;
case "ACK":
// TODO: handle `ACK -cap` to
args[0].split(" ").forEach((cap) => {
cap = cap.toLowerCase();
if (cap.startsWith("-")) {

109
lib/oauth2.js Normal file
View File

@@ -0,0 +1,109 @@
function formatQueryString(params) {
let l = [];
for (let k in params) {
l.push(encodeURIComponent(k) + "=" + encodeURIComponent(params[k]));
}
return l.join("&");
}
export async function fetchServerMetadata(url) {
// TODO: handle path in config.oauth2.url
let resp;
try {
resp = await fetch(url + "/.well-known/oauth-authorization-server");
if (!resp.ok) {
throw new Error(`HTTP error: ${resp.status} ${resp.statusText}`);
}
} catch (err) {
console.warn("OAuth 2.0 server doesn't support Authorization Server Metadata (retrying with OpenID Connect Discovery): ", err);
resp = await fetch(url + "/.well-known/openid-configuration");
if (!resp.ok) {
throw new Error(`HTTP error: ${resp.status} ${resp.statusText}`);
}
}
let data = await resp.json();
if (!data.issuer) {
throw new Error("Missing issuer in response");
}
if (!data.authorization_endpoint) {
throw new Error("Missing authorization_endpoint in response");
}
if (!data.token_endpoint) {
throw new Error("Missing authorization_endpoint in response");
}
if (!data.response_types_supported.includes("code")) {
throw new Error("Server doesn't support authorization code response type");
}
return data;
}
export function redirectAuthorize({ serverMetadata, clientId, redirectUri, scope }) {
// TODO: move fragment to query string in redirect_uri
// TODO: use the state param to prevent cross-site request
// forgery
let params = {
response_type: "code",
client_id: clientId,
redirect_uri: redirectUri,
};
if (scope) {
params.scope = scope;
}
window.location.assign(serverMetadata.authorization_endpoint + "?" + formatQueryString(params));
}
function buildPostHeaders(clientId, clientSecret) {
let headers = {
"Content-Type": "application/x-www-form-urlencoded",
"Accept": "application/json",
};
if (clientSecret) {
headers["Authorization"] = "Basic " + btoa(encodeURIComponent(clientId) + ":" + encodeURIComponent(clientSecret));
}
return headers;
}
export async function exchangeCode({ serverMetadata, redirectUri, code, clientId, clientSecret }) {
let data = {
grant_type: "authorization_code",
code,
redirect_uri: redirectUri,
};
if (!clientSecret) {
data.client_id = clientId;
}
let resp = await fetch(serverMetadata.token_endpoint, {
method: "POST",
headers: buildPostHeaders(clientId, clientSecret),
body: formatQueryString(data),
});
if (!resp.ok) {
throw new Error(`HTTP error: ${resp.status} ${resp.statusText}`);
}
data = await resp.json();
if (data.error) {
throw new Error("Authentication failed: " + (data.error_description || data.error));
}
return data;
}
export async function introspectToken({ serverMetadata, token, clientId, clientSecret }) {
let resp = await fetch(serverMetadata.introspection_endpoint, {
method: "POST",
headers: buildPostHeaders(clientId, clientSecret),
body: formatQueryString({ token }),
});
if (!resp.ok) {
throw new Error(`HTTP error: ${resp.status} ${resp.statusText}`);
}
let data = await resp.json();
if (!data.active) {
throw new Error("Expired token");
}
return data;
}

13653
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -24,5 +24,8 @@
"source": "index.html",
"publicUrl": "."
}
},
"engines": {
"node": ">=14.13.0"
}
}

View File

@@ -1,5 +1,6 @@
import * as irc from "./lib/irc.js";
import Client from "./lib/client.js";
import { createContext } from "./lib/index.js";
export const SERVER_BUFFER = "*";
@@ -34,6 +35,14 @@ export const ReceiptType = {
READ: "read",
};
export const BufferEventsDisplayMode = {
FOLD: "fold",
EXPAND: "expand",
HIDE: "hide",
};
export const SettingsContext = createContext("settings");
export function getNickURL(nick) {
return "irc:///" + encodeURIComponent(nick) + ",isuser";
}
@@ -85,6 +94,42 @@ export function getServerName(server, bouncerNetwork) {
}
}
export function receiptFromMessage(msg) {
// At this point all messages are supposed to have a time tag.
// App.addMessage ensures this is the case even if the server doesn't
// support server-time.
if (!msg.tags.time) {
throw new Error("Missing time message tag");
}
return { time: msg.tags.time };
}
export function isReceiptBefore(a, b) {
if (!b) {
return false;
}
if (!a) {
return true;
}
if (!a.time || !b.time) {
throw new Error("Missing receipt time");
}
return a.time <= b.time;
}
export function isMessageBeforeReceipt(msg, receipt) {
if (!receipt) {
return false;
}
if (!msg.tags.time) {
throw new Error("Missing time message tag");
}
if (!receipt.time) {
throw new Error("Missing receipt time");
}
return msg.tags.time <= receipt.time;
}
function updateState(state, updater) {
let updated;
if (typeof updater === "function") {
@@ -112,7 +157,7 @@ function compareBuffers(a, b) {
return isServerBuffer(b) ? 1 : -1;
}
if (a.name != b.name) {
return a.name > b.name ? 1 : -1;
return a.name.localeCompare(b.name);
}
return 0;
}
@@ -172,6 +217,11 @@ export const State = {
servers: new Map(),
buffers: new Map(),
activeBuffer: null,
bouncerNetworks: new Map(),
settings: {
secondsInTimestamps: true,
bufferEvents: BufferEventsDisplayMode.FOLD,
},
};
},
updateServer(state, id, updater) {
@@ -293,6 +343,7 @@ export const State = {
serverInfo: null, // if server
joined: false, // if channel
topic: null, // if channel
hasInitialWho: false, // if channel
members: new irc.CaseMapMap(null, client.cm), // if channel
messages: [],
unread: Unread.NONE,
@@ -302,6 +353,19 @@ export const State = {
let buffers = new Map(bufferList.map((buf) => [buf.id, buf]));
return [id, { buffers }];
},
storeBouncerNetwork(state, id, attrs) {
let bouncerNetworks = new Map(state.bouncerNetworks);
bouncerNetworks.set(id, {
...bouncerNetworks.get(id),
...attrs,
});
return { bouncerNetworks };
},
deleteBouncerNetwork(state, id) {
let bouncerNetworks = new Map(state.bouncerNetworks);
bouncerNetworks.delete(id);
return { bouncerNetworks };
},
handleMessage(state, msg, serverID, client) {
function updateServer(updater) {
return State.updateServer(state, serverID, updater);
@@ -404,6 +468,10 @@ export const State = {
if (who.flags !== undefined) {
who.away = who.flags.indexOf("G") >= 0; // H for here, G for gone
who.operator = who.flags.indexOf("*") >= 0;
let botFlag = client.isupport.bot();
if (botFlag) {
who.bot = who.flags.indexOf(botFlag) >= 0;
}
delete who.flags;
}

View File

@@ -1,3 +1,5 @@
import { ReceiptType } from "./state.js";
const PREFIX = "gamja_";
class Item {
@@ -24,18 +26,18 @@ class Item {
export const autoconnect = new Item("autoconnect");
export const naggedProtocolHandler = new Item("naggedProtocolHandler");
export const settings = new Item("settings");
const rawReceipts = new Item("receipts");
export const receipts = {
load() {
let v = rawReceipts.load();
return new Map(Object.entries(v || {}));
},
put(m) {
rawReceipts.put(Object.fromEntries(m));
},
};
function debounce(f, delay) {
let timeout = null;
return (...args) => {
clearTimeout(timeout);
timeout = setTimeout(() => {
timeout = null;
f(...args);
}, delay);
};
}
export class Buffer {
raw = new Item("buffers");
@@ -44,14 +46,24 @@ export class Buffer {
constructor() {
let obj = this.raw.load();
this.m = new Map(Object.entries(obj || {}));
let saveImmediately = this.save.bind(this);
this.save = debounce(saveImmediately, 500);
document.addEventListener("visibilitychange", () => {
if (document.visibilityState === "hidden") {
saveImmediately();
}
});
}
key(buf) {
// TODO: use case-mapping here somehow
return JSON.stringify({
name: buf.name,
name: buf.name.toLowerCase(),
server: {
url: buf.server.url,
nick: buf.server.nick,
nick: buf.server.nick.toLowerCase(),
bouncerNetwork: buf.server.bouncerNetwork,
},
});
@@ -72,14 +84,39 @@ export class Buffer {
put(buf) {
let key = this.key(buf);
let prev = this.m.get(key);
if (prev && prev.unread === buf.unread) {
return;
let updated = !this.m.has(key);
let prev = this.m.get(key) || {};
let unread = prev.unread;
if (buf.unread !== undefined && buf.unread !== prev.unread) {
unread = buf.unread;
updated = true;
}
let receipts = { ...prev.receipts };
if (buf.receipts) {
Object.keys(buf.receipts).forEach((k) => {
// Use a not-equals comparison here so that no-op receipt
// changes are correctly handled
if (!receipts[k] || receipts[k].time < buf.receipts[k].time) {
receipts[k] = buf.receipts[k];
updated = true;
}
});
if (receipts[ReceiptType.DELIVERED] < receipts[ReceiptType.READ]) {
receipts[ReceiptType.DELIVERED] = receipts[ReceiptType.READ];
updated = true;
}
}
if (!updated) {
return false;
}
this.m.set(this.key(buf), {
name: buf.name,
unread: buf.unread,
unread,
receipts,
server: {
url: buf.server.url,
nick: buf.server.nick,
@@ -88,6 +125,7 @@ export class Buffer {
});
this.save();
return true;
}
delete(buf) {

View File

@@ -158,6 +158,9 @@ button.danger:hover {
color: white;
background-color: var(--gray);
}
#buffer-list li.error a {
color: red;
}
#buffer-list li.unread-message a {
color: #b37400;
}
@@ -186,7 +189,7 @@ button.danger:hover {
grid-column: 2;
display: grid;
grid-template-rows: auto auto;
grid-template-rows: 1fr auto;
grid-template-columns: 1fr auto;
}
@@ -202,6 +205,9 @@ button.danger:hover {
padding: 5px 10px;
grid-row: 2;
grid-column: 1;
max-height: 20vh;
overflow-y: auto;
word-break: break-word;
}
#buffer-header .actions {
@@ -349,6 +355,8 @@ form input[type="url"],
form input[type="email"] {
box-sizing: border-box;
width: 100%;
font-family: inherit;
font-size: inherit;
}
a {
@@ -530,6 +538,14 @@ details summary[role="button"] {
overflow: auto; /* hack to clear floating elements */
}
.dialog .protocol-handler {
display: flex;
flex-direction: row;
}
.dialog .protocol-handler .left {
flex-grow: 1;
}
kbd {
background-color: #f0f0f0;
border: 1px solid #bfbfbf;