Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit613d9fc

Browse files
committed
Send irc features to the client
1 parent9267c66 commit613d9fc

File tree

20 files changed

+683
-297
lines changed

20 files changed

+683
-297
lines changed

‎assets/bindata.go‎

Lines changed: 97 additions & 97 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎client/js/commands.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ export default createCommandMiddleware(COMMAND, {
7979
topic({ dispatch, getState, server, channel}, ...newTopic){
8080
if(newTopic.length>0){
8181
dispatch(setTopic(newTopic.join(' '),channel,server));
82+
return;
8283
}elseif(channel){
8384
const{ topic}=getState().channels[server][channel];
8485
if(topic){

‎client/js/components/TabList.js‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
importReact,{PureComponent}from'react';
22
importclassnamesfrom'classnames';
3+
importgetfrom'lodash/get';
34
importButtonfrom'components/ui/Button';
45
importTabListItemfrom'containers/TabListItem';
56

@@ -39,13 +40,22 @@ export default class TabList extends PureComponent {
3940
/>
4041
);
4142

43+
letchanLabel;
44+
constchanLimit=
45+
get(srv.features,['CHANLIMIT','#'],0)||srv.features.MAXCHANNELS;
46+
if(chanLimit>0){
47+
chanLabel=`CHANNELS (${server.channels.length}/${chanLimit})`;
48+
}else{
49+
chanLabel=`CHANNELS (${server.channels.length})`;
50+
}
51+
4252
tabs.push(
4353
<div
4454
key={`${address}-chans}`}
4555
className="tab-label"
4656
onClick={()=>openModal('channel',{server:address})}
4757
>
48-
<span>CHANNELS ({server.channels.length})</span>
58+
<span>{chanLabel}</span>
4959
<Button>+</Button>
5060
</div>
5161
);

‎client/js/state/__tests__/reducer-servers.test.js‎

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ describe('server reducer', () => {
1616
status:{
1717
connected:false,
1818
error:null
19-
}
19+
},
20+
features:{}
2021
}
2122
});
2223

@@ -30,7 +31,8 @@ describe('server reducer', () => {
3031
status:{
3132
connected:false,
3233
error:null
33-
}
34+
},
35+
features:{}
3436
}
3537
});
3638

@@ -47,7 +49,8 @@ describe('server reducer', () => {
4749
status:{
4850
connected:false,
4951
error:null
50-
}
52+
},
53+
features:{}
5154
},
5255
'127.0.0.2':{
5356
name:'srv',
@@ -56,7 +59,8 @@ describe('server reducer', () => {
5659
status:{
5760
connected:false,
5861
error:null
59-
}
62+
},
63+
features:{}
6064
}
6165
});
6266
});
@@ -216,15 +220,17 @@ describe('server reducer', () => {
216220
editedNick:null,
217221
status:{
218222
connected:true
219-
}
223+
},
224+
features:{}
220225
},
221226
'127.0.0.2':{
222227
name:'stuffz',
223228
nick:'nick2',
224229
editedNick:null,
225230
status:{
226231
connected:false
227-
}
232+
},
233+
features:{}
228234
}
229235
});
230236
});
@@ -247,7 +253,8 @@ describe('server reducer', () => {
247253
editedNick:null,
248254
status:{
249255
connected:true
250-
}
256+
},
257+
features:{}
251258
}
252259
});
253260

@@ -266,7 +273,8 @@ describe('server reducer', () => {
266273
status:{
267274
connected:false,
268275
error:'Bad stuff happened'
269-
}
276+
},
277+
features:{}
270278
}
271279
});
272280
});

‎client/js/state/actions.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ export const socket = createSocketActions([
7070
'channel_search',
7171
'connection_update',
7272
'error',
73+
'features',
7374
'join',
7475
'message',
7576
'mode',

‎client/js/state/servers.js‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ export default createReducer(
4545
status:{
4646
connected:false,
4747
error:null
48-
}
48+
},
49+
features:{}
4950
};
5051
}
5152
},
@@ -79,8 +80,8 @@ export default createReducer(
7980

8081
[actions.socket.SERVERS](state,{ data}){
8182
if(data){
82-
data.forEach(({ host, name, nick, status})=>{
83-
state[host]={ name, nick, status,editedNick:null};
83+
data.forEach(({ host, name=host, nick, status, features={}})=>{
84+
state[host]={ name, nick, status,features,editedNick:null};
8485
});
8586
}
8687
},
@@ -90,6 +91,17 @@ export default createReducer(
9091
state[server].status.connected=connected;
9192
state[server].status.error=error;
9293
}
94+
},
95+
96+
[actions.socket.FEATURES](state,{ server, features}){
97+
constsrv=state[server];
98+
if(srv){
99+
srv.features=features;
100+
101+
if(features.NETWORK&&srv.name===server){
102+
srv.name=features.NETWORK;
103+
}
104+
}
93105
}
94106
}
95107
);

‎pkg/irc/case.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ const (
1414
)
1515

1616
func (c*Client)Casefold(sstring)string {
17-
mapping:=c.Support.Get("CASEMAPPING")
17+
mapping:=c.Features.String("CASEMAPPING")
1818
ifmapping=="" {
1919
mapping=RFC1459
2020
}
2121
returnCasefold(mapping,s)
2222
}
2323

2424
func (c*Client)EqualFold(s1,s2string)bool {
25-
mapping:=c.Support.Get("CASEMAPPING")
25+
mapping:=c.Features.String("CASEMAPPING")
2626
ifmapping=="" {
2727
mapping=RFC1459
2828
}

‎pkg/irc/client.go‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,20 @@ import (
1111
)
1212

1313
typeClientstruct {
14-
Serverstring
15-
Hoststring
16-
TLSbool
17-
TLSConfig*tls.Config
18-
Passwordstring
19-
Usernamestring
20-
Realnamestring
14+
Serverstring
15+
Hoststring
16+
TLSbool
17+
TLSConfig*tls.Config
18+
Passwordstring
19+
Usernamestring
20+
Realnamestring
21+
HandleNickInUsefunc(string)string
22+
2123
Messageschan*Message
2224
ConnectionChangedchanConnectionState
23-
HandleNickInUsefunc(string)string
24-
25-
nickstring
26-
channels []string
27-
Support*iSupport
25+
Features*Features
26+
nickstring
27+
channels []string
2828

2929
conn net.Conn
3030
connectedbool
@@ -44,7 +44,7 @@ type Client struct {
4444
funcNewClient(nick,usernamestring)*Client {
4545
return&Client{
4646
nick:nick,
47-
Support:newISupport(),
47+
Features:NewFeatures(),
4848
Username:username,
4949
Realname:nick,
5050
Messages:make(chan*Message,32),

‎pkg/irc/conn.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ func (c *Client) recv() {
232232
goc.send()
233233

234234
caseReplyISupport:
235-
c.Support.parse(msg.Params)
235+
c.Features.Parse(msg.Params)
236236

237237
caseErrNicknameInUse:
238238
ifc.HandleNickInUse!=nil {

‎pkg/irc/feature.go‎

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
package irc
2+
3+
import (
4+
"strconv"
5+
"strings"
6+
"sync"
7+
)
8+
9+
typeFeaturesstruct {
10+
mmap[string]interface{}
11+
lock sync.Mutex
12+
}
13+
14+
funcNewFeatures()*Features {
15+
return&Features{
16+
m:map[string]interface{}{},
17+
}
18+
}
19+
20+
func (f*Features)Map()map[string]interface{} {
21+
m:=map[string]interface{}{}
22+
f.lock.Lock()
23+
fork,v:=rangef.m {
24+
m[k]=v
25+
}
26+
f.lock.Unlock()
27+
returnm
28+
}
29+
30+
func (f*Features)Parse(params []string) {
31+
f.lock.Lock()
32+
for_,param:=rangeparams[1 :len(params)-1] {
33+
key,val:=splitParam(param)
34+
ifkey=="" {
35+
continue
36+
}
37+
38+
ifkey[0]=='-' {
39+
delete(f.m,key[1:])
40+
}else {
41+
ift,ok:=featureTransforms[key];ok {
42+
f.m[key]=t(val)
43+
}else {
44+
f.m[key]=val
45+
}
46+
}
47+
}
48+
49+
f.lock.Unlock()
50+
}
51+
52+
func (f*Features)Has(keystring)bool {
53+
f.lock.Lock()
54+
_,has:=f.m[key]
55+
f.lock.Unlock()
56+
returnhas
57+
}
58+
59+
func (f*Features)Get(keystring)interface{} {
60+
f.lock.Lock()
61+
v:=f.m[key]
62+
f.lock.Unlock()
63+
returnv
64+
}
65+
66+
func (f*Features)String(keystring)string {
67+
ifv,ok:=f.Get(key).(string);ok {
68+
returnv
69+
}
70+
return""
71+
}
72+
73+
func (f*Features)Int(keystring)int {
74+
ifv,ok:=f.Get(key).(int);ok {
75+
returnv
76+
}
77+
return0
78+
}
79+
80+
typefeatureTransformfunc(interface{})interface{}
81+
82+
functoInt(vinterface{})interface{} {
83+
s:=v.(string)
84+
ifs=="" {
85+
return0
86+
}
87+
88+
i,_:=strconv.Atoi(s)
89+
returni
90+
}
91+
92+
functoCharList(vinterface{})interface{} {
93+
s:=v.(string)
94+
list:=make([]string,len(s))
95+
fori:=ranges {
96+
list[i]=s[i :i+1]
97+
}
98+
returnlist
99+
}
100+
101+
funcparseChanlimit(vinterface{})interface{} {
102+
limits:=map[string]int{}
103+
104+
pairs:=strings.Split(v.(string),",")
105+
for_,p:=rangepairs {
106+
pair:=strings.Split(p,":")
107+
108+
iflen(pair)==2 {
109+
prefixes:=pair[0]
110+
limit,_:=strconv.Atoi(pair[1])
111+
112+
fori:=rangeprefixes {
113+
limits[prefixes[i:i+1]]=limit
114+
}
115+
}
116+
}
117+
118+
returnlimits
119+
}
120+
121+
varfeatureTransforms=map[string]featureTransform{
122+
"AWAYLEN":toInt,
123+
"CHANLIMIT":parseChanlimit,
124+
"CHANNELLEN":toInt,
125+
"CHANTYPES":toCharList,
126+
"HOSTLEN":toInt,
127+
"KICKLEN":toInt,
128+
"MAXCHANNELS":toInt,
129+
"MAXTARGETS":toInt,
130+
"MODES":toInt,
131+
"NICKLEN":toInt,
132+
"TOPICLEN":toInt,
133+
"USERLEN":toInt,
134+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp