添加设置用户关系中的附加信息

This commit is contained in:
heavyrain2012
2021-09-01 14:39:59 +08:00
parent 5ce8165514
commit f62e3f3cef
7 changed files with 141 additions and 0 deletions
@@ -0,0 +1,40 @@
/*
* 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.pojos.InputUpdateAlias;
import cn.wildfirechat.pojos.InputUpdateExtra;
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;
@Route(APIPath.Friend_Set_Extra)
@HttpMethod("POST")
public class FriendExtraPutAction extends AdminAction {
@Override
public boolean isTransactionAction() {
return true;
}
@Override
public boolean action(Request request, Response response) {
if (request.getNettyRequest() instanceof FullHttpRequest) {
InputUpdateExtra input = getRequestBody(request.getNettyRequest(), InputUpdateExtra.class);
ErrorCode errorCode = messagesStore.setFriendExtraRequest(input.getOperator(), input.getTargetId(), input.getExtra(), new long[1]);
setResponseContent(RestResult.resultOf(errorCode), response);
}
return true;
}
}
@@ -3079,6 +3079,43 @@ public class MemoryMessagesStore implements IMessagesStore {
return ErrorCode.ERROR_CODE_SUCCESS;
}
@Override
public ErrorCode setFriendExtraRequest(String fromUser, String targetUserId, String extra, long[] heads){
HazelcastInstance hzInstance = m_Server.getHazelcastInstance();
MultiMap<String, FriendData> friendsMap = hzInstance.getMultiMap(USER_FRIENDS);
FriendData friendData = null;
Collection<FriendData> friends = friendsMap.get(fromUser);
if (friends == null || friends.size() == 0) {
friends = loadFriend(friendsMap, fromUser);
}
for (FriendData fd:friends) {
if (fd.getFriendUid().equals(targetUserId)) {
friendData = fd;
break;
}
}
if (friendData == null) {
friendData = new FriendData();
friendData.setUserId(fromUser);
friendData.setFriendUid(targetUserId);
}
friendData.setExtra(extra);
friendData.setTimestamp(System.currentTimeMillis());
databaseStore.persistOrUpdateFriendData(friendData);
heads[0] = friendData.getTimestamp();
friendsMap.remove(fromUser);
callbackRelationEvent(fromUser, targetUserId, 3, extra);
return ErrorCode.ERROR_CODE_SUCCESS;
}
@Override
public ErrorCode handleJoinChatroom(String userId, String clientId, String chatroomId) {
IMap<String, WFCMessage.ChatroomInfo> chatroomInfoMap = m_Server.getHazelcastInstance().getMap(CHATROOMS);
@@ -182,6 +182,7 @@ public interface IMessagesStore {
ErrorCode SyncFriendRequestUnread(String userId, long unreadDt, long[] head);
ErrorCode isAllowUserMessage(String fromUser, String userId);
ErrorCode setFriendAliasRequest(String fromUser, String targetUserId, String alias, long[] head);
ErrorCode setFriendExtraRequest(String fromUser, String targetUserId, String extra, long[] head);
ErrorCode handleJoinChatroom(String userId, String clientId, String chatroomId);
ErrorCode handleQuitChatroom(String userId, String clientId, String chatroomId);