Skip to content

Commit

Permalink
update 2 3.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamling committed Feb 25, 2019
1 parent 2be85d5 commit 38ab6da
Show file tree
Hide file tree
Showing 27 changed files with 492 additions and 149 deletions.
2 changes: 1 addition & 1 deletion cn.ieclipse.smartqq.feature/feature.xml
Expand Up @@ -2,7 +2,7 @@
<feature
id="cn.ieclipse.smartqq.feature"
label="SmartQQ"
version="3.2.0.qualifier"
version="3.3.0.qualifier"
provider-name="ieclipse.cn"
plugin="cn.ieclipse.smartqq">

Expand Down
2 changes: 1 addition & 1 deletion cn.ieclipse.smartqq/META-INF/MANIFEST.MF
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: SmartQQ
Bundle-SymbolicName: cn.ieclipse.smartqq;singleton:=true
Bundle-Version: 3.2.0.qualifier
Bundle-Version: 3.3.0.qualifier
Bundle-Activator: cn.ieclipse.smartim.IMPlugin
Bundle-Vendor: ieclipse.cn
Require-Bundle: org.eclipse.ui,
Expand Down
Binary file modified cn.ieclipse.smartqq/libs/core-0.0.1.jar
Binary file not shown.
Binary file modified cn.ieclipse.smartqq/libs/smartqq-0.0.1.jar
Binary file not shown.
Binary file modified cn.ieclipse.smartqq/libs/wechat-0.0.1.jar
Binary file not shown.
19 changes: 10 additions & 9 deletions cn.ieclipse.smartqq/src/cn/ieclipse/smartim/IMHistoryManager.java
Expand Up @@ -20,7 +20,7 @@
import java.util.List;
import java.util.Map;

import cn.ieclipse.smartim.helper.FileStorage;
import cn.ieclipse.util.FileStorage;
import cn.ieclipse.smartim.preferences.SettingsPerferencePage;

/**
Expand All @@ -37,15 +37,16 @@ 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 = IMPlugin.getDefault().getPreferenceStore()
.getBoolean(SettingsPerferencePage.LOG_HISTORY);
Expand All @@ -55,13 +56,13 @@ private FileStorage get(SmartClient client, String uin) {
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 @@ -71,8 +72,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
Expand Up @@ -30,8 +30,8 @@ protected void handle(boolean unknown, boolean notify,
SmartClient client = fContactView.getClient();
String msg = getMsgContent(message, from);
if (!unknown) {
IMHistoryManager.getInstance().save(client,
EncodeUtils.getMd5(contact.getName()), msg);
String hf = EncodeUtils.getMd5(from.getContact().getName());
IMHistoryManager.getInstance().save(client.getWorkDir(IMHistoryManager.HISTORY_NAME), hf, msg);
}

if (notify) {
Expand Down
Expand Up @@ -20,6 +20,9 @@
import cn.ieclipse.smartim.common.IMUtils;
import cn.ieclipse.smartim.console.MockChatConsole;
import cn.ieclipse.smartim.views.IMContactView;
import cn.ieclipse.wechat.WXChatConsole;
import cn.ieclipse.wechat.WXChatConsoleMock;
import cn.ieclipse.wechat.WXContactView;
import icons.SmartIcons;

/**
Expand All @@ -43,11 +46,14 @@ public void run() {
Friend f = new Friend();
f.setUserId(System.currentTimeMillis());
f.setMarkname("Test" + System.currentTimeMillis());
MockChatConsole console = new MockChatConsole(f, fContactView);
MockChatConsole console = null;
if (fContactView instanceof WXContactView) {
console = new WXChatConsoleMock(f, fContactView);
} else {
console =new MockChatConsole(f, fContactView);
}
console.initMockMsg();
fContactView.getTabbedChat().setSelection(console);
fContactView.randBling();
String msg = IMUtils.formatHtmlMsg(System.currentTimeMillis(), "明月",
"我的未来不是梦http://www.baidu.com咕咕");
console.write(msg);
}
}
Expand Up @@ -34,8 +34,8 @@
* @date 2017年6月20日
*
*/
public class SettingAction extends IMPanelAction {
public SettingAction(IMContactView contactView) {
public class SettingsAction extends IMPanelAction {
public SettingsAction(IMContactView contactView) {
super(contactView);
setText("Settings");
setToolTipText("Settings & Helps");
Expand Down
56 changes: 37 additions & 19 deletions cn.ieclipse.smartqq/src/cn/ieclipse/smartim/common/IMUtils.java
Expand Up @@ -84,15 +84,21 @@ 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) {
// TODO only replace the non-html tag space;
String m = encodeHtml(msg);
m = m.replaceAll("\r?\n", "<br/>");
String content = encodeHtml ? autoLink(autoReviewLink(m)) : m;
String content;
if (encodeHtml) {
content = autoLink(autoReviewLink(m).replace(" ", "&nbsp;"));
}
else {
content = m.replace(" ", "&nbsp;");
}
return content;
}

Expand All @@ -114,7 +120,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 @@ -131,9 +137,9 @@ private static String autoReviewLink(String input) {
return input;
}

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

List<String> groups = new ArrayList<>();
Expand All @@ -152,7 +158,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,26 +198,19 @@ else if (c == '>') {
continue;
}
}
String rg = UCS_REGEX.matcher(g).replaceAll("$1");
String ucs = "";
if (g.length() > rg.length()) {
ucs = g.substring(rg.length());
g = rg;
e = e - ucs.length();
}
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>",
link, link, g);
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 @@ -221,8 +236,11 @@ else if (c == '>') {
+ "\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 = Pattern
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);
public static final Pattern HTML_TAG_REGEX = Pattern
.compile("<[^>]+>", Pattern.MULTILINE);
}
Expand Up @@ -21,7 +21,7 @@
import org.eclipse.wb.swt.SWTResourceManager;

import cn.ieclipse.smartim.IMPlugin;
import cn.ieclipse.smartim.actions.SettingAction;
import cn.ieclipse.smartim.actions.SettingsAction;
import cn.ieclipse.smartim.model.IContact;
import cn.ieclipse.smartim.preferences.SettingsPerferencePage;
import cn.ieclipse.smartim.views.IMContactView;
Expand Down Expand Up @@ -134,7 +134,7 @@ public void mouseDown(MouseEvent e) {
fSettings.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
SettingAction.open(SettingsPerferencePage.class.getName());
SettingsAction.open(SettingsPerferencePage.class.getName());
}
});

Expand Down
110 changes: 110 additions & 0 deletions cn.ieclipse.smartqq/src/cn/ieclipse/smartim/common/RestUtils.java
@@ -0,0 +1,110 @@
/*
* 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 org.eclipse.core.runtime.Platform;

import com.google.gson.Gson;

import cn.ieclipse.smartim.IMPlugin;
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=eclipse";
public final static String about_url = "http://api.ieclipse.cn/smartqq/index/about";


public static String getWelcome(String im) {
try {
okhttp3.Request.Builder builder = new okhttp3.Request.Builder()
.url(String.format(welcome_format, "eclipse", im,
Platform.getBundle(IMPlugin.PLUGIN_ID).getVersion().toString()))
.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 {
okhttp3.Request.Builder builder = (new okhttp3.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();
if (response.code() == 200) {
final UpdateInfo info = new Gson().fromJson(json,
UpdateInfo.class);

}
} catch (Exception 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();
}
}
}

0 comments on commit 38ab6da

Please sign in to comment.