Handle channel forwarding and errors better

This commit is contained in:
Ken-Håvard Lieng 2019-01-25 11:02:31 +01:00
parent 497934888c
commit f8e12f5938
15 changed files with 481 additions and 213 deletions

File diff suppressed because one or more lines are too long

View File

@ -149,6 +149,10 @@ i[class*=' icon-']:before {
color: #f6546a !important;
}
.disabled {
color: #999 !important;
}
.textinput {
display: block;
position: relative;

View File

@ -1,7 +1,7 @@
import React, { PureComponent } from 'react';
import classnames from 'classnames';
import Button from 'components/ui/Button';
import TabListItem from './TabListItem';
import TabListItem from 'containers/TabListItem';
export default class TabList extends PureComponent {
handleTabClick = (server, target) => this.props.select(server, target);

View File

@ -1,4 +1,4 @@
import React, { memo } from 'react';
import React from 'react';
import classnames from 'classnames';
const TabListItem = ({
@ -7,12 +7,15 @@ const TabListItem = ({
server,
selected,
connected,
joined,
error,
onClick
}) => {
const className = classnames({
'tab-server': !target,
success: !target && connected,
error: !target && !connected,
error: (!target && !connected) || (!joined && error),
disabled: !!target && !error && joined === false,
selected
});
@ -23,4 +26,4 @@ const TabListItem = ({
);
};
export default memo(TabListItem);
export default TabListItem;

View File

@ -0,0 +1,20 @@
import { createStructuredSelector } from 'reselect';
import get from 'lodash/get';
import TabListItem from 'components/TabListItem';
import connect from 'utils/connect';
const mapState = createStructuredSelector({
joined: (state, { server, target }) =>
get(state, ['channels', server, target, 'joined']),
error: (state, { server, target }) => {
const messages = get(state, ['messages', server, target]);
if (messages && messages.length > 0) {
return messages[messages.length - 1].type === 'error';
}
return false;
}
});
export default connect(mapState)(TabListItem);

View File

@ -10,7 +10,7 @@ import {
import { openModal } from 'state/modals';
import { reconnect } from 'state/servers';
import { select } from 'state/tab';
import { find, normalizeChannel } from 'utils';
import { find } from 'utils';
function withReason(message, reason) {
return message + (reason ? ` (${reason})` : '');
@ -46,22 +46,7 @@ export default function handleSocket({
},
join({ user, server, channels }) {
const state = getState();
const tab = state.tab.selected;
const [joinedChannel] = channels;
if (tab.server && tab.name) {
const { nick } = state.servers[tab.server];
if (
tab.server === server &&
nick === user &&
tab.name !== joinedChannel &&
normalizeChannel(tab.name) === normalizeChannel(joinedChannel)
) {
dispatch(select(server, joinedChannel));
}
}
dispatch(inform(`${user} joined the channel`, server, joinedChannel));
dispatch(inform(`${user} joined the channel`, server, channels[0]));
},
part({ user, server, channel, reason }) {
@ -123,6 +108,10 @@ export default function handleSocket({
dispatch(addMessage(message, tab.server, tab.name));
},
error({ server, target, message }) {
dispatch(addMessage({ content: message, type: 'error' }, server, target));
},
connection_update({ server, errorType }) {
if (errorType === 'verify') {
dispatch(
@ -145,6 +134,16 @@ export default function handleSocket({
}
};
const afterHandlers = {
channel_forward(forward) {
const { selected } = getState().tab;
if (selected.server === forward.server && selected.name === forward.old) {
dispatch(select(forward.server, forward.new, true));
}
}
};
socket.onMessage((type, data) => {
let action;
if (Array.isArray(data)) {
@ -162,5 +161,9 @@ export default function handleSocket({
}
dispatch(action);
if (type in afterHandlers) {
afterHandlers[type](data);
}
});
}

View File

@ -66,8 +66,10 @@ export const socket = createSocketActions([
'cert_fail',
'cert_success',
'channels',
'channel_forward',
'channel_search',
'connection_update',
'error',
'join',
'message',
'mode',

View File

@ -140,6 +140,11 @@ export default createReducer(
state[server][channel].users.push(createUser(user));
},
[actions.socket.CHANNEL_FORWARD](state, action) {
init(state, action.server, action.new);
delete state[action.server][action.old];
},
[actions.socket.PART](state, { server, channel, user }) {
if (state[server][channel]) {
removeUser(state[server][channel].users, user);
@ -230,16 +235,27 @@ export function join(channels, server) {
}
export function part(channels, server) {
return dispatch => {
dispatch({
return (dispatch, getState) => {
const action = {
type: actions.PART,
channels,
server,
socket: {
server
};
const state = getState().channels[server];
const joined = channels.filter(c => state[c] && state[c].joined);
if (joined.length > 0) {
action.socket = {
type: 'part',
data: { channels, server }
}
});
data: {
channels: joined,
server
}
};
}
dispatch(action);
dispatch(updateSelection());
};
}

View File

@ -140,6 +140,12 @@ export default createReducer(
channels.forEach(channel => delete state[server][channel]);
},
[actions.socket.CHANNEL_FORWARD](state, { server, old }) {
if (state[server]) {
delete state[server][old];
}
},
[actions.UPDATE_MESSAGE_HEIGHT](
state,
{ wrapWidth, charWidth, windowWidth }

View File

@ -39,4 +39,5 @@ const (
ReplyEndOfMotd = "376"
ErrErroneousNickname = "432"
ErrNicknameInUse = "433"
ErrForward = "470"
)

View File

@ -3,6 +3,7 @@ package server
import (
"crypto/tls"
"encoding/hex"
"fmt"
"net"
"github.com/khlieng/dispatch/pkg/irc"
@ -19,7 +20,10 @@ func createNickInUseHandler(i *irc.Client, state *State) func(string) string {
})
}
state.printError("Nickname", nick, "is already in use, using", newNick, "instead")
state.sendJSON("error", IRCError{
Server: i.Host,
Message: fmt.Sprintf("Nickname %s is already in use, using %s instead", nick, newNick),
})
return newNick
}

View File

@ -15,6 +15,7 @@ import (
var excludedErrors = []string{
irc.ErrNicknameInUse,
irc.ErrForward,
}
type ircHandler struct {
@ -68,7 +69,21 @@ func (i *ircHandler) run() {
func (i *ircHandler) dispatchMessage(msg *irc.Message) {
if msg.Command[0] == '4' && !isExcludedError(msg.Command) {
i.state.printError(formatIRCError(msg))
err := IRCError{
Server: i.client.Host,
Message: msg.LastParam(),
}
if len(msg.Params) > 2 {
for i := 1; i < len(msg.Params); i++ {
if isChannel(msg.Params[i]) {
err.Target = msg.Params[i]
break
}
}
}
i.state.sendJSON("error", err)
}
if handler, ok := i.handlers[msg.Command]; ok {
@ -323,8 +338,21 @@ func (i *ircHandler) badNick(msg *irc.Message) {
})
}
func (i *ircHandler) forward(msg *irc.Message) {
if len(msg.Params) > 2 {
i.state.sendJSON("channel_forward", ChannelForward{
Server: i.client.Host,
Old: msg.Params[1],
New: msg.Params[2],
})
}
}
func (i *ircHandler) error(msg *irc.Message) {
i.state.printError(msg.LastParam())
i.state.sendJSON("error", IRCError{
Server: i.client.Host,
Message: msg.LastParam(),
})
}
func (i *ircHandler) initHandlers() {
@ -360,6 +388,7 @@ func (i *ircHandler) initHandlers() {
irc.ReplyList: i.list,
irc.ReplyListEnd: i.listEnd,
irc.ErrErroneousNickname: i.badNick,
irc.ErrForward: i.forward,
}
}

View File

@ -193,6 +193,12 @@ type Error struct {
Message string
}
type IRCError struct {
Server string
Target string
Message string
}
type ChannelSearch struct {
Server string
Q string
@ -203,3 +209,9 @@ type ChannelSearchResult struct {
Results []*storage.ChannelListItem
Start int
}
type ChannelForward struct {
Server string
Old string
New string
}

View File

@ -2633,7 +2633,102 @@ func (v *Invite) UnmarshalJSON(data []byte) error {
func (v *Invite) UnmarshalEasyJSON(l *jlexer.Lexer) {
easyjson42239ddeDecodeGithubComKhliengDispatchServer22(l, v)
}
func easyjson42239ddeDecodeGithubComKhliengDispatchServer23(in *jlexer.Lexer, out *FetchMessages) {
func easyjson42239ddeDecodeGithubComKhliengDispatchServer23(in *jlexer.Lexer, out *IRCError) {
isTopLevel := in.IsStart()
if in.IsNull() {
if isTopLevel {
in.Consumed()
}
in.Skip()
return
}
in.Delim('{')
for !in.IsDelim('}') {
key := in.UnsafeString()
in.WantColon()
if in.IsNull() {
in.Skip()
in.WantComma()
continue
}
switch key {
case "server":
out.Server = string(in.String())
case "target":
out.Target = string(in.String())
case "message":
out.Message = string(in.String())
default:
in.SkipRecursive()
}
in.WantComma()
}
in.Delim('}')
if isTopLevel {
in.Consumed()
}
}
func easyjson42239ddeEncodeGithubComKhliengDispatchServer23(out *jwriter.Writer, in IRCError) {
out.RawByte('{')
first := true
_ = first
if in.Server != "" {
const prefix string = ",\"server\":"
if first {
first = false
out.RawString(prefix[1:])
} else {
out.RawString(prefix)
}
out.String(string(in.Server))
}
if in.Target != "" {
const prefix string = ",\"target\":"
if first {
first = false
out.RawString(prefix[1:])
} else {
out.RawString(prefix)
}
out.String(string(in.Target))
}
if in.Message != "" {
const prefix string = ",\"message\":"
if first {
first = false
out.RawString(prefix[1:])
} else {
out.RawString(prefix)
}
out.String(string(in.Message))
}
out.RawByte('}')
}
// MarshalJSON supports json.Marshaler interface
func (v IRCError) MarshalJSON() ([]byte, error) {
w := jwriter.Writer{}
easyjson42239ddeEncodeGithubComKhliengDispatchServer23(&w, v)
return w.Buffer.BuildBytes(), w.Error
}
// MarshalEasyJSON supports easyjson.Marshaler interface
func (v IRCError) MarshalEasyJSON(w *jwriter.Writer) {
easyjson42239ddeEncodeGithubComKhliengDispatchServer23(w, v)
}
// UnmarshalJSON supports json.Unmarshaler interface
func (v *IRCError) UnmarshalJSON(data []byte) error {
r := jlexer.Lexer{Data: data}
easyjson42239ddeDecodeGithubComKhliengDispatchServer23(&r, v)
return r.Error()
}
// UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (v *IRCError) UnmarshalEasyJSON(l *jlexer.Lexer) {
easyjson42239ddeDecodeGithubComKhliengDispatchServer23(l, v)
}
func easyjson42239ddeDecodeGithubComKhliengDispatchServer24(in *jlexer.Lexer, out *FetchMessages) {
isTopLevel := in.IsStart()
if in.IsNull() {
if isTopLevel {
@ -2668,7 +2763,7 @@ func easyjson42239ddeDecodeGithubComKhliengDispatchServer23(in *jlexer.Lexer, ou
in.Consumed()
}
}
func easyjson42239ddeEncodeGithubComKhliengDispatchServer23(out *jwriter.Writer, in FetchMessages) {
func easyjson42239ddeEncodeGithubComKhliengDispatchServer24(out *jwriter.Writer, in FetchMessages) {
out.RawByte('{')
first := true
_ = first
@ -2708,27 +2803,27 @@ func easyjson42239ddeEncodeGithubComKhliengDispatchServer23(out *jwriter.Writer,
// MarshalJSON supports json.Marshaler interface
func (v FetchMessages) MarshalJSON() ([]byte, error) {
w := jwriter.Writer{}
easyjson42239ddeEncodeGithubComKhliengDispatchServer23(&w, v)
easyjson42239ddeEncodeGithubComKhliengDispatchServer24(&w, v)
return w.Buffer.BuildBytes(), w.Error
}
// MarshalEasyJSON supports easyjson.Marshaler interface
func (v FetchMessages) MarshalEasyJSON(w *jwriter.Writer) {
easyjson42239ddeEncodeGithubComKhliengDispatchServer23(w, v)
easyjson42239ddeEncodeGithubComKhliengDispatchServer24(w, v)
}
// UnmarshalJSON supports json.Unmarshaler interface
func (v *FetchMessages) UnmarshalJSON(data []byte) error {
r := jlexer.Lexer{Data: data}
easyjson42239ddeDecodeGithubComKhliengDispatchServer23(&r, v)
easyjson42239ddeDecodeGithubComKhliengDispatchServer24(&r, v)
return r.Error()
}
// UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (v *FetchMessages) UnmarshalEasyJSON(l *jlexer.Lexer) {
easyjson42239ddeDecodeGithubComKhliengDispatchServer23(l, v)
easyjson42239ddeDecodeGithubComKhliengDispatchServer24(l, v)
}
func easyjson42239ddeDecodeGithubComKhliengDispatchServer24(in *jlexer.Lexer, out *Error) {
func easyjson42239ddeDecodeGithubComKhliengDispatchServer25(in *jlexer.Lexer, out *Error) {
isTopLevel := in.IsStart()
if in.IsNull() {
if isTopLevel {
@ -2761,7 +2856,7 @@ func easyjson42239ddeDecodeGithubComKhliengDispatchServer24(in *jlexer.Lexer, ou
in.Consumed()
}
}
func easyjson42239ddeEncodeGithubComKhliengDispatchServer24(out *jwriter.Writer, in Error) {
func easyjson42239ddeEncodeGithubComKhliengDispatchServer25(out *jwriter.Writer, in Error) {
out.RawByte('{')
first := true
_ = first
@ -2791,27 +2886,27 @@ func easyjson42239ddeEncodeGithubComKhliengDispatchServer24(out *jwriter.Writer,
// MarshalJSON supports json.Marshaler interface
func (v Error) MarshalJSON() ([]byte, error) {
w := jwriter.Writer{}
easyjson42239ddeEncodeGithubComKhliengDispatchServer24(&w, v)
easyjson42239ddeEncodeGithubComKhliengDispatchServer25(&w, v)
return w.Buffer.BuildBytes(), w.Error
}
// MarshalEasyJSON supports easyjson.Marshaler interface
func (v Error) MarshalEasyJSON(w *jwriter.Writer) {
easyjson42239ddeEncodeGithubComKhliengDispatchServer24(w, v)
easyjson42239ddeEncodeGithubComKhliengDispatchServer25(w, v)
}
// UnmarshalJSON supports json.Unmarshaler interface
func (v *Error) UnmarshalJSON(data []byte) error {
r := jlexer.Lexer{Data: data}
easyjson42239ddeDecodeGithubComKhliengDispatchServer24(&r, v)
easyjson42239ddeDecodeGithubComKhliengDispatchServer25(&r, v)
return r.Error()
}
// UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (v *Error) UnmarshalEasyJSON(l *jlexer.Lexer) {
easyjson42239ddeDecodeGithubComKhliengDispatchServer24(l, v)
easyjson42239ddeDecodeGithubComKhliengDispatchServer25(l, v)
}
func easyjson42239ddeDecodeGithubComKhliengDispatchServer25(in *jlexer.Lexer, out *ConnectionUpdate) {
func easyjson42239ddeDecodeGithubComKhliengDispatchServer26(in *jlexer.Lexer, out *ConnectionUpdate) {
isTopLevel := in.IsStart()
if in.IsNull() {
if isTopLevel {
@ -2848,7 +2943,7 @@ func easyjson42239ddeDecodeGithubComKhliengDispatchServer25(in *jlexer.Lexer, ou
in.Consumed()
}
}
func easyjson42239ddeEncodeGithubComKhliengDispatchServer25(out *jwriter.Writer, in ConnectionUpdate) {
func easyjson42239ddeEncodeGithubComKhliengDispatchServer26(out *jwriter.Writer, in ConnectionUpdate) {
out.RawByte('{')
first := true
_ = first
@ -2898,27 +2993,27 @@ func easyjson42239ddeEncodeGithubComKhliengDispatchServer25(out *jwriter.Writer,
// MarshalJSON supports json.Marshaler interface
func (v ConnectionUpdate) MarshalJSON() ([]byte, error) {
w := jwriter.Writer{}
easyjson42239ddeEncodeGithubComKhliengDispatchServer25(&w, v)
easyjson42239ddeEncodeGithubComKhliengDispatchServer26(&w, v)
return w.Buffer.BuildBytes(), w.Error
}
// MarshalEasyJSON supports easyjson.Marshaler interface
func (v ConnectionUpdate) MarshalEasyJSON(w *jwriter.Writer) {
easyjson42239ddeEncodeGithubComKhliengDispatchServer25(w, v)
easyjson42239ddeEncodeGithubComKhliengDispatchServer26(w, v)
}
// UnmarshalJSON supports json.Unmarshaler interface
func (v *ConnectionUpdate) UnmarshalJSON(data []byte) error {
r := jlexer.Lexer{Data: data}
easyjson42239ddeDecodeGithubComKhliengDispatchServer25(&r, v)
easyjson42239ddeDecodeGithubComKhliengDispatchServer26(&r, v)
return r.Error()
}
// UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (v *ConnectionUpdate) UnmarshalEasyJSON(l *jlexer.Lexer) {
easyjson42239ddeDecodeGithubComKhliengDispatchServer25(l, v)
easyjson42239ddeDecodeGithubComKhliengDispatchServer26(l, v)
}
func easyjson42239ddeDecodeGithubComKhliengDispatchServer26(in *jlexer.Lexer, out *ClientCert) {
func easyjson42239ddeDecodeGithubComKhliengDispatchServer27(in *jlexer.Lexer, out *ClientCert) {
isTopLevel := in.IsStart()
if in.IsNull() {
if isTopLevel {
@ -2951,7 +3046,7 @@ func easyjson42239ddeDecodeGithubComKhliengDispatchServer26(in *jlexer.Lexer, ou
in.Consumed()
}
}
func easyjson42239ddeEncodeGithubComKhliengDispatchServer26(out *jwriter.Writer, in ClientCert) {
func easyjson42239ddeEncodeGithubComKhliengDispatchServer27(out *jwriter.Writer, in ClientCert) {
out.RawByte('{')
first := true
_ = first
@ -2981,27 +3076,27 @@ func easyjson42239ddeEncodeGithubComKhliengDispatchServer26(out *jwriter.Writer,
// MarshalJSON supports json.Marshaler interface
func (v ClientCert) MarshalJSON() ([]byte, error) {
w := jwriter.Writer{}
easyjson42239ddeEncodeGithubComKhliengDispatchServer26(&w, v)
easyjson42239ddeEncodeGithubComKhliengDispatchServer27(&w, v)
return w.Buffer.BuildBytes(), w.Error
}
// MarshalEasyJSON supports easyjson.Marshaler interface
func (v ClientCert) MarshalEasyJSON(w *jwriter.Writer) {
easyjson42239ddeEncodeGithubComKhliengDispatchServer26(w, v)
easyjson42239ddeEncodeGithubComKhliengDispatchServer27(w, v)
}
// UnmarshalJSON supports json.Unmarshaler interface
func (v *ClientCert) UnmarshalJSON(data []byte) error {
r := jlexer.Lexer{Data: data}
easyjson42239ddeDecodeGithubComKhliengDispatchServer26(&r, v)
easyjson42239ddeDecodeGithubComKhliengDispatchServer27(&r, v)
return r.Error()
}
// UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (v *ClientCert) UnmarshalEasyJSON(l *jlexer.Lexer) {
easyjson42239ddeDecodeGithubComKhliengDispatchServer26(l, v)
easyjson42239ddeDecodeGithubComKhliengDispatchServer27(l, v)
}
func easyjson42239ddeDecodeGithubComKhliengDispatchServer27(in *jlexer.Lexer, out *ChannelSearchResult) {
func easyjson42239ddeDecodeGithubComKhliengDispatchServer28(in *jlexer.Lexer, out *ChannelSearchResult) {
isTopLevel := in.IsStart()
if in.IsNull() {
if isTopLevel {
@ -3063,7 +3158,7 @@ func easyjson42239ddeDecodeGithubComKhliengDispatchServer27(in *jlexer.Lexer, ou
in.Consumed()
}
}
func easyjson42239ddeEncodeGithubComKhliengDispatchServer27(out *jwriter.Writer, in ChannelSearchResult) {
func easyjson42239ddeEncodeGithubComKhliengDispatchServer28(out *jwriter.Writer, in ChannelSearchResult) {
out.RawByte('{')
first := true
_ = first
@ -3106,25 +3201,25 @@ func easyjson42239ddeEncodeGithubComKhliengDispatchServer27(out *jwriter.Writer,
// MarshalJSON supports json.Marshaler interface
func (v ChannelSearchResult) MarshalJSON() ([]byte, error) {
w := jwriter.Writer{}
easyjson42239ddeEncodeGithubComKhliengDispatchServer27(&w, v)
easyjson42239ddeEncodeGithubComKhliengDispatchServer28(&w, v)
return w.Buffer.BuildBytes(), w.Error
}
// MarshalEasyJSON supports easyjson.Marshaler interface
func (v ChannelSearchResult) MarshalEasyJSON(w *jwriter.Writer) {
easyjson42239ddeEncodeGithubComKhliengDispatchServer27(w, v)
easyjson42239ddeEncodeGithubComKhliengDispatchServer28(w, v)
}
// UnmarshalJSON supports json.Unmarshaler interface
func (v *ChannelSearchResult) UnmarshalJSON(data []byte) error {
r := jlexer.Lexer{Data: data}
easyjson42239ddeDecodeGithubComKhliengDispatchServer27(&r, v)
easyjson42239ddeDecodeGithubComKhliengDispatchServer28(&r, v)
return r.Error()
}
// UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (v *ChannelSearchResult) UnmarshalEasyJSON(l *jlexer.Lexer) {
easyjson42239ddeDecodeGithubComKhliengDispatchServer27(l, v)
easyjson42239ddeDecodeGithubComKhliengDispatchServer28(l, v)
}
func easyjson42239ddeDecodeGithubComKhliengDispatchStorage1(in *jlexer.Lexer, out *storage.ChannelListItem) {
isTopLevel := in.IsStart()
@ -3197,7 +3292,7 @@ func easyjson42239ddeEncodeGithubComKhliengDispatchStorage1(out *jwriter.Writer,
}
out.RawByte('}')
}
func easyjson42239ddeDecodeGithubComKhliengDispatchServer28(in *jlexer.Lexer, out *ChannelSearch) {
func easyjson42239ddeDecodeGithubComKhliengDispatchServer29(in *jlexer.Lexer, out *ChannelSearch) {
isTopLevel := in.IsStart()
if in.IsNull() {
if isTopLevel {
@ -3232,7 +3327,7 @@ func easyjson42239ddeDecodeGithubComKhliengDispatchServer28(in *jlexer.Lexer, ou
in.Consumed()
}
}
func easyjson42239ddeEncodeGithubComKhliengDispatchServer28(out *jwriter.Writer, in ChannelSearch) {
func easyjson42239ddeEncodeGithubComKhliengDispatchServer29(out *jwriter.Writer, in ChannelSearch) {
out.RawByte('{')
first := true
_ = first
@ -3272,27 +3367,122 @@ func easyjson42239ddeEncodeGithubComKhliengDispatchServer28(out *jwriter.Writer,
// MarshalJSON supports json.Marshaler interface
func (v ChannelSearch) MarshalJSON() ([]byte, error) {
w := jwriter.Writer{}
easyjson42239ddeEncodeGithubComKhliengDispatchServer28(&w, v)
easyjson42239ddeEncodeGithubComKhliengDispatchServer29(&w, v)
return w.Buffer.BuildBytes(), w.Error
}
// MarshalEasyJSON supports easyjson.Marshaler interface
func (v ChannelSearch) MarshalEasyJSON(w *jwriter.Writer) {
easyjson42239ddeEncodeGithubComKhliengDispatchServer28(w, v)
easyjson42239ddeEncodeGithubComKhliengDispatchServer29(w, v)
}
// UnmarshalJSON supports json.Unmarshaler interface
func (v *ChannelSearch) UnmarshalJSON(data []byte) error {
r := jlexer.Lexer{Data: data}
easyjson42239ddeDecodeGithubComKhliengDispatchServer28(&r, v)
easyjson42239ddeDecodeGithubComKhliengDispatchServer29(&r, v)
return r.Error()
}
// UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (v *ChannelSearch) UnmarshalEasyJSON(l *jlexer.Lexer) {
easyjson42239ddeDecodeGithubComKhliengDispatchServer28(l, v)
easyjson42239ddeDecodeGithubComKhliengDispatchServer29(l, v)
}
func easyjson42239ddeDecodeGithubComKhliengDispatchServer29(in *jlexer.Lexer, out *Away) {
func easyjson42239ddeDecodeGithubComKhliengDispatchServer30(in *jlexer.Lexer, out *ChannelForward) {
isTopLevel := in.IsStart()
if in.IsNull() {
if isTopLevel {
in.Consumed()
}
in.Skip()
return
}
in.Delim('{')
for !in.IsDelim('}') {
key := in.UnsafeString()
in.WantColon()
if in.IsNull() {
in.Skip()
in.WantComma()
continue
}
switch key {
case "server":
out.Server = string(in.String())
case "old":
out.Old = string(in.String())
case "new":
out.New = string(in.String())
default:
in.SkipRecursive()
}
in.WantComma()
}
in.Delim('}')
if isTopLevel {
in.Consumed()
}
}
func easyjson42239ddeEncodeGithubComKhliengDispatchServer30(out *jwriter.Writer, in ChannelForward) {
out.RawByte('{')
first := true
_ = first
if in.Server != "" {
const prefix string = ",\"server\":"
if first {
first = false
out.RawString(prefix[1:])
} else {
out.RawString(prefix)
}
out.String(string(in.Server))
}
if in.Old != "" {
const prefix string = ",\"old\":"
if first {
first = false
out.RawString(prefix[1:])
} else {
out.RawString(prefix)
}
out.String(string(in.Old))
}
if in.New != "" {
const prefix string = ",\"new\":"
if first {
first = false
out.RawString(prefix[1:])
} else {
out.RawString(prefix)
}
out.String(string(in.New))
}
out.RawByte('}')
}
// MarshalJSON supports json.Marshaler interface
func (v ChannelForward) MarshalJSON() ([]byte, error) {
w := jwriter.Writer{}
easyjson42239ddeEncodeGithubComKhliengDispatchServer30(&w, v)
return w.Buffer.BuildBytes(), w.Error
}
// MarshalEasyJSON supports easyjson.Marshaler interface
func (v ChannelForward) MarshalEasyJSON(w *jwriter.Writer) {
easyjson42239ddeEncodeGithubComKhliengDispatchServer30(w, v)
}
// UnmarshalJSON supports json.Unmarshaler interface
func (v *ChannelForward) UnmarshalJSON(data []byte) error {
r := jlexer.Lexer{Data: data}
easyjson42239ddeDecodeGithubComKhliengDispatchServer30(&r, v)
return r.Error()
}
// UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (v *ChannelForward) UnmarshalEasyJSON(l *jlexer.Lexer) {
easyjson42239ddeDecodeGithubComKhliengDispatchServer30(l, v)
}
func easyjson42239ddeDecodeGithubComKhliengDispatchServer31(in *jlexer.Lexer, out *Away) {
isTopLevel := in.IsStart()
if in.IsNull() {
if isTopLevel {
@ -3325,7 +3515,7 @@ func easyjson42239ddeDecodeGithubComKhliengDispatchServer29(in *jlexer.Lexer, ou
in.Consumed()
}
}
func easyjson42239ddeEncodeGithubComKhliengDispatchServer29(out *jwriter.Writer, in Away) {
func easyjson42239ddeEncodeGithubComKhliengDispatchServer31(out *jwriter.Writer, in Away) {
out.RawByte('{')
first := true
_ = first
@ -3355,23 +3545,23 @@ func easyjson42239ddeEncodeGithubComKhliengDispatchServer29(out *jwriter.Writer,
// MarshalJSON supports json.Marshaler interface
func (v Away) MarshalJSON() ([]byte, error) {
w := jwriter.Writer{}
easyjson42239ddeEncodeGithubComKhliengDispatchServer29(&w, v)
easyjson42239ddeEncodeGithubComKhliengDispatchServer31(&w, v)
return w.Buffer.BuildBytes(), w.Error
}
// MarshalEasyJSON supports easyjson.Marshaler interface
func (v Away) MarshalEasyJSON(w *jwriter.Writer) {
easyjson42239ddeEncodeGithubComKhliengDispatchServer29(w, v)
easyjson42239ddeEncodeGithubComKhliengDispatchServer31(w, v)
}
// UnmarshalJSON supports json.Unmarshaler interface
func (v *Away) UnmarshalJSON(data []byte) error {
r := jlexer.Lexer{Data: data}
easyjson42239ddeDecodeGithubComKhliengDispatchServer29(&r, v)
easyjson42239ddeDecodeGithubComKhliengDispatchServer31(&r, v)
return r.Error()
}
// UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (v *Away) UnmarshalEasyJSON(l *jlexer.Lexer) {
easyjson42239ddeDecodeGithubComKhliengDispatchServer29(l, v)
easyjson42239ddeDecodeGithubComKhliengDispatchServer31(l, v)
}

View File

@ -5,8 +5,6 @@ import (
"sync"
"time"
"fmt"
"github.com/khlieng/dispatch/pkg/irc"
"github.com/khlieng/dispatch/pkg/session"
"github.com/khlieng/dispatch/storage"
@ -132,13 +130,6 @@ func (s *State) sendJSON(t string, v interface{}) {
s.broadcast <- WSResponse{t, v}
}
func (s *State) sendError(err error, server string) {
s.sendJSON("error", Error{
Server: server,
Message: err.Error(),
})
}
func (s *State) sendLastMessages(server, channel string, count int) {
messages, hasMore, err := s.user.GetLastMessages(server, channel, count)
if err == nil && len(messages) > 0 {
@ -174,19 +165,6 @@ func (s *State) sendMessages(server, channel string, count int, fromID string) {
}
}
func (s *State) print(a ...interface{}) {
s.sendJSON("print", Message{
Content: fmt.Sprintln(a...),
})
}
func (s *State) printError(a ...interface{}) {
s.sendJSON("print", Message{
Content: fmt.Sprintln(a...),
Type: "error",
})
}
func (s *State) resetExpirationIfEmpty() {
if s.numIRC() == 0 && s.numWS() == 0 {
s.reset <- AnonymousUserExpiration