好友关系api
This commit is contained in:
+62
@@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
* 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.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 com.xiaoleilu.loServer.model.FriendData;
|
||||||
|
import com.xiaoleilu.loServer.pojos.InputCreateGroup;
|
||||||
|
import com.xiaoleilu.loServer.pojos.InputFriendRequest;
|
||||||
|
import com.xiaoleilu.loServer.pojos.InputGetFriendList;
|
||||||
|
import io.moquette.persistence.RPCCenter;
|
||||||
|
import io.moquette.persistence.TargetEntry;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import io.netty.buffer.Unpooled;
|
||||||
|
import io.netty.handler.codec.http.FullHttpRequest;
|
||||||
|
import io.netty.handler.codec.http.HttpResponseStatus;
|
||||||
|
import io.netty.util.internal.StringUtil;
|
||||||
|
import win.liyufan.im.ErrorCode;
|
||||||
|
import win.liyufan.im.IMTopic;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
|
@Route("admin/friend/list")
|
||||||
|
@HttpMethod("POST")
|
||||||
|
public class FriendRelationGetAction extends AdminAction {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isTransactionAction() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean action(Request request, Response response) {
|
||||||
|
if (request.getNettyRequest() instanceof FullHttpRequest) {
|
||||||
|
InputGetFriendList inputGetFriendList = getRequestBody(request.getNettyRequest(), InputGetFriendList.class);
|
||||||
|
List<FriendData> dataList = messagesStore.getFriendList(inputGetFriendList.getUserId(), 0);
|
||||||
|
List<String> list = new ArrayList<>();
|
||||||
|
for (FriendData data : dataList) {
|
||||||
|
if (data.getState() == inputGetFriendList.getStatus()) {
|
||||||
|
list.add(data.getFriendUid());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
response.setStatus(HttpResponseStatus.OK);
|
||||||
|
RestResult result = RestResult.ok(list);
|
||||||
|
response.setContent(new Gson().toJson(result));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
* 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.pojos;
|
||||||
|
|
||||||
|
|
||||||
|
import cn.wildfirechat.proto.WFCMessage;
|
||||||
|
import io.netty.util.internal.StringUtil;
|
||||||
|
|
||||||
|
public class InputGetFriendList {
|
||||||
|
private String userId;
|
||||||
|
private int status;
|
||||||
|
|
||||||
|
public String getUserId() {
|
||||||
|
return userId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUserId(String userId) {
|
||||||
|
this.userId = userId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStatus(int status) {
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* 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.pojos;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class OutputGetFriendList {
|
||||||
|
private List<String> friends;
|
||||||
|
|
||||||
|
public List<String> getFriends() {
|
||||||
|
return friends;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFriends(List<String> friends) {
|
||||||
|
this.friends = friends;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1564,28 +1564,32 @@ public class MemoryMessagesStore implements IMessagesStore {
|
|||||||
friendsMap.put(userId, friendData1);
|
friendsMap.put(userId, friendData1);
|
||||||
databaseStore.persistOrUpdateFriendData(friendData1);
|
databaseStore.persistOrUpdateFriendData(friendData1);
|
||||||
|
|
||||||
FriendData friendData2 = null;
|
if (request.getStatus() != 2) {
|
||||||
|
FriendData friendData2 = null;
|
||||||
|
|
||||||
friendDatas = friendsMap.get(request.getTargetUid());
|
friendDatas = friendsMap.get(request.getTargetUid());
|
||||||
for (FriendData fd : friendDatas) {
|
for (FriendData fd : friendDatas) {
|
||||||
if (fd.getFriendUid().equals(userId)) {
|
if (fd.getFriendUid().equals(userId)) {
|
||||||
friendData2 = fd;
|
friendData2 = fd;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
if (friendData2 == null) {
|
||||||
if (friendData2 == null) {
|
friendData2 = new FriendData(request.getTargetUid(), userId, "", request.getStatus(), friendData1.getTimestamp());
|
||||||
friendData2 = new FriendData(request.getTargetUid(), userId, "", request.getStatus(), friendData1.getTimestamp());
|
} else {
|
||||||
|
friendsMap.remove(request.getTargetUid(), friendData2);
|
||||||
|
friendData2.setState(request.getStatus());
|
||||||
|
friendData2.setTimestamp(System.currentTimeMillis());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
friendsMap.put(request.getTargetUid(), friendData2);
|
||||||
|
databaseStore.persistOrUpdateFriendData(friendData2);
|
||||||
|
|
||||||
|
heads[0] = friendData2.getTimestamp();
|
||||||
} else {
|
} else {
|
||||||
friendsMap.remove(request.getTargetUid(), friendData2);
|
heads[0] = 0;
|
||||||
friendData2.setState(request.getStatus());
|
|
||||||
friendData2.setTimestamp(System.currentTimeMillis());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
friendsMap.put(request.getTargetUid(), friendData2);
|
|
||||||
databaseStore.persistOrUpdateFriendData(friendData2);
|
|
||||||
|
|
||||||
heads[0] = friendData2.getTimestamp();
|
|
||||||
heads[1] = friendData1.getTimestamp();
|
heads[1] = friendData1.getTimestamp();
|
||||||
return ErrorCode.ERROR_CODE_SUCCESS;
|
return ErrorCode.ERROR_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user