Skip to content

Commit

Permalink
添加配置,请求机器人好友时,是否自动接受
Browse files Browse the repository at this point in the history
  • Loading branch information
heavyrian2012 committed May 4, 2023
1 parent ca50872 commit 6245fe3
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 2 deletions.
3 changes: 3 additions & 0 deletions broker/config/wildfirechat.conf
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ friend.reject_request_duration 2592000000
##好友请求过期时间,单位是毫秒,默认是7天,0为无限长期限。
friend.request_expiration_duration 604800000

##请求添加机器人为好友时,机器人是否自动接受,默认为true
friend.robot_auto_accept true

## 聊天室观众空闲退出时间,单位为毫秒,默认为15分钟,0为永远不退出
chatroom.participant_idle_time 900000

Expand Down
2 changes: 2 additions & 0 deletions broker/src/main/java/io/moquette/BrokerConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ public final class BrokerConstants {
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_Request_Expiration_Duration = "friend.request_expiration_duration";
public static final String FRIEND_Request_Robot_Auto_Accept = "friend.robot_auto_accept";


public static final String CHATROOM_Participant_Idle_Time = "chatroom.participant_idle_time";
public static final String CHATROOM_Rejoin_When_Active = "chatroom.rejoin_when_active";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, Pr
if (user != null && user.getType() == ProtoConstants.UserType.UserType_Normal) {
publisher.publishNotification(IMTopic.NotifyFriendRequestTopic, request.getTargetUid(), head[0], fromUser, request.getReason());
} else if(user != null && user.getType() == ProtoConstants.UserType.UserType_Robot) {
WFCMessage.HandleFriendRequest handleFriendRequest = WFCMessage.HandleFriendRequest.newBuilder().setTargetUid(fromUser).setStatus(ProtoConstants.FriendRequestStatus.RequestStatus_Accepted).build();
mServer.onApiMessage(request.getTargetUid(), null, handleFriendRequest.toByteArray(), 0, fromUser, HandleFriendRequestTopic, requestSourceType);
if(m_messagesStore.isRobotAutoAcceptFriendRequest()) {
WFCMessage.HandleFriendRequest handleFriendRequest = WFCMessage.HandleFriendRequest.newBuilder().setTargetUid(fromUser).setStatus(ProtoConstants.FriendRequestStatus.RequestStatus_Accepted).build();
mServer.onApiMessage(request.getTargetUid(), null, handleFriendRequest.toByteArray(), 0, fromUser, HandleFriendRequestTopic, requestSourceType);
}
}
}
return errorCode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ public class MemoryMessagesStore implements IMessagesStore {
private long mFriendRequestDuration = 7 * 24 * 60 * 60 * 1000;
private long mFriendRejectDuration = 30 * 24 * 60 * 60 * 1000;
private long mFriendRequestExpiration = 7 * 24 * 60 * 60 * 1000;
private boolean mFriendRobotAutoAccept = true;

private boolean mMultiPlatformNotification = false;
private boolean mMobileDefaultSilentWhenPCOnline = true;
Expand Down Expand Up @@ -297,6 +298,12 @@ public class MemoryMessagesStore implements IMessagesStore {
printMissConfigLog(FRIEND_Request_Expiration_Duration, mFriendRequestExpiration + "");
}


try {
mFriendRobotAutoAccept = Boolean.parseBoolean(m_Server.getConfig().getProperty(BrokerConstants.FRIEND_Request_Robot_Auto_Accept, "true"));
} catch (Exception e) {
}

try {
mChatroomRejoinWhenActive = Boolean.parseBoolean(m_Server.getConfig().getProperty(BrokerConstants.CHATROOM_Rejoin_When_Active));
} catch (Exception e) {
Expand Down Expand Up @@ -4306,6 +4313,11 @@ public boolean isChannelCallbackWithClientInfo() {
return mChannelCallbackWithClientInfo;
}

@Override
public boolean isRobotAutoAcceptFriendRequest() {
return mFriendRobotAutoAccept;
}

@Override
public List<Integer> getClientForbiddenSendTypes() {
return mForbiddenClientSendTypes;
Expand Down
2 changes: 2 additions & 0 deletions broker/src/main/java/io/moquette/spi/IMessagesStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,8 @@ public String toString() {
boolean isRobotCallbackWithClientInfo();
boolean isChannelCallbackWithClientInfo();

boolean isRobotAutoAcceptFriendRequest();

List<Integer> getClientForbiddenSendTypes();
List<Integer> getBlackListExceptionTypes();
List<Integer> getGroupMuteExceptionTypes();
Expand Down
3 changes: 3 additions & 0 deletions distribution/src/main/resources/wildfirechat.conf
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ friend.reject_request_duration 2592000000
##好友请求过期时间,单位是毫秒,默认是7天,0为无限长期限。
friend.request_expiration_duration 604800000

##请求添加机器人为好友时,机器人是否自动接受,默认为true
friend.robot_auto_accept true

## 聊天室观众空闲退出时间,单位为毫秒,默认为15分钟,0为永远不退出
chatroom.participant_idle_time 900000

Expand Down

0 comments on commit 6245fe3

Please sign in to comment.