添加更新接口
This commit is contained in:
+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;
|
||||
|
||||
Reference in New Issue
Block a user