Skip to content

Commit d47dc9c

Browse files
committed
增加图片处理
1 parent 04ed841 commit d47dc9c

32 files changed

+853
-174
lines changed

conf/nbs-conf.properties

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,7 @@ nbs.client.files.root=nbs
99
nbs.client.im.topic.subworld =disabled
1010
nbs.client.i18n.home=zh_cn
1111
nbs.server.address=/ip4/127.0.0.1/tcp/5001
12-
nbs.server.address.gateway-url=
12+
nbs.server.address.gateway-url=http://127.0.0.1:8080
13+
nbs.server.address.host=127.0.0.1
14+
nbs.server.address.api-port=5001
15+
nbs.server.address.gateway-port=8080

conf/nbs.db

0 Bytes
Binary file not shown.

pom.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,11 @@
7575
<artifactId>emoji-java</artifactId>
7676
<version>4.0.0</version>
7777
</dependency>
78-
78+
<dependency>
79+
<groupId>nine-patch</groupId>
80+
<artifactId>android.nine.patch</artifactId>
81+
<version>1.0</version>
82+
</dependency>
7983

8084
</dependencies>
8185

src/main/java/UI/AppMainWindow.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ public void run() {
349349
TimeUnit.SECONDS.sleep(30);
350350
broadcastOnline();
351351
}else {
352-
String ctrlMsg = Base64CodecUtil.encodeCtrlMsg(SEFL_BASE,Base64CodecUtil.CtrlTypes.online);
352+
String ctrlMsg = Base64CodecUtil.encode(JSON.toJSONString(SEFL_BASE));
353353
Object o = ipfs.pubsub.pub(IPFSHelper.NBSWORLD_IMS_TOPIC,ctrlMsg);
354354
logger.info("TOPIC["+IPFSHelper.NBSWORLD_IMS_TOPIC+" ]Send CTRL MSG : "+ctrlMsg);
355355
boradcastSuccess = true;

src/main/java/UI/common/Base64CodecUtil.java

Lines changed: 3 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
public class Base64CodecUtil {
2323
private static final Base64 base64 = new Base64();
2424

25-
public static final String BASE64_START = "$BASE64$";
26-
public static final String BASE64_END = "$";
2725
/**
2826
*
2927
* @param origin
@@ -58,74 +56,13 @@ public static String decode(String baseStr){
5856

5957

6058

61-
62-
public static boolean isBase64encode(String base64Str){
63-
return base64Str.startsWith(BASE64_START)&&base64Str.endsWith(BASE64_END);
64-
}
65-
66-
67-
68-
/**
69-
* IPFS 消息解码
70-
* @param encodeStr
71-
* @return
72-
*/
73-
public static String decodeIPFSMsg(String encodeStr){
74-
if(isBase64encode(encodeStr)){
75-
int len = encodeStr.length();
76-
encodeStr = encodeStr.substring(BASE64_START.length(),len-1);
77-
return decode(encodeStr);
78-
}else {
79-
return encodeStr;
80-
}
81-
}
82-
83-
/**
84-
*
85-
* @param message
86-
* @return
87-
* @throws IllegalIPFSMessageException
88-
*/
89-
public PeerBoradcastInfo parseFromIm(IpfsMessage message) throws IllegalIPFSMessageException {
90-
if(message==null
91-
||message.getTypes()!=CtrlTypes.online
92-
||(StringUtils.isBlank(message.getContents())&&StringUtils.isBlank(message.getData())))
93-
return null;
94-
if(StringUtils.isBlank(message.getContents())){
95-
String jsonData = decode(message.getData());
96-
if(!jsonData.startsWith(CtrlTypes.online.getPreffix())||!jsonData.endsWith(CtrlTypes.online.sperator)){
97-
throw new IllegalIPFSMessageException("message data not online type message");
98-
}
99-
int len = jsonData.length();
100-
message.setContents(jsonData.substring(CtrlTypes.online.getPreffixLength(),len-1));
101-
}
102-
PeerBoradcastInfo res = JSON.parseObject(message.getContents(),PeerBoradcastInfo.class);
103-
return res;
104-
}
105-
106-
/**
107-
* 编码控制消息
108-
* @param o
109-
* @param type
110-
* @return
111-
*/
112-
public static String encodeCtrlMsg(Object o,CtrlTypes type){
113-
if(o==null)return null;
114-
if(type==null)type=CtrlTypes.online;
115-
StringBuffer mSb = new StringBuffer();
116-
mSb.append(type.sperator).append(type.starter).append(type.sperator);
117-
String json = JSON.toJSONString(o);
118-
mSb.append(encode(json));
119-
mSb.append(type.sperator);
120-
return mSb.toString();
121-
}
122-
12359
/**
12460
*
12561
* @param message
12662
* @param types
12763
* @return
12864
*/
65+
@Deprecated
12966
public static String encodeByCtrlType(Object message,CtrlTypes types){
13067
if(message==null)return null;
13168
StringBuffer sb = new StringBuffer();
@@ -154,6 +91,7 @@ public static String encodeByCtrlType(Object message,CtrlTypes types){
15491
* @param m
15592
* @return
15693
*/
94+
@Deprecated
15795
public static IpfsMessage parseIpmsMessageCtrlType(IpfsMessage m){
15896
if(m==null||m.getData()==null||m.getData().length()<1)return null;
15997
String decode64 = decode(m.getData());
@@ -179,25 +117,9 @@ public static IpfsMessage parseIpmsMessageCtrlType(IpfsMessage m){
179117
}
180118

181119

182-
/**
183-
*
184-
* @param baseStr
185-
* @param type
186-
* @return
187-
*/
188-
public static String decodeCtrlMsg(String baseStr,CtrlTypes type){
189-
if(baseStr==null)return null;
190-
if(type==null)type=CtrlTypes.online;
191-
if(baseStr.startsWith(type.sperator+type.starter+type.sperator)&&baseStr.endsWith(type.sperator+"")){
192-
int len = baseStr.length();
193-
baseStr = baseStr.substring(type.starter.length()+2,len-1);
194-
return decode(baseStr);
195-
}else {
196-
return decode(baseStr);
197-
}
198-
}
199120

200121

122+
@Deprecated
201123
public static enum CtrlTypes{
202124
/**
203125
* $ON.B64.J$xxxxxsssds$
@@ -263,24 +185,4 @@ public String toString() {
263185
}
264186
}
265187

266-
public static void main(String[] args) {
267-
String in = "你好NBS 的圣诞 xccxv 节收到 \\n slfsak阿卡恢复大师的/n";
268-
System.out.println(in);
269-
String encodeIn = encode(in);
270-
System.out.println(encodeIn);
271-
String enMsg = "$BASE64|"+encodeIn+"|";
272-
System.out.println(enMsg);
273-
String dec = decodeIPFSMsg(enMsg);
274-
System.out.println(dec);
275-
String h = "Hello!";
276-
String res = "";
277-
res = Base64CodecUtil.encode(h);
278-
System.out.println(res);
279-
280-
281-
Multihash multihash = Multihash.fromHex("EiBCOcWflebcLfrIFDlcWTMFG+2sQ6dGv2BKlop/JjrRmA==");
282-
283-
System.out.println(Base64CodecUtil.decode("EiBCOcWflebcLfrIFDlcWTMFG+2sQ6dGv2BKlop/JjrRmA=="));
284-
285-
}
286188
}

src/main/java/com/nbs/biz/service/PeerLoginService.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import com.nbs.biz.data.dao.PeerLoginDao;
44
import com.nbs.biz.data.entity.PeerLoginEntity;
5+
import io.nbs.commons.helper.DateHelper;
6+
import io.nbs.sdk.beans.PeerInfo;
57
import org.apache.ibatis.session.SqlSession;
68

79
/**
@@ -30,4 +32,28 @@ public int updateOrInsertPeer(PeerLoginEntity entity){
3032
return dao.insert(entity);
3133
}
3234
}
35+
36+
/**
37+
*
38+
* @param info
39+
* @return
40+
*/
41+
public int refreshLoginInfo(PeerInfo info){
42+
if(info==null)return 0;
43+
PeerLoginEntity entity = convertFromPeerInfo(info);
44+
return updateOrInsertPeer(entity);
45+
}
46+
47+
public static PeerLoginEntity convertFromPeerInfo(PeerInfo info){
48+
PeerLoginEntity entity = new PeerLoginEntity();
49+
entity.setId(info.getId());
50+
entity.setNick(info.getNick());
51+
entity.setAvatar(info.getAvatar());
52+
entity.setAvatarSuffix(info.getAvatarSuffix());
53+
entity.setIp(info.getIp());
54+
entity.setFromid(info.getFrom());
55+
entity.setSysuser(System.getProperty("user.name",""));
56+
entity.setLmtime(DateHelper.currentSecond());
57+
return entity;
58+
}
3359
}

src/main/java/com/nbs/tools/ConfigHelper.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*/
2222
public class ConfigHelper {
2323
private static final Logger logger = LoggerFactory.getLogger(ConfigHelper.class);
24-
private int stats = 0;
24+
private static int stats = 0;
2525
/**
2626
* 系统当前路径
2727
*/
@@ -135,8 +135,27 @@ private static class ConfigHolder {
135135
public static ConfigHelper instance = new ConfigHelper();
136136
}
137137

138+
/**
139+
*
140+
* @return
141+
*/
138142
public static ConfigHelper getInstance(){
139-
return ConfigHolder.instance;
143+
ConfigHelper instance = ConfigHolder.instance;
144+
switch (stats){
145+
case 1:
146+
instance.initLoadI18n();
147+
break;
148+
case 2:
149+
instance.initLoadEnv();
150+
break;
151+
default:
152+
instance.initLoadI18n();
153+
instance.initLoadEnv();
154+
break;
155+
156+
}
157+
158+
return instance;
140159
}
141160

142161
/**
@@ -301,4 +320,6 @@ public String getI18nProperty(String key){
301320
public String getI18nProperty(String key,String defaultVal){
302321
return i18nProps.getProperty(key,defaultVal);
303322
}
323+
324+
304325
}

src/main/java/com/nbs/ui/components/NBSAttachmentMessageBubble.java renamed to src/main/java/com/nbs/ui/components/IMAttachmentMessageBubble.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.nbs.ui.components;
22

3+
import io.nbs.client.ui.components.message.IMMessageBubble;
4+
35
import javax.swing.*;
46
import java.awt.*;
57
import java.awt.event.MouseAdapter;
@@ -14,12 +16,12 @@
1416
* Copyright (c) 2018, NBS , lambor.c<[email protected]>.
1517
* All rights reserved.
1618
*/
17-
public class NBSAttachmentMessageBubble extends JPanel implements NBSMessageBubble {
19+
public class IMAttachmentMessageBubble extends JPanel implements IMMessageBubble {
1820

1921
private NBS9PathImageIcon normal;
2022
private NBS9PathImageIcon active;
2123

22-
public NBSAttachmentMessageBubble() {
24+
public IMAttachmentMessageBubble() {
2325
setOpaque(false);
2426
setListener();
2527
}
@@ -71,7 +73,7 @@ public void setActiveStatus(boolean status)
7173
setBackgroundIcon(normal);
7274
}
7375

74-
NBSAttachmentMessageBubble.this.repaint();
76+
IMAttachmentMessageBubble.this.repaint();
7577
}
7678

7779
@Override

src/main/java/com/nbs/ui/components/messages/NBSLeftImageMessageBubble.java renamed to src/main/java/com/nbs/ui/components/messages/IMLeftImageMessageBubble.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.nbs.ui.components.messages;
22

33
import com.nbs.ui.components.NBS9PathImageIcon;
4-
import com.nbs.ui.components.NBSAttachmentMessageBubble;
4+
import com.nbs.ui.components.IMAttachmentMessageBubble;
55

66
import java.awt.*;
77

@@ -13,9 +13,9 @@
1313
* Copyright (c) 2018, NBS , lambor.c<[email protected]>.
1414
* All rights reserved.
1515
*/
16-
public class NBSLeftImageMessageBubble extends NBSAttachmentMessageBubble {
16+
public class IMLeftImageMessageBubble extends IMAttachmentMessageBubble {
1717

18-
public NBSLeftImageMessageBubble() {
18+
public IMLeftImageMessageBubble() {
1919
NBS9PathImageIcon normal = new NBS9PathImageIcon(this.getClass().getResource("/icon/nbs64.png"));
2020
NBS9PathImageIcon active = new NBS9PathImageIcon(this.getClass().getResource("/icon/nbs64.png"));
2121
setBackgroundIcon(normal);

src/main/java/com/nbs/ui/components/messages/NBSRightImageMessageBubble.java renamed to src/main/java/com/nbs/ui/components/messages/IMRightImageMessageBubble.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
package com.nbs.ui.components.messages;
22

3-
import UI.AppMainWindow;
43
import com.nbs.ui.components.NBS9PathImageIcon;
5-
import com.nbs.ui.components.NBSAttachmentMessageBubble;
4+
import com.nbs.ui.components.IMAttachmentMessageBubble;
65

76
import java.awt.*;
87

@@ -14,8 +13,8 @@
1413
* Copyright (c) 2018, NBS , lambor.c<[email protected]>.
1514
* All rights reserved.
1615
*/
17-
public class NBSRightImageMessageBubble extends NBSAttachmentMessageBubble {
18-
public NBSRightImageMessageBubble(){
16+
public class IMRightImageMessageBubble extends IMAttachmentMessageBubble {
17+
public IMRightImageMessageBubble(){
1918
NBS9PathImageIcon normal = new NBS9PathImageIcon(this.getClass().getResource("/icon/nbs64.png"));
2019
NBS9PathImageIcon active = new NBS9PathImageIcon(this.getClass().getResource("/icon/nbs64.png"));
2120

0 commit comments

Comments
 (0)