Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f6e8cd4ca8 | ||
|
|
da74b9fa94 |
+1
-1
@@ -5,7 +5,7 @@
|
||||
<relativePath>../</relativePath>
|
||||
<artifactId>wildfirechat-parent</artifactId>
|
||||
<groupId>cn.wildfirechat</groupId>
|
||||
<version>0.54</version>
|
||||
<version>0.55</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>moquette-broker</artifactId>
|
||||
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* This file is part of the Wildfire Chat package.
|
||||
* (c) Heavyrain2012 <[email protected]>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
package com.xiaoleilu.loServer.action.admin;
|
||||
|
||||
import cn.wildfirechat.common.APIPath;
|
||||
import cn.wildfirechat.common.ErrorCode;
|
||||
import cn.wildfirechat.common.IMExceptionEvent;
|
||||
import cn.wildfirechat.pojos.InputOutputUserInfo;
|
||||
import cn.wildfirechat.pojos.InputUpdateUserInfo;
|
||||
import cn.wildfirechat.pojos.OutputCreateUser;
|
||||
import cn.wildfirechat.proto.ProtoConstants;
|
||||
import cn.wildfirechat.proto.WFCMessage;
|
||||
import com.google.gson.Gson;
|
||||
import com.xiaoleilu.loServer.RestResult;
|
||||
import com.xiaoleilu.loServer.annotation.HttpMethod;
|
||||
import com.xiaoleilu.loServer.annotation.Route;
|
||||
import com.xiaoleilu.loServer.handler.Request;
|
||||
import com.xiaoleilu.loServer.handler.Response;
|
||||
import io.netty.handler.codec.http.FullHttpRequest;
|
||||
import io.netty.handler.codec.http.HttpResponseStatus;
|
||||
import io.netty.util.internal.StringUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import win.liyufan.im.UUIDGenerator;
|
||||
import win.liyufan.im.Utility;
|
||||
|
||||
@Route(APIPath.Update_User)
|
||||
@HttpMethod("POST")
|
||||
public class UpdateUserAction extends AdminAction {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(UpdateUserAction.class);
|
||||
|
||||
@Override
|
||||
public boolean isTransactionAction() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean action(Request request, Response response) {
|
||||
if (request.getNettyRequest() instanceof FullHttpRequest) {
|
||||
InputUpdateUserInfo inputCreateUser = getRequestBody(request.getNettyRequest(), InputUpdateUserInfo.class);
|
||||
if (inputCreateUser != null
|
||||
&& inputCreateUser.userInfo != null
|
||||
&& !StringUtil.isNullOrEmpty(inputCreateUser.userInfo.getUserId())
|
||||
&& inputCreateUser.flag > 0) {
|
||||
|
||||
ErrorCode errorCode = messagesStore.updateUserInfo(inputCreateUser.userInfo, inputCreateUser.flag);
|
||||
response.setStatus(HttpResponseStatus.OK);
|
||||
RestResult result = RestResult.resultOf(errorCode);
|
||||
response.setContent(new Gson().toJson(result));
|
||||
} else {
|
||||
response.setStatus(HttpResponseStatus.OK);
|
||||
RestResult result = RestResult.resultOf(ErrorCode.INVALID_PARAMETER);
|
||||
response.setContent(new Gson().toJson(result));
|
||||
}
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -59,6 +59,7 @@ import static cn.wildfirechat.proto.ProtoConstants.ModifyChannelInfoType.*;
|
||||
import static cn.wildfirechat.proto.ProtoConstants.ModifyGroupInfoType.*;
|
||||
import static cn.wildfirechat.proto.ProtoConstants.PersistFlag.Transparent;
|
||||
import static cn.wildfirechat.proto.ProtoConstants.Platform.*;
|
||||
import static cn.wildfirechat.proto.ProtoConstants.UpdateUserInfoMask.*;
|
||||
import static io.moquette.BrokerConstants.*;
|
||||
import static io.moquette.server.Constants.MAX_CHATROOM_MESSAGE_QUEUE;
|
||||
import static io.moquette.server.Constants.MAX_MESSAGE_QUEUE;
|
||||
@@ -2127,6 +2128,56 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
return out;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ErrorCode updateUserInfo(InputOutputUserInfo userInfo, int flag) {
|
||||
HazelcastInstance hzInstance = m_Server.getHazelcastInstance();
|
||||
IMap<String, WFCMessage.User> mUserMap = hzInstance.getMap(USERS);
|
||||
WFCMessage.User user = mUserMap.get(userInfo.getUserId());
|
||||
if(user == null) {
|
||||
return ErrorCode.ERROR_CODE_NOT_EXIST;
|
||||
}
|
||||
WFCMessage.User.Builder builder = user.toBuilder();
|
||||
if((flag & Update_User_DisplayName) > 0) {
|
||||
builder.setDisplayName(userInfo.getDisplayName());
|
||||
}
|
||||
if((flag & Update_User_Portrait) > 0) {
|
||||
builder.setPortrait(userInfo.getPortrait());
|
||||
}
|
||||
if((flag & Update_User_Gender) > 0) {
|
||||
builder.setGender(userInfo.getGender());
|
||||
}
|
||||
if((flag & Update_User_Mobile) > 0) {
|
||||
builder.setMobile(userInfo.getMobile());
|
||||
}
|
||||
if((flag & Update_User_Email) > 0) {
|
||||
builder.setEmail(userInfo.getEmail());
|
||||
}
|
||||
if((flag & Update_User_Address) > 0) {
|
||||
builder.setAddress(userInfo.getAddress());
|
||||
}
|
||||
if((flag & Update_User_Company) > 0) {
|
||||
builder.setCompany(userInfo.getCompany());
|
||||
}
|
||||
if((flag & Update_User_Social) > 0) {
|
||||
builder.setSocial(userInfo.getSocial());
|
||||
}
|
||||
if((flag & Update_User_Extra) > 0) {
|
||||
builder.setExtra(userInfo.getExtra());
|
||||
}
|
||||
builder.setUpdateDt(System.currentTimeMillis());
|
||||
user = builder.build();
|
||||
try {
|
||||
databaseStore.updateUser(user);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return ErrorCode.ERROR_CODE_SERVER_ERROR;
|
||||
}
|
||||
|
||||
mUserMap.put(user.getUid(), user);
|
||||
callbackUserInfoEvent(user);
|
||||
return ErrorCode.ERROR_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addUserInfo(WFCMessage.User user, String password) throws Exception {
|
||||
HazelcastInstance hzInstance = m_Server.getHazelcastInstance();
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package io.moquette.spi;
|
||||
|
||||
import cn.wildfirechat.pojos.InputOutputUserInfo;
|
||||
import cn.wildfirechat.pojos.SystemSettingPojo;
|
||||
import cn.wildfirechat.proto.WFCMessage;
|
||||
import com.xiaoleilu.loServer.model.FriendData;
|
||||
@@ -142,6 +143,7 @@ public interface IMessagesStore {
|
||||
int getUserStatus(String userId);
|
||||
List<InputOutputUserBlockStatus> getUserStatusList();
|
||||
|
||||
ErrorCode updateUserInfo(InputOutputUserInfo userInfo, int flag);
|
||||
void addUserInfo(WFCMessage.User user, String password) throws Exception;
|
||||
void destoryUser(String userId);
|
||||
void updateUserInfo(WFCMessage.User user) throws Exception;
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>wildfirechat-parent</artifactId>
|
||||
<groupId>cn.wildfirechat</groupId>
|
||||
<version>0.54</version>
|
||||
<version>0.55</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ public interface APIPath {
|
||||
String Sensitive_Query = "/admin/sensitive/query";
|
||||
|
||||
String Create_User = "/admin/user/create";
|
||||
String Update_User = "/admin/user/update";
|
||||
String Destroy_User = "/admin/user/destroy";
|
||||
String Create_Robot = "/admin/robot/create";
|
||||
String CreateOrUpdate_Device = "/admin/device/create";
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* This file is part of the Wildfire Chat package.
|
||||
* (c) Heavyrain2012 <[email protected]>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
package cn.wildfirechat.pojos;
|
||||
|
||||
|
||||
import cn.wildfirechat.proto.WFCMessage;
|
||||
|
||||
public class InputUpdateUserInfo {
|
||||
//UpdateUserInfoMask
|
||||
public int flag;
|
||||
public InputOutputUserInfo userInfo;
|
||||
}
|
||||
@@ -201,6 +201,19 @@ public class ProtoConstants {
|
||||
int Chatroom_Member_Event_Unmute = 4;
|
||||
}
|
||||
|
||||
public interface UpdateUserInfoMask {
|
||||
int Update_User_DisplayName = 0x01;
|
||||
int Update_User_Portrait = 0x02;
|
||||
int Update_User_Gender = 0x04;
|
||||
int Update_User_Mobile = 0x08;
|
||||
int Update_User_Email = 0x10;
|
||||
int Update_User_Address = 0x20;
|
||||
int Update_User_Company = 0x40;
|
||||
int Update_User_Social = 0x80;
|
||||
int Update_User_Extra = 0x100;
|
||||
}
|
||||
|
||||
|
||||
public static final int MESSAGE_CONTENT_TYPE_CREATE_GROUP = 104;
|
||||
public static final int MESSAGE_CONTENT_TYPE_ADD_GROUP_MEMBER = 105;
|
||||
public static final int MESSAGE_CONTENT_TYPE_KICKOF_GROUP_MEMBER = 106;
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<!--<relativePath>../pom.xml</relativePath>-->
|
||||
<artifactId>wildfirechat-parent</artifactId>
|
||||
<groupId>cn.wildfirechat</groupId>
|
||||
<version>0.54</version>
|
||||
<version>0.55</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>distribution</artifactId>
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<artifactId>wildfirechat-parent</artifactId>
|
||||
|
||||
<packaging>pom</packaging>
|
||||
<version>0.54</version>
|
||||
<version>0.55</version>
|
||||
<name>Wildfire Chat</name>
|
||||
<description>Wildfire Chat Server</description>
|
||||
<inceptionYear>2019</inceptionYear>
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>wildfirechat-parent</artifactId>
|
||||
<groupId>cn.wildfirechat</groupId>
|
||||
<version>0.54</version>
|
||||
<version>0.55</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -134,6 +134,43 @@ public class Main {
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
InputOutputUserInfo updateUserInfo = new InputOutputUserInfo();
|
||||
updateUserInfo.setUserId(System.currentTimeMillis()+"");
|
||||
updateUserInfo.setDisplayName("updatedUserName");
|
||||
updateUserInfo.setPortrait("updatedUserPortrait");
|
||||
int updateUserFlag = ProtoConstants.UpdateUserInfoMask.Update_User_DisplayName | ProtoConstants.UpdateUserInfoMask.Update_User_Portrait;
|
||||
IMResult<Void> result = UserAdmin.updateUserInfo(updateUserInfo, updateUserFlag);
|
||||
if(result != null && result.getErrorCode() == ErrorCode.ERROR_CODE_NOT_EXIST) {
|
||||
System.out.println("updateUserInfo success");
|
||||
} else {
|
||||
System.out.println("updateUserInfo failure");
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
updateUserInfo.setUserId(userInfo.getUserId());
|
||||
result = UserAdmin.updateUserInfo(updateUserInfo, updateUserFlag);
|
||||
if(result != null && result.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
System.out.println("updateUserInfo success");
|
||||
} else {
|
||||
System.out.println("updateUserInfo failure");
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
IMResult<InputOutputUserInfo> resultGetUserInfo4 = UserAdmin.getUserByUserId(userInfo.getUserId());
|
||||
if (resultGetUserInfo4 != null && resultGetUserInfo4.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
if (userInfo.getUserId().equals(resultGetUserInfo4.getResult().getUserId())
|
||||
&& updateUserInfo.getDisplayName().equals(resultGetUserInfo4.getResult().getDisplayName())
|
||||
&& updateUserInfo.getPortrait().equals(resultGetUserInfo4.getResult().getPortrait())) {
|
||||
System.out.println("get user info success");
|
||||
} else {
|
||||
System.out.println("get user info by userId failure");
|
||||
System.exit(-1);
|
||||
}
|
||||
} else {
|
||||
System.out.println("get user info by userId failure");
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
IMResult<OutputGetIMTokenData> resultGetToken = UserAdmin.getUserToken(userInfo.getUserId(), "client111", ProtoConstants.Platform.Platform_Android);
|
||||
if (resultGetToken != null && resultGetToken.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
System.out.println("get token success: " + resultGetToken.getResult().getToken());
|
||||
|
||||
@@ -29,6 +29,14 @@ public class UserAdmin {
|
||||
return AdminHttpUtils.httpJsonPost(path, user, OutputCreateUser.class);
|
||||
}
|
||||
|
||||
public static IMResult<Void> updateUserInfo(InputOutputUserInfo user, int/*UpdateUserInfoMask*/ flag) throws Exception {
|
||||
String path = APIPath.Update_User;
|
||||
InputUpdateUserInfo updateUserInfo = new InputUpdateUserInfo();
|
||||
updateUserInfo.flag = flag;
|
||||
updateUserInfo.userInfo = user;
|
||||
return AdminHttpUtils.httpJsonPost(path, updateUserInfo, Void.class);
|
||||
}
|
||||
|
||||
public static IMResult<OutputCreateRobot> createRobot(InputCreateRobot robot) throws Exception {
|
||||
String path = APIPath.Create_Robot;
|
||||
return AdminHttpUtils.httpJsonPost(path, robot, OutputCreateRobot.class);
|
||||
|
||||
Reference in New Issue
Block a user