forked from CringeStudios/gamja
Add message URLs, unify URL generation
This commit is contained in:
parent
36df984b09
commit
0d9f7f35f0
@ -1,5 +1,5 @@
|
|||||||
import { html, Component } from "/lib/index.js";
|
import { html, Component } from "/lib/index.js";
|
||||||
import { BufferType, Unread } from "/state.js";
|
import { BufferType, Unread, getBufferURL } from "/state.js";
|
||||||
|
|
||||||
function BufferItem(props) {
|
function BufferItem(props) {
|
||||||
function handleClick(event) {
|
function handleClick(event) {
|
||||||
@ -19,22 +19,9 @@ function BufferItem(props) {
|
|||||||
unreadClass = "unread-" + props.buffer.unread;
|
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`
|
return html`
|
||||||
<li class="${activeClass} ${unreadClass}">
|
<li class="${activeClass} ${unreadClass}">
|
||||||
<a href=${url} onClick=${handleClick}>${name}</a>
|
<a href=${getBufferURL(props.buffer)} onClick=${handleClick}>${name}</a>
|
||||||
</li>
|
</li>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { html, Component } from "/lib/index.js";
|
import { html, Component } from "/lib/index.js";
|
||||||
import linkify from "/lib/linkify.js";
|
import linkify from "/lib/linkify.js";
|
||||||
import * as irc from "/lib/irc.js";
|
import * as irc from "/lib/irc.js";
|
||||||
import { BufferType } from "/state.js";
|
import { BufferType, getNickURL, getMessageURL } from "/state.js";
|
||||||
|
|
||||||
function djb2(s) {
|
function djb2(s) {
|
||||||
var hash = 5381;
|
var hash = 5381;
|
||||||
@ -19,13 +19,12 @@ function Nick(props) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var colorIndex = djb2(props.nick) % 16 + 1;
|
var colorIndex = djb2(props.nick) % 16 + 1;
|
||||||
var url = "irc:///" + encodeURIComponent(props.nick) + ",isnick";
|
|
||||||
return html`
|
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) {
|
if (!date) {
|
||||||
return html`<spam class="timestamp">--:--:--</span>`;
|
return html`<spam class="timestamp">--:--:--</span>`;
|
||||||
}
|
}
|
||||||
@ -35,7 +34,7 @@ function Timestamp({ date }) {
|
|||||||
var ss = date.getSeconds().toString().padStart(2, "0");
|
var ss = date.getSeconds().toString().padStart(2, "0");
|
||||||
var timestamp = `${hh}:${mm}:${ss}`;
|
var timestamp = `${hh}:${mm}:${ss}`;
|
||||||
return html`
|
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`
|
return html`
|
||||||
<div class="logline ${lineClass}">
|
<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}
|
${content}
|
||||||
</div>
|
</div>
|
||||||
@ -172,7 +171,7 @@ export default class Buffer extends Component {
|
|||||||
<div class="logline-list">
|
<div class="logline-list">
|
||||||
${notifNagger}
|
${notifNagger}
|
||||||
${this.props.buffer.messages.map((msg) => html`
|
${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>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { html, Component } from "/lib/index.js";
|
import { html, Component } from "/lib/index.js";
|
||||||
|
import { getNickURL } from "/state.js";
|
||||||
|
|
||||||
class MemberItem extends Component {
|
class MemberItem extends Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
@ -17,10 +18,9 @@ class MemberItem extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
var url = "irc:///" + encodeURIComponent(this.props.nick) + ",isnick";
|
|
||||||
return html`
|
return html`
|
||||||
<li>
|
<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>
|
</li>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
21
state.js
21
state.js
@ -26,3 +26,24 @@ export const Unread = {
|
|||||||
return (priority[a] > priority[b]) ? a : b;
|
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…
x
Reference in New Issue
Block a user