Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
220e010193 | ||
|
|
865888824c | ||
|
|
583df110fd | ||
|
|
f204bd693e | ||
|
|
b6be1ca045 | ||
|
|
beb403a9f7 | ||
|
|
00f1187200 |
+1
-1
@@ -5,7 +5,7 @@
|
|||||||
<relativePath>../</relativePath>
|
<relativePath>../</relativePath>
|
||||||
<artifactId>wildfirechat-parent</artifactId>
|
<artifactId>wildfirechat-parent</artifactId>
|
||||||
<groupId>cn.wildfirechat</groupId>
|
<groupId>cn.wildfirechat</groupId>
|
||||||
<version>0.34</version>
|
<version>0.35</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>moquette-broker</artifactId>
|
<artifactId>moquette-broker</artifactId>
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import java.util.List;
|
|||||||
public class UserSearchHandler extends IMHandler<WFCMessage.SearchUserRequest> {
|
public class UserSearchHandler extends IMHandler<WFCMessage.SearchUserRequest> {
|
||||||
@Override
|
@Override
|
||||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, boolean isAdmin, WFCMessage.SearchUserRequest request, Qos1PublishHandler.IMCallback callback) {
|
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, boolean isAdmin, WFCMessage.SearchUserRequest request, Qos1PublishHandler.IMCallback callback) {
|
||||||
List<WFCMessage.User> users = m_messagesStore.searchUser(request.getKeyword(), request.getFuzzy() > 0, request.getPage());
|
List<WFCMessage.User> users = m_messagesStore.searchUser(request.getKeyword(), request.getFuzzy(), request.getPage());
|
||||||
WFCMessage.SearchUserResult.Builder builder = WFCMessage.SearchUserResult.newBuilder();
|
WFCMessage.SearchUserResult.Builder builder = WFCMessage.SearchUserResult.newBuilder();
|
||||||
builder.addAllEntry(users);
|
builder.addAllEntry(users);
|
||||||
byte[] data = builder.build().toByteArray();
|
byte[] data = builder.build().toByteArray();
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ import java.util.function.Function;
|
|||||||
import static cn.wildfirechat.proto.ProtoConstants.PersistFlag.Transparent;
|
import static cn.wildfirechat.proto.ProtoConstants.PersistFlag.Transparent;
|
||||||
import static io.moquette.persistence.MemoryMessagesStore.USER_STATUS;
|
import static io.moquette.persistence.MemoryMessagesStore.USER_STATUS;
|
||||||
import static io.moquette.server.Constants.MAX_MESSAGE_QUEUE;
|
import static io.moquette.server.Constants.MAX_MESSAGE_QUEUE;
|
||||||
|
import static cn.wildfirechat.proto.ProtoConstants.SearchUserType.*;
|
||||||
|
|
||||||
public class DatabaseStore {
|
public class DatabaseStore {
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(DatabaseStore.class);
|
private static final Logger LOG = LoggerFactory.getLogger(DatabaseStore.class);
|
||||||
@@ -148,8 +149,12 @@ public class DatabaseStore {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
//searchType
|
||||||
List<WFCMessage.User> searchUserFromDB(String keyword, boolean buzzy, int page) {
|
// 0 模糊匹配displayName, 精确匹配账户名和电话号码
|
||||||
|
// 1 精确匹配账户名和电话号码
|
||||||
|
// 2 精确匹配账户名
|
||||||
|
// 3 精确匹配电话号码
|
||||||
|
List<WFCMessage.User> searchUserFromDB(String keyword, int searchType, int page) {
|
||||||
Connection connection = null;
|
Connection connection = null;
|
||||||
PreparedStatement statement = null;
|
PreparedStatement statement = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
@@ -169,18 +174,29 @@ public class DatabaseStore {
|
|||||||
", `_social`" +
|
", `_social`" +
|
||||||
", `_extra`" +
|
", `_extra`" +
|
||||||
", `_dt` from t_user";
|
", `_dt` from t_user";
|
||||||
if (buzzy) {
|
switch (searchType) {
|
||||||
sql += " where (`_display_name` like ? or `_name` = ? or `_mobile` = ?) ";
|
case SearchUserType_Name_Mobile:
|
||||||
} else {
|
sql += " where (`_name` = ? or `_mobile` = ?) ";
|
||||||
sql += " where (`_name` = ? or `_mobile` = ?) ";
|
break;
|
||||||
|
case SearchUserType_Name:
|
||||||
|
sql += " where `_name` = ? ";
|
||||||
|
break;
|
||||||
|
case SearchUserType_Mobile:
|
||||||
|
sql += " where `_mobile` = ? ";
|
||||||
|
break;
|
||||||
|
case SearchUserType_General:
|
||||||
|
default:
|
||||||
|
sql += " where (`_display_name` like ? or `_name` = ? or `_mobile` = ?) ";
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
sql += " and _type <> 2"; //can search normal user(0) and robot(1), can not search things
|
sql += " and _type <> 2"; //can search normal user(0) and robot(1), can not search things
|
||||||
|
|
||||||
if (buzzy) {
|
if (searchType == SearchUserType_Name_Mobile || searchType == SearchUserType_Name || searchType == SearchUserType_Mobile) {
|
||||||
sql += " limit 20";
|
|
||||||
} else {
|
|
||||||
sql += " limit 1";
|
sql += " limit 1";
|
||||||
|
} else {
|
||||||
|
sql += " limit 20";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (page > 0) {
|
if (page > 0) {
|
||||||
@@ -190,12 +206,24 @@ public class DatabaseStore {
|
|||||||
|
|
||||||
statement = connection.prepareStatement(sql);
|
statement = connection.prepareStatement(sql);
|
||||||
int index = 1;
|
int index = 1;
|
||||||
if (buzzy) {
|
|
||||||
statement.setString(index++, "%" + keyword + "%");
|
switch (searchType) {
|
||||||
|
case SearchUserType_Name_Mobile:
|
||||||
|
statement.setString(index++, keyword);
|
||||||
|
statement.setString(index++, keyword);
|
||||||
|
break;
|
||||||
|
case SearchUserType_Name:
|
||||||
|
case SearchUserType_Mobile:
|
||||||
|
statement.setString(index++, keyword);
|
||||||
|
break;
|
||||||
|
case SearchUserType_General:
|
||||||
|
default:
|
||||||
|
statement.setString(index++, "%" + keyword + "%");
|
||||||
|
statement.setString(index++, keyword);
|
||||||
|
statement.setString(index++, keyword);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
statement.setString(index++, keyword);
|
|
||||||
statement.setString(index++, keyword);
|
|
||||||
|
|
||||||
rs = statement.executeQuery();
|
rs = statement.executeQuery();
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
|
|||||||
@@ -42,7 +42,6 @@ import java.sql.PreparedStatement;
|
|||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.locks.Lock;
|
import java.util.concurrent.locks.Lock;
|
||||||
@@ -112,7 +111,7 @@ public class MemoryMessagesStore implements IMessagesStore {
|
|||||||
private final DatabaseStore databaseStore;
|
private final DatabaseStore databaseStore;
|
||||||
private ConcurrentHashMap<String, Long> userMaxPullSeq = new ConcurrentHashMap<>();
|
private ConcurrentHashMap<String, Long> userMaxPullSeq = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
private AtomicReference<SensitiveFilter> mSensitiveFilter = new AtomicReference<>();
|
private SensitiveFilter mSensitiveFilter;
|
||||||
private volatile long lastUpdateSensitiveTime = 0;
|
private volatile long lastUpdateSensitiveTime = 0;
|
||||||
|
|
||||||
private ConcurrentHashMap<String, Boolean> userGlobalSlientMap = new ConcurrentHashMap<>();
|
private ConcurrentHashMap<String, Boolean> userGlobalSlientMap = new ConcurrentHashMap<>();
|
||||||
@@ -148,7 +147,7 @@ public class MemoryMessagesStore implements IMessagesStore {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Set<String> sensitiveWords = databaseStore.getSensitiveWord();
|
Set<String> sensitiveWords = databaseStore.getSensitiveWord();
|
||||||
mSensitiveFilter.set(new SensitiveFilter(sensitiveWords));
|
mSensitiveFilter = new SensitiveFilter(sensitiveWords);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -353,6 +352,9 @@ public class MemoryMessagesStore implements IMessagesStore {
|
|||||||
|
|
||||||
size += bundle.getMessage().getSerializedSize();
|
size += bundle.getMessage().getSerializedSize();
|
||||||
if (size >= 512 * 1024) { //3M
|
if (size >= 512 * 1024) { //3M
|
||||||
|
if(builder.getMessageCount() == 0){
|
||||||
|
builder.addMessage(bundle.getMessage());
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
builder.addMessage(bundle.getMessage());
|
builder.addMessage(bundle.getMessage());
|
||||||
@@ -687,7 +689,11 @@ public class MemoryMessagesStore implements IMessagesStore {
|
|||||||
List<WFCMessage.GroupMember> tmp = new ArrayList<>();
|
List<WFCMessage.GroupMember> tmp = new ArrayList<>();
|
||||||
ArrayList<String> newInviteUsers = new ArrayList<>();
|
ArrayList<String> newInviteUsers = new ArrayList<>();
|
||||||
for (WFCMessage.GroupMember member : memberList) {
|
for (WFCMessage.GroupMember member : memberList) {
|
||||||
member = member.toBuilder().setType(ProtoConstants.GroupMemberType.GroupMemberType_Normal).setUpdateDt(updateDt).setAlias("").build();
|
if (member.getMemberId().equals(groupInfo.getOwner())) {
|
||||||
|
member = member.toBuilder().setType(GroupMemberType_Owner).setUpdateDt(updateDt).setAlias("").build();
|
||||||
|
} else {
|
||||||
|
member = member.toBuilder().setType(GroupMemberType_Normal).setUpdateDt(updateDt).setAlias("").build();
|
||||||
|
}
|
||||||
tmp.add(member);
|
tmp.add(member);
|
||||||
newInviteUsers.add(member.getMemberId());
|
newInviteUsers.add(member.getMemberId());
|
||||||
}
|
}
|
||||||
@@ -1492,8 +1498,8 @@ public class MemoryMessagesStore implements IMessagesStore {
|
|||||||
return getUserInfo(userId);
|
return getUserInfo(userId);
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public List<WFCMessage.User> searchUser(String keyword, boolean buzzy, int page) {
|
public List<WFCMessage.User> searchUser(String keyword, int searchType, int page) {
|
||||||
return databaseStore.searchUserFromDB(keyword, buzzy, page);
|
return databaseStore.searchUserFromDB(keyword, searchType, page);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -2495,7 +2501,7 @@ public class MemoryMessagesStore implements IMessagesStore {
|
|||||||
@Override
|
@Override
|
||||||
public Set<String> handleSensitiveWord(String message) {
|
public Set<String> handleSensitiveWord(String message) {
|
||||||
updateSensitiveWord();
|
updateSensitiveWord();
|
||||||
return mSensitiveFilter.get().getSensitiveWords(message, SensitiveFilter.MatchType.MAX_MATCH);
|
return mSensitiveFilter.getSensitiveWords(message, SensitiveFilter.MatchType.MAX_MATCH);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -139,7 +139,7 @@ public interface IMessagesStore {
|
|||||||
WFCMessage.User getUserInfo(String userId);
|
WFCMessage.User getUserInfo(String userId);
|
||||||
WFCMessage.User getUserInfoByName(String name);
|
WFCMessage.User getUserInfoByName(String name);
|
||||||
WFCMessage.User getUserInfoByMobile(String mobile);
|
WFCMessage.User getUserInfoByMobile(String mobile);
|
||||||
List<WFCMessage.User> searchUser(String keyword, boolean buzzy, int page);
|
List<WFCMessage.User> searchUser(String keyword, int searchType, int page);
|
||||||
|
|
||||||
boolean updateSystemSetting(int id, String value, String desc);
|
boolean updateSystemSetting(int id, String value, String desc);
|
||||||
SystemSettingPojo getSystemSetting(int id);
|
SystemSettingPojo getSystemSetting(int id);
|
||||||
|
|||||||
@@ -179,15 +179,16 @@ public class Qos1PublishHandler extends QosPublishHandler {
|
|||||||
MemorySessionStore.Session session = m_sessionStore.getSession(clientID);
|
MemorySessionStore.Session session = m_sessionStore.getSession(clientID);
|
||||||
if (session != null && session.getUsername().equals(fromUser)) {
|
if (session != null && session.getUsername().equals(fromUser)) {
|
||||||
if (data.length > 7*1024 && session.getMqttVersion().protocolLevel() >= MqttVersion.Wildfire_1.protocolLevel()) {
|
if (data.length > 7*1024 && session.getMqttVersion().protocolLevel() >= MqttVersion.Wildfire_1.protocolLevel()) {
|
||||||
try (
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
GZIPOutputStream gzip;
|
||||||
GZIPOutputStream gzip = new GZIPOutputStream(out)
|
try {
|
||||||
) {
|
gzip = new GZIPOutputStream(out);
|
||||||
gzip.write(data);
|
gzip.write(data);
|
||||||
data = out.toByteArray();
|
gzip.close();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
data = out.toByteArray();
|
||||||
code = (byte)ErrorCode.ERROR_CODE_SUCCESS_GZIPED.code;
|
code = (byte)ErrorCode.ERROR_CODE_SUCCESS_GZIPED.code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>wildfirechat-parent</artifactId>
|
<artifactId>wildfirechat-parent</artifactId>
|
||||||
<groupId>cn.wildfirechat</groupId>
|
<groupId>cn.wildfirechat</groupId>
|
||||||
<version>0.34</version>
|
<version>0.35</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
@@ -132,6 +132,12 @@ public class ProtoConstants {
|
|||||||
int Group_Max_Member_Count = 1;
|
int Group_Max_Member_Count = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public interface SearchUserType {
|
||||||
|
int SearchUserType_General = 0;
|
||||||
|
int SearchUserType_Name_Mobile = 1;
|
||||||
|
int SearchUserType_Name = 2;
|
||||||
|
int SearchUserType_Mobile = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
<!--<relativePath>../pom.xml</relativePath>-->
|
<!--<relativePath>../pom.xml</relativePath>-->
|
||||||
<artifactId>wildfirechat-parent</artifactId>
|
<artifactId>wildfirechat-parent</artifactId>
|
||||||
<groupId>cn.wildfirechat</groupId>
|
<groupId>cn.wildfirechat</groupId>
|
||||||
<version>0.34</version>
|
<version>0.35</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>distribution</artifactId>
|
<artifactId>distribution</artifactId>
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
<artifactId>wildfirechat-parent</artifactId>
|
<artifactId>wildfirechat-parent</artifactId>
|
||||||
|
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
<version>0.34</version>
|
<version>0.35</version>
|
||||||
<name>Wildfire Chat</name>
|
<name>Wildfire Chat</name>
|
||||||
<description>Wildfire Chat Server</description>
|
<description>Wildfire Chat Server</description>
|
||||||
<inceptionYear>2019</inceptionYear>
|
<inceptionYear>2019</inceptionYear>
|
||||||
|
|||||||
+1
-1
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>wildfirechat-parent</artifactId>
|
<artifactId>wildfirechat-parent</artifactId>
|
||||||
<groupId>cn.wildfirechat</groupId>
|
<groupId>cn.wildfirechat</groupId>
|
||||||
<version>0.34</version>
|
<version>0.35</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user