Skip to content

Commit

Permalink
update 2 2.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamling committed Feb 25, 2019
1 parent 7292d7b commit 463e00d
Show file tree
Hide file tree
Showing 29 changed files with 848 additions and 147 deletions.
Binary file modified lib/core-0.0.1.jar
Binary file not shown.
Binary file modified lib/smartqq-0.0.1.jar
Binary file not shown.
Binary file modified lib/wechat-0.0.1.jar
Binary file not shown.
1 change: 1 addition & 0 deletions resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
]]></description>

<change-notes><![CDATA[
v2.6.0 2019-02-26, 优化微信
v2.4.0 2018-05-10, 修复部分微信用户登录异常的问题
v2.3.2 2018-03-05, 优化链接自动识别,优化聊天记录
v2.3.0 2018-02-27, 添加发送工程中的文件,图灵机器人,消息群发等功能<br/>
Expand Down
34 changes: 17 additions & 17 deletions src/cn/ieclipse/smartim/IMHistoryManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,19 @@
*/
package cn.ieclipse.smartim;

import cn.ieclipse.smartim.helper.FileStorage;
import cn.ieclipse.smartim.settings.SmartIMSettings;

import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.ieclipse.util.FileStorage;
import cn.ieclipse.smartim.settings.SmartIMSettings;

/**
* 类/接口描述
*
*
* @author Jamling
* @date 2017年10月23日
*
*/
public class IMHistoryManager {
private Map<String, FileStorage> stores = new HashMap<>();
Expand All @@ -37,30 +36,31 @@ public class IMHistoryManager {
private long ts = System.currentTimeMillis();

private static IMHistoryManager instance = new IMHistoryManager();

public static final String HISTORY_NAME = "history";

public static IMHistoryManager getInstance() {
return instance;
}
private FileStorage get(SmartClient client, String uin) {

private FileStorage get(File dir, String uin) {
FileStorage fs = stores.get(uin);
if (fs == null) {
File f = new File(client.getWorkDir("history"), uin);
File f = new File(dir, uin);
fs = new FileStorage(size, f.getAbsolutePath());
boolean persistent = SmartIMSettings.getInstance().getState().LOG_HISTORY;
fs.setPersistent(persistent);
stores.put(uin, fs);
}
return fs;
}
public List<String> load(SmartClient client, String uin) {
FileStorage fs = get(client, uin);

public List<String> load(File dir, String uin) {
FileStorage fs = get(dir, uin);
return fs.getLast(max);
}
public boolean save(SmartClient client, String uin, String rawMsg) {
FileStorage fs = get(client, uin);

public boolean save(File dir, String uin, String rawMsg) {
FileStorage fs = get(dir, uin);
boolean ret = fs.append(rawMsg);
ret = ret && fs.isPersistent();
if (System.currentTimeMillis() - ts > 1000 * 120) {
Expand All @@ -70,8 +70,8 @@ public boolean save(SmartClient client, String uin, String rawMsg) {
return ret;
}

public boolean clear(SmartClient client, String uin) {
FileStorage fs = get(client, uin);
public boolean clear(File dir, String uin) {
FileStorage fs = get(dir, uin);
fs.release();
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/cn/ieclipse/smartim/IMReceiveCallback.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ protected void handle(boolean unknown, boolean notify,
String msg = getMsgContent(message, from);
if (!unknown) {
String hf = EncodeUtils.getMd5(from.getContact().getName());
IMHistoryManager.getInstance().save(client, hf, msg);
IMHistoryManager.getInstance().save(client.getWorkDir(IMHistoryManager.HISTORY_NAME), hf, msg);
}

if (notify) {
Expand Down
14 changes: 11 additions & 3 deletions src/cn/ieclipse/smartim/IMWindowFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,22 @@ public void stateChanged() {
}

private void createContents(@NotNull Project project, @NotNull ToolWindow toolWindow) {
SmartQQPanel qqPanel = new SmartQQPanel(project, toolWindow);
File dir = new File(getWorkDir(), "SmartIM");
if (dir.exists()) {
dir.mkdirs();
}
System.setProperty("log.home", dir.getAbsolutePath());
ContentFactory contentFactory = ContentFactory.SERVICE.getInstance();
Content content = contentFactory.createContent(qqPanel, "SmartQQ", false);
toolWindow.getContentManager().addContent(content, 0);
Content content = null;

WechatPanel wechatPanel = new WechatPanel(project, toolWindow);
content = contentFactory.createContent(wechatPanel, "Wechat", false);
toolWindow.getContentManager().addContent(content, 0);

SmartQQPanel qqPanel = new SmartQQPanel(project, toolWindow);
content = contentFactory.createContent(qqPanel, "SmartQQ", false);
toolWindow.getContentManager().addContent(content, 1);

}

private Content createContentPanel(Project project, ToolWindow toolWindow) {
Expand Down
12 changes: 11 additions & 1 deletion src/cn/ieclipse/smartim/actions/MockConsoleAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import cn.ieclipse.smartim.console.MockChatConsole;
import cn.ieclipse.smartim.model.impl.AbstractContact;
import cn.ieclipse.smartim.views.IMPanel;
import cn.ieclipse.wechat.WXChatConsoleMock;
import cn.ieclipse.wechat.WechatPanel;
import com.intellij.openapi.actionSystem.AnActionEvent;
import icons.SmartIcons;

Expand All @@ -29,8 +31,16 @@ public String getUin() {
}
};

MockChatConsole console = new MockChatConsole(contact, imPanel);
MockChatConsole console = null;
if (imPanel instanceof WechatPanel) {
console = new WXChatConsoleMock(contact, imPanel);
}
else {
console = new MockChatConsole(contact, imPanel);
}
console.setName(contact.getName());
imPanel.addConsole(console);
imPanel.randBling();
console.initMockMsg();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
/**
* Created by Jamling on 2017/7/11.
*/
public class SettingAction extends IMPanelAction {
public SettingAction(IMPanel panel) {
public class SettingsAction extends IMPanelAction {
public SettingsAction(IMPanel panel) {
super(panel, "设置", "首选项及设置", SmartIcons.settings);
this.imPanel = panel;
}
Expand Down
58 changes: 47 additions & 11 deletions src/cn/ieclipse/smartim/common/IMUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ public static String formatMsg(long time, String name, CharSequence msg) {
}

public static boolean isMySendMsg(String raw) {
return raw.matches("^\\d{2}:\\d{2}:\\d{2} [.\\s\\S]*")
|| raw.startsWith("<div");
return raw.startsWith("<div")
|| raw.matches("^\\d{2}:\\d{2}:\\d{2} [.\\s\\S]*");
}

public static String formatHtmlMsg(String msg, boolean encodeHtml) {
Expand Down Expand Up @@ -116,7 +116,7 @@ public static String formatHtmlMsg(boolean my, boolean encodeHtml,
return String.format(DIV_ROW_FORMAT, clz, t, name, name, content);
}

private static String autoReviewLink(String input) {
public static String autoReviewLink(String input) {
Matcher m = Pattern.compile(CODE_REGEX, Pattern.MULTILINE)
.matcher(input);
if (m.find()) {
Expand All @@ -133,7 +133,7 @@ private static String autoReviewLink(String input) {
return input;
}

private static String autoLink(String input) {
public static String autoLink(String input) {
Pattern p = Patterns.WEB_URL;// Pattern.compile(LINK_REGEX, Pattern.MULTILINE);
Matcher m = p.matcher(input);

Expand All @@ -153,7 +153,23 @@ private static String autoLink(String input) {
int e = ends.get(i);
String g = groups.get(i);
String http = null;
if (!g.matches(Patterns.PROTOCOL)) {

String ucs = "";
String rg = UCS_REGEX_BEGIN.matcher(g).replaceAll("$2");
if (g.length() > rg.length()) {
ucs = g.substring(0, g.length() - rg.length());
g = rg;
s = s + ucs.length();
}

rg = UCS_REGEX_END.matcher(g).replaceAll("$1");
if (g.length() > rg.length()) {
ucs = g.substring(rg.length());
g = rg;
e = e - ucs.length();
}

if (!PROTOCOL.matcher(g).find()) {
boolean f = g.startsWith("www.") || g.endsWith(".com")
|| g.endsWith(".cn");
if (!f) {
Expand All @@ -176,14 +192,19 @@ private static String autoLink(String input) {
continue;
}
}
sb.delete(pos, offset + e);
sb.delete(offset + s, offset + e);
String link = http == null ? g : http + g;
String ng = g;
if (IMG_EXTS.indexOf(FileUtils.getExtension(g).toLowerCase()) >= 0) {
ng = String.format("<a href=\"%s\"><img src=\"%s\" alt=\"%s\" border=\"0\"/></a>", g, g, g);
} else {
ng = String.format("<a href=\"%s\">%s</a>", g, g);
if (IMG_EXTS.indexOf(
FileUtils.getExtension(g).toLowerCase()) >= 0) {
ng = String.format(
"<a href=\"%s\"><img src=\"%s\" alt=\"%s\" border=\"0\"/></a>",
link, link, "无法预览,请尝试点击");
}
else {
ng = String.format("<a href=\"%s\">%s</a>", link, g);
}
sb.insert(pos, ng);
sb.insert(offset + s, ng);
offset += ng.length() - g.length();
}
return sb.toString();
Expand All @@ -198,4 +219,19 @@ private static String autoLink(String input) {
public static final List<String> IMG_EXTS = Arrays.asList("png", "jpg", "gif", "webp");
public static final String CODE_REGEX = "Code: [\\S ]+:[\\d]+ ?";
public static final String LINK_REGEX = "(https?|ftp|file)://(([\\w-~]+).)+([\\w-~\\/])+(((?!\\.)(\\S))+(\\.\\w+(\\?(\\w+=\\S&?)*)?)?)?";
public static final String UCS_CHAR = "[" + "\u00A0-\uD7FF"
+ "\uF900-\uFDCF" + "\uFDF0-\uFFEF" + "\uD800\uDC00-\uD83F\uDFFD"
+ "\uD840\uDC00-\uD87F\uDFFD" + "\uD880\uDC00-\uD8BF\uDFFD"
+ "\uD8C0\uDC00-\uD8FF\uDFFD" + "\uD900\uDC00-\uD93F\uDFFD"
+ "\uD940\uDC00-\uD97F\uDFFD" + "\uD980\uDC00-\uD9BF\uDFFD"
+ "\uD9C0\uDC00-\uD9FF\uDFFD" + "\uDA00\uDC00-\uDA3F\uDFFD"
+ "\uDA40\uDC00-\uDA7F\uDFFD" + "\uDA80\uDC00-\uDABF\uDFFD"
+ "\uDAC0\uDC00-\uDAFF\uDFFD" + "\uDB00\uDC00-\uDB3F\uDFFD"
+ "\uDB44\uDC00-\uDB7F\uDFFD"
+ "&&[^\u00A0[\u2000-\u200A]\u2028\u2029\u202F\u3000]]";
public static final Pattern UCS_REGEX_END = Pattern
.compile("(.+?)(" + UCS_CHAR + "+$)");
public static final Pattern UCS_REGEX_BEGIN = Pattern
.compile("^(" + UCS_CHAR + "+)" + "(.+?)");
public static final Pattern PROTOCOL = Pattern.compile(Patterns.PROTOCOL);
}
123 changes: 123 additions & 0 deletions src/cn/ieclipse/smartim/common/RestUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/*
* Copyright 2014-2018 ieclipse.cn.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.ieclipse.smartim.common;

import java.net.MalformedURLException;
import java.net.URL;

import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import javax.swing.text.html.StyleSheet;

import com.google.gson.Gson;

import com.intellij.ide.plugins.IdeaPluginDescriptor;
import com.intellij.ide.plugins.PluginManager;
import com.intellij.openapi.extensions.PluginId;
import okhttp3.Call;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

/**
* 类/接口描述
*
* @author Jamling
* @date 2019年1月16日
*
*/
public class RestUtils {
public final static String welcome_format = "http://api.ieclipse.cn/smartqq/index/welcome?p=%s&im=%s&v=%s";
public final static String update_url = "http://api.ieclipse.cn/smartqq/index/notice?p=intellij";
public final static String about_url = "http://api.ieclipse.cn/smartqq/index/about";

public static String getWelcome(String im) {
try {
final IdeaPluginDescriptor descriptor = PluginManager.getPlugin(PluginId.findId("cn.ieclipse.smartqq.intellij"));
Request.Builder builder = new Request.Builder()
.url(String.format(welcome_format, "intellij", im,
descriptor.getVersion()))
.get();
Request request = builder.build();
Call call = new OkHttpClient().newCall(request);
Response response = call.execute();
String json = response.body().string();
if (response.code() == 200) {
return json;
}
} catch (Exception e) {
}
return null;
}

public static void checkUpdate() {
new Thread() {
public void run() {
try {
Request.Builder builder = (new Request.Builder())
.url(RestUtils.update_url).get();
Request request = builder.build();
Call call = new OkHttpClient().newCall(request);
Response response = call.execute();
String json = response.body().string();
LOG.info(json);
if (response.code() == 200) {
final UpdateInfo info = new Gson().fromJson(json,
UpdateInfo.class);
final IdeaPluginDescriptor descriptor = PluginManager.getPlugin(PluginId.findId("cn.ieclipse.smartqq.intellij"));
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
if (descriptor != null && descriptor.getVersion().equals(info.latest)) {
JOptionPane.showMessageDialog(null, "已是最新版本");
return;
}
cn.ieclipse.smartim.common.Notifications.notify(info.latest, info.desc);
JOptionPane.showMessageDialog(null, "发现新版本" + info.latest + "请在File->Settings->Plugins插件页中更新SmartQQ");
};
});
}
} catch (Exception ex) {
LOG.error("检查SmartIM最新版本", ex);
}
};
}.start();
}

public static class UpdateInfo {
public String latest;
public String desc;
public String link;
}

public static void loadStyleAsync(final StyleSheet styleSheet) {
// new Thread() {
// @Override
// public void run() {
// loadStyleSync(styleSheet);
// }
// }.start();
}

public static void loadStyleSync(final StyleSheet styleSheet) {
try {
styleSheet.importStyleSheet(
new URL("http://dl.ieclipse.cn/r/smartim.css"));
} catch (MalformedURLException e1) {
e1.printStackTrace();
}
}
}
Loading

0 comments on commit 463e00d

Please sign in to comment.