mirror of
https://codeberg.org/emersion/gamja.git
synced 2025-02-17 19:40:15 -05:00
Add message URLs, unify URL generation
This commit is contained in:
parent
36df984b09
commit
0d9f7f35f0
4 changed files with 31 additions and 24 deletions
|
@ -1,5 +1,5 @@
|
|||
import { html, Component } from "/lib/index.js";
|
||||
import { BufferType, Unread } from "/state.js";
|
||||
import { BufferType, Unread, getBufferURL } from "/state.js";
|
||||
|
||||
function BufferItem(props) {
|
||||
function handleClick(event) {
|
||||
|
@ -19,22 +19,9 @@ function BufferItem(props) {
|
|||
unreadClass = "unread-" + props.buffer.unread;
|
||||
}
|
||||
|
||||
var url = "#";
|
||||
switch (props.buffer.type) {
|
||||
case BufferType.SERVER:
|
||||
url = "irc:///";
|
||||
break;
|
||||
case BufferType.CHANNEL:
|
||||
url = "irc:///" + encodeURIComponent(props.buffer.name);
|
||||
break;
|
||||
case BufferType.NICK:
|
||||
url = "irc:///" + encodeURIComponent(props.buffer.name) + ",isnick";
|
||||
break;
|
||||
}
|
||||
|
||||
return html`
|
||||
<li class="${activeClass} ${unreadClass}">
|
||||
<a href=${url} onClick=${handleClick}>${name}</a>
|
||||
<a href=${getBufferURL(props.buffer)} onClick=${handleClick}>${name}</a>
|
||||
</li>
|
||||
`;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { html, Component } from "/lib/index.js";
|
||||
import linkify from "/lib/linkify.js";
|
||||
import * as irc from "/lib/irc.js";
|
||||
import { BufferType } from "/state.js";
|
||||
import { BufferType, getNickURL, getMessageURL } from "/state.js";
|
||||
|
||||
function djb2(s) {
|
||||
var hash = 5381;
|
||||
|
@ -19,13 +19,12 @@ function Nick(props) {
|
|||
}
|
||||
|
||||
var colorIndex = djb2(props.nick) % 16 + 1;
|
||||
var url = "irc:///" + encodeURIComponent(props.nick) + ",isnick";
|
||||
return html`
|
||||
<a href=${url} class="nick nick-${colorIndex}" onClick=${handleClick}>${props.nick}</a>
|
||||
<a href=${getNickURL(props.nick)} class="nick nick-${colorIndex}" onClick=${handleClick}>${props.nick}</a>
|
||||
`;
|
||||
}
|
||||
|
||||
function Timestamp({ date }) {
|
||||
function Timestamp({ date, url }) {
|
||||
if (!date) {
|
||||
return html`<spam class="timestamp">--:--:--</span>`;
|
||||
}
|
||||
|
@ -35,7 +34,7 @@ function Timestamp({ date }) {
|
|||
var ss = date.getSeconds().toString().padStart(2, "0");
|
||||
var timestamp = `${hh}:${mm}:${ss}`;
|
||||
return html`
|
||||
<a href="#" class="timestamp" onClick=${(event) => event.preventDefault()}>${timestamp}</a>
|
||||
<a href=${url} class="timestamp" onClick=${(event) => event.preventDefault()}>${timestamp}</a>
|
||||
`;
|
||||
}
|
||||
|
||||
|
@ -107,7 +106,7 @@ class LogLine extends Component {
|
|||
|
||||
return html`
|
||||
<div class="logline ${lineClass}">
|
||||
<${Timestamp} date=${new Date(msg.tags.time)}/>
|
||||
<${Timestamp} date=${new Date(msg.tags.time)} url=${getMessageURL(this.props.buffer, msg)}/>
|
||||
${" "}
|
||||
${content}
|
||||
</div>
|
||||
|
@ -172,7 +171,7 @@ export default class Buffer extends Component {
|
|||
<div class="logline-list">
|
||||
${notifNagger}
|
||||
${this.props.buffer.messages.map((msg) => html`
|
||||
<${LogLine} key=${msg.key} message=${msg} onNickClick=${this.props.onNickClick}/>
|
||||
<${LogLine} key=${msg.key} message=${msg} buffer=${this.props.buffer} onNickClick=${this.props.onNickClick}/>
|
||||
`)}
|
||||
</div>
|
||||
`;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { html, Component } from "/lib/index.js";
|
||||
import { getNickURL } from "/state.js";
|
||||
|
||||
class MemberItem extends Component {
|
||||
constructor(props) {
|
||||
|
@ -17,10 +18,9 @@ class MemberItem extends Component {
|
|||
}
|
||||
|
||||
render() {
|
||||
var url = "irc:///" + encodeURIComponent(this.props.nick) + ",isnick";
|
||||
return html`
|
||||
<li>
|
||||
<a href=${url} class="nick" onClick=${this.handleClick}>${this.props.nick}</a>
|
||||
<a href=${getNickURL(this.props.nick)} class="nick" onClick=${this.handleClick}>${this.props.nick}</a>
|
||||
</li>
|
||||
`;
|
||||
}
|
||||
|
|
21
state.js
21
state.js
|
@ -26,3 +26,24 @@ export const Unread = {
|
|||
return (priority[a] > priority[b]) ? a : b;
|
||||
},
|
||||
};
|
||||
|
||||
export function getNickURL(nick) {
|
||||
return "irc:///" + encodeURIComponent(nick) + ",isnick";
|
||||
}
|
||||
|
||||
export function getBufferURL(buf) {
|
||||
switch (buf.type) {
|
||||
case BufferType.SERVER:
|
||||
return "irc:///";
|
||||
case BufferType.CHANNEL:
|
||||
return "irc:///" + encodeURIComponent(buf.name);
|
||||
case BufferType.NICK:
|
||||
return getNickURL(buf.name);
|
||||
}
|
||||
throw new Error("Unknown buffer type: " + buf.type);
|
||||
}
|
||||
|
||||
export function getMessageURL(buf, msg) {
|
||||
var bufURL = getBufferURL(buf);
|
||||
return bufURL + "#timestamp=" + encodeURIComponent(msg.tags.time);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue