mirror of
https://codeberg.org/emersion/gamja
synced 2025-03-13 07:48:37 +01:00
Limit composer length
Often times IRC servers will truncate messages which are too big.
This commit is contained in:
parent
cfbd91d257
commit
e7b69cec9a
@ -1928,8 +1928,12 @@ export default class App extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let commandOnly = false;
|
let commandOnly = false;
|
||||||
|
let privmsgMaxLen;
|
||||||
if (activeBuffer && activeBuffer.type === BufferType.SERVER) {
|
if (activeBuffer && activeBuffer.type === BufferType.SERVER) {
|
||||||
commandOnly = true;
|
commandOnly = true;
|
||||||
|
} else if (activeBuffer) {
|
||||||
|
let client = this.clients.get(activeBuffer.server);
|
||||||
|
privmsgMaxLen = irc.getMaxPrivmsgLen(client.isupport, client.nick, activeBuffer.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
let app = html`
|
let app = html`
|
||||||
@ -1981,6 +1985,7 @@ export default class App extends Component {
|
|||||||
onSubmit=${this.handleComposerSubmit}
|
onSubmit=${this.handleComposerSubmit}
|
||||||
autocomplete=${this.autocomplete}
|
autocomplete=${this.autocomplete}
|
||||||
commandOnly=${commandOnly}
|
commandOnly=${commandOnly}
|
||||||
|
maxLen=${privmsgMaxLen}
|
||||||
/>
|
/>
|
||||||
${dialog}
|
${dialog}
|
||||||
${error}
|
${error}
|
||||||
|
@ -222,6 +222,7 @@ export default class Composer extends Component {
|
|||||||
placeholder=${placeholder}
|
placeholder=${placeholder}
|
||||||
enterkeyhint="send"
|
enterkeyhint="send"
|
||||||
onKeyDown=${this.handleInputKeyDown}
|
onKeyDown=${this.handleInputKeyDown}
|
||||||
|
maxlength=${this.props.maxLen}
|
||||||
/>
|
/>
|
||||||
</form>
|
</form>
|
||||||
`;
|
`;
|
||||||
|
30
lib/irc.js
30
lib/irc.js
@ -479,6 +479,36 @@ export class Isupport {
|
|||||||
bot() {
|
bot() {
|
||||||
return this.raw.get("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 = {
|
export const CaseMapping = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user