支持按照用户ID来搜索用户
This commit is contained in:
@@ -145,6 +145,9 @@ friend.disable_search false
|
|||||||
##禁止按照昵称搜索用户。
|
##禁止按照昵称搜索用户。
|
||||||
friend.disable_nick_name_search false
|
friend.disable_nick_name_search false
|
||||||
|
|
||||||
|
##禁止按照用户id搜索用户,默认为true。
|
||||||
|
friend.disable_user_id_search true
|
||||||
|
|
||||||
##禁止发送好友邀请,通过server api添加好友不受此限制(force参数需要为true)
|
##禁止发送好友邀请,通过server api添加好友不受此限制(force参数需要为true)
|
||||||
friend.disable_friend_request false
|
friend.disable_friend_request false
|
||||||
|
|
||||||
|
|||||||
@@ -161,6 +161,7 @@ public final class BrokerConstants {
|
|||||||
|
|
||||||
public static final String FRIEND_Disable_Search = "friend.disable_search";
|
public static final String FRIEND_Disable_Search = "friend.disable_search";
|
||||||
public static final String FRIEND_Disable_NickName_Search = "friend.disable_nick_name_search";
|
public static final String FRIEND_Disable_NickName_Search = "friend.disable_nick_name_search";
|
||||||
|
public static final String FRIEND_Disable_UserId_Search = "friend.disable_user_id_search";
|
||||||
public static final String FRIEND_Disable_Friend_Request = "friend.disable_friend_request";
|
public static final String FRIEND_Disable_Friend_Request = "friend.disable_friend_request";
|
||||||
public static final String FRIEND_Repeat_Request_Duration = "friend.repeat_request_duration";
|
public static final String FRIEND_Repeat_Request_Duration = "friend.repeat_request_duration";
|
||||||
public static final String FRIEND_Reject_Request_Duration = "friend.reject_request_duration";
|
public static final String FRIEND_Reject_Request_Duration = "friend.reject_request_duration";
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import cn.wildfirechat.pojos.SystemSettingPojo;
|
|||||||
import cn.wildfirechat.proto.ProtoConstants;
|
import cn.wildfirechat.proto.ProtoConstants;
|
||||||
import cn.wildfirechat.proto.WFCMessage;
|
import cn.wildfirechat.proto.WFCMessage;
|
||||||
import cn.wildfirechat.server.ThreadPoolExecutorWrapper;
|
import cn.wildfirechat.server.ThreadPoolExecutorWrapper;
|
||||||
import com.google.protobuf.InvalidProtocolBufferException;
|
|
||||||
import com.hazelcast.core.HazelcastInstance;
|
import com.hazelcast.core.HazelcastInstance;
|
||||||
import com.hazelcast.core.MultiMap;
|
import com.hazelcast.core.MultiMap;
|
||||||
import com.hazelcast.util.StringUtil;
|
import com.hazelcast.util.StringUtil;
|
||||||
@@ -163,7 +162,7 @@ public class DatabaseStore {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<WFCMessage.User> searchUserByNameMobile(String keyword, int searchType) {
|
List<WFCMessage.User> searchUserByNameMobileUserId(String keyword, int searchType) {
|
||||||
ArrayList<WFCMessage.User> out = new ArrayList<>();
|
ArrayList<WFCMessage.User> out = new ArrayList<>();
|
||||||
Connection connection = null;
|
Connection connection = null;
|
||||||
PreparedStatement statement = null;
|
PreparedStatement statement = null;
|
||||||
@@ -182,26 +181,34 @@ public class DatabaseStore {
|
|||||||
", `_extra`" +
|
", `_extra`" +
|
||||||
", `_dt`, `_type` from t_user";
|
", `_dt`, `_type` from t_user";
|
||||||
|
|
||||||
|
int sqlParaCount = 1;
|
||||||
if(searchType == SearchUserType_Name) {
|
if(searchType == SearchUserType_Name) {
|
||||||
sql += " where `_name` = ? ";
|
sql += " where `_name` = ? ";
|
||||||
} else if(searchType == SearchUserType_Mobile) {
|
} else if(searchType == SearchUserType_Mobile) {
|
||||||
sql += " where `_mobile` = ? ";
|
sql += " where `_mobile` = ? ";
|
||||||
} else {
|
} else if(searchType == SearchUserType_UserId) {
|
||||||
|
sql += " where `_uid` = ? ";
|
||||||
|
} else if(searchType == SearchUserType_Name_Mobile) {
|
||||||
|
sqlParaCount = 2;
|
||||||
sql += " where (`_name` = ? or `_mobile` = ?) ";
|
sql += " where (`_name` = ? or `_mobile` = ?) ";
|
||||||
|
} else {
|
||||||
|
sqlParaCount = 3;
|
||||||
|
sql += " where (`_name` = ? or `_mobile` = ? or `_uid` = ?) ";
|
||||||
}
|
}
|
||||||
|
|
||||||
sql += " and `_type` <> 2 and `_deleted` = 0"; //can search normal user(0) and robot(1) and admin(100), can not search things
|
sql += " and `_type` <> 2 and `_deleted` = 0"; //can search normal user(0) and robot(1) and admin(100), can not search things
|
||||||
|
|
||||||
if(searchType == SearchUserType_Name || searchType == SearchUserType_Mobile) {
|
if(searchType == SearchUserType_Name || searchType == SearchUserType_Mobile || searchType == SearchUserType_UserId) {
|
||||||
sql += " limit 1";
|
sql += " limit 1";
|
||||||
} else {
|
} else if(searchType == SearchUserType_Name_Mobile) {
|
||||||
sql += " limit 2";
|
sql += " limit 2";
|
||||||
|
} else {
|
||||||
|
sql += " limit 3";
|
||||||
}
|
}
|
||||||
|
|
||||||
statement = connection.prepareStatement(sql);
|
statement = connection.prepareStatement(sql);
|
||||||
statement.setString(1, keyword);
|
for (int i = 0; i < sqlParaCount; i++) {
|
||||||
if(searchType != SearchUserType_Name && searchType != SearchUserType_Mobile) {
|
statement.setString(i+1, keyword);
|
||||||
statement.setString(2, keyword);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
rs = statement.executeQuery();
|
rs = statement.executeQuery();
|
||||||
@@ -284,7 +291,7 @@ public class DatabaseStore {
|
|||||||
if (searchType == SearchUserType_Name) {
|
if (searchType == SearchUserType_Name) {
|
||||||
filter.add(user);
|
filter.add(user);
|
||||||
continue;
|
continue;
|
||||||
} else if(searchType != SearchUserType_Mobile) {
|
} else if(searchType == SearchUserType_Name_Mobile) {
|
||||||
if(keyword.equals(user.getName())) {
|
if(keyword.equals(user.getName())) {
|
||||||
if(!keyword.equals(user.getMobile())) {
|
if(!keyword.equals(user.getMobile())) {
|
||||||
filter.add(user);
|
filter.add(user);
|
||||||
@@ -294,15 +301,96 @@ public class DatabaseStore {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if(searchType == SearchUserType_Name_Mobile_UserId) {
|
||||||
|
if(keyword.equals(user.getName())) {
|
||||||
|
if(keyword.equals(user.getMobile()) && keyword.equals(user.getUid())) {
|
||||||
|
if((value & ProtoConstants.DisableSearchMask.DisableSearchMobileMask) > 0 && (value & ProtoConstants.DisableSearchMask.DisableSearchUserIdMask) > 0) {
|
||||||
|
filter.add(user);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
} else if(keyword.equals(user.getMobile())) {
|
||||||
|
if((value & ProtoConstants.DisableSearchMask.DisableSearchMobileMask) > 0) {
|
||||||
|
filter.add(user);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
} else if(keyword.equals(user.getUid())) {
|
||||||
|
if((value & ProtoConstants.DisableSearchMask.DisableSearchUserIdMask) > 0) {
|
||||||
|
filter.add(user);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
filter.add(user);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((value & ProtoConstants.DisableSearchMask.DisableSearchMobileMask) > 0) {
|
|
||||||
|
if((value & ProtoConstants.DisableSearchMask.DisableSearchMobileMask) > 0) {
|
||||||
if (searchType == SearchUserType_Mobile) {
|
if (searchType == SearchUserType_Mobile) {
|
||||||
filter.add(user);
|
filter.add(user);
|
||||||
} else if(searchType != SearchUserType_Name) {
|
continue;
|
||||||
if(keyword.equals(user.getMobile()) && !keyword.equals(user.getName())) {
|
} else if(searchType == SearchUserType_Name_Mobile) {
|
||||||
filter.add(user);
|
if(keyword.equals(user.getMobile())) {
|
||||||
|
if(!keyword.equals(user.getName())) {
|
||||||
|
filter.add(user);
|
||||||
|
continue;
|
||||||
|
} else if((value & ProtoConstants.DisableSearchMask.DisableSearchNameMask) > 0) {
|
||||||
|
filter.add(user);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if(searchType == SearchUserType_Name_Mobile_UserId) {
|
||||||
|
if(keyword.equals(user.getMobile())) {
|
||||||
|
if(keyword.equals(user.getName()) && keyword.equals(user.getUid())) {
|
||||||
|
if((value & ProtoConstants.DisableSearchMask.DisableSearchNameMask) > 0 && (value & ProtoConstants.DisableSearchMask.DisableSearchUserIdMask) > 0) {
|
||||||
|
filter.add(user);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
} else if(keyword.equals(user.getName())) {
|
||||||
|
if((value & ProtoConstants.DisableSearchMask.DisableSearchNameMask) > 0) {
|
||||||
|
filter.add(user);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
} else if(keyword.equals(user.getUid())) {
|
||||||
|
if((value & ProtoConstants.DisableSearchMask.DisableSearchUserIdMask) > 0) {
|
||||||
|
filter.add(user);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
filter.add(user);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if((value & ProtoConstants.DisableSearchMask.DisableSearchUserIdMask) > 0) {
|
||||||
|
if (searchType == SearchUserType_UserId) {
|
||||||
|
filter.add(user);
|
||||||
|
continue;
|
||||||
|
} else if(searchType == SearchUserType_Name_Mobile_UserId) {
|
||||||
|
if(keyword.equals(user.getUid())) {
|
||||||
|
if(keyword.equals(user.getName()) && keyword.equals(user.getMobile())) {
|
||||||
|
if((value & ProtoConstants.DisableSearchMask.DisableSearchNameMask) > 0 && (value & ProtoConstants.DisableSearchMask.DisableSearchMobileMask) > 0) {
|
||||||
|
filter.add(user);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
} else if(keyword.equals(user.getName())) {
|
||||||
|
if((value & ProtoConstants.DisableSearchMask.DisableSearchNameMask) > 0) {
|
||||||
|
filter.add(user);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
} else if(keyword.equals(user.getMobile())) {
|
||||||
|
if((value & ProtoConstants.DisableSearchMask.DisableSearchMobileMask) > 0) {
|
||||||
|
filter.add(user);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
filter.add(user);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -423,7 +511,7 @@ public class DatabaseStore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
List<WFCMessage.User> searchUserFromDB(String keyword, int searchType, int page) {
|
List<WFCMessage.User> searchUserFromDB(String keyword, int searchType, int page) {
|
||||||
List<WFCMessage.User> nameOrIdMatched = searchUserByNameMobile(keyword, searchType);
|
List<WFCMessage.User> nameOrIdMatched = searchUserByNameMobileUserId(keyword, searchType);
|
||||||
List<WFCMessage.User> out = new ArrayList<>();
|
List<WFCMessage.User> out = new ArrayList<>();
|
||||||
if(page == 0) {
|
if(page == 0) {
|
||||||
out.addAll(nameOrIdMatched);
|
out.addAll(nameOrIdMatched);
|
||||||
|
|||||||
@@ -146,6 +146,7 @@ public class MemoryMessagesStore implements IMessagesStore {
|
|||||||
|
|
||||||
private boolean mDisableSearch = false;
|
private boolean mDisableSearch = false;
|
||||||
private boolean mDisableNicknameSearch = false;
|
private boolean mDisableNicknameSearch = false;
|
||||||
|
private boolean mDisableUserIdSearch = false;
|
||||||
private boolean mDisableFriendRequest = false;
|
private boolean mDisableFriendRequest = false;
|
||||||
private long mFriendRequestDuration = 7 * 24 * 60 * 60 * 1000;
|
private long mFriendRequestDuration = 7 * 24 * 60 * 60 * 1000;
|
||||||
private long mFriendRejectDuration = 30 * 24 * 60 * 60 * 1000;
|
private long mFriendRejectDuration = 30 * 24 * 60 * 60 * 1000;
|
||||||
@@ -279,6 +280,12 @@ public class MemoryMessagesStore implements IMessagesStore {
|
|||||||
Utility.printExecption(LOG, e);
|
Utility.printExecption(LOG, e);
|
||||||
printMissConfigLog(FRIEND_Disable_NickName_Search, mDisableNicknameSearch + "");
|
printMissConfigLog(FRIEND_Disable_NickName_Search, mDisableNicknameSearch + "");
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
mDisableUserIdSearch = Boolean.parseBoolean(m_Server.getConfig().getProperty(BrokerConstants.FRIEND_Disable_UserId_Search, "true"));
|
||||||
|
} catch (Exception e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
mDisableFriendRequest = Boolean.parseBoolean(m_Server.getConfig().getProperty(BrokerConstants.FRIEND_Disable_Friend_Request));
|
mDisableFriendRequest = Boolean.parseBoolean(m_Server.getConfig().getProperty(BrokerConstants.FRIEND_Disable_Friend_Request));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -2838,6 +2845,10 @@ public class MemoryMessagesStore implements IMessagesStore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (mDisableNicknameSearch && searchType == ProtoConstants.SearchUserType.SearchUserType_General) {
|
if (mDisableNicknameSearch && searchType == ProtoConstants.SearchUserType.SearchUserType_General) {
|
||||||
|
searchType = ProtoConstants.SearchUserType.SearchUserType_Name_Mobile_UserId;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(mDisableUserIdSearch && (searchType == ProtoConstants.SearchUserType.SearchUserType_General || searchType == ProtoConstants.SearchUserType.SearchUserType_Name_Mobile_UserId)) {
|
||||||
searchType = ProtoConstants.SearchUserType.SearchUserType_Name_Mobile;
|
searchType = ProtoConstants.SearchUserType.SearchUserType_Name_Mobile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -218,12 +218,15 @@ public class ProtoConstants {
|
|||||||
int SearchUserType_Name_Mobile = 1;
|
int SearchUserType_Name_Mobile = 1;
|
||||||
int SearchUserType_Name = 2;
|
int SearchUserType_Name = 2;
|
||||||
int SearchUserType_Mobile = 3;
|
int SearchUserType_Mobile = 3;
|
||||||
|
int SearchUserType_UserId = 4;
|
||||||
|
int SearchUserType_Name_Mobile_UserId = 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface DisableSearchMask {
|
public interface DisableSearchMask {
|
||||||
int DisableSearchDisplayNameMask = 1;
|
int DisableSearchDisplayNameMask = 1;
|
||||||
int DisableSearchNameMask = 2;
|
int DisableSearchNameMask = 2;
|
||||||
int DisableSearchMobileMask = 4;
|
int DisableSearchMobileMask = 4;
|
||||||
|
int DisableSearchUserIdMask = 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface UserStatus {
|
public interface UserStatus {
|
||||||
|
|||||||
@@ -143,6 +143,9 @@ friend.disable_search false
|
|||||||
##禁止按照昵称搜索用户。
|
##禁止按照昵称搜索用户。
|
||||||
friend.disable_nick_name_search false
|
friend.disable_nick_name_search false
|
||||||
|
|
||||||
|
##禁止按照用户id搜索用户,默认为true。
|
||||||
|
friend.disable_user_id_search true
|
||||||
|
|
||||||
##禁止发送好友邀请,通过server api添加好友不受此限制(force参数需要为true)
|
##禁止发送好友邀请,通过server api添加好友不受此限制(force参数需要为true)
|
||||||
friend.disable_friend_request false
|
friend.disable_friend_request false
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user