添加配置运行回调消息带上客户端信息
This commit is contained in:
@@ -109,6 +109,15 @@ message.global_mute_exception_types 401,402,403,404,405,407,408,410,411
|
|||||||
## 当为true时,不转发server api发送的消息;当为false时,转发server api发送的消息。
|
## 当为true时,不转发server api发送的消息;当为false时,转发server api发送的消息。
|
||||||
message.no_forward_admin_message false
|
message.no_forward_admin_message false
|
||||||
|
|
||||||
|
## 消息转发功能开启时,转发信息是否带上用户clientId和平台类型。
|
||||||
|
message.forward_with_client_info false
|
||||||
|
|
||||||
|
## 机器人回调信息是否带上用户clientId和平台类型。
|
||||||
|
robot.callback_with_client_info false
|
||||||
|
|
||||||
|
## 频道回调信息是否带上用户clientId和平台类型。
|
||||||
|
channel.callback_with_client_info false
|
||||||
|
|
||||||
##禁止搜索用户
|
##禁止搜索用户
|
||||||
friend.disable_search false
|
friend.disable_search false
|
||||||
|
|
||||||
|
|||||||
@@ -142,6 +142,10 @@ public final class BrokerConstants {
|
|||||||
|
|
||||||
public static final String MESSAGE_NO_Forward_Admin_Message = "message.no_forward_admin_message";
|
public static final String MESSAGE_NO_Forward_Admin_Message = "message.no_forward_admin_message";
|
||||||
|
|
||||||
|
public static final String MESSAGE_Forward_With_Client_Info = "message.forward_with_client_info";
|
||||||
|
public static final String ROBOT_Callback_With_Client_Info = "robot.callback_with_client_info";
|
||||||
|
public static final String CHANNEL_Callback_With_Client_Info = "channel.callback_with_client_info";
|
||||||
|
|
||||||
public static final String FRIEND_Disable_Search = "friend.disable_search";
|
public static final String FRIEND_Disable_Search = "friend.disable_search";
|
||||||
public static final String FRIEND_Disable_NickName_Search = "friend.disable_nick_name_search";
|
public static final String FRIEND_Disable_NickName_Search = "friend.disable_nick_name_search";
|
||||||
public static final String FRIEND_Disable_Friend_Request = "friend.disable_friend_request";
|
public static final String FRIEND_Disable_Friend_Request = "friend.disable_friend_request";
|
||||||
|
|||||||
@@ -9,11 +9,13 @@
|
|||||||
package io.moquette.imhandler;
|
package io.moquette.imhandler;
|
||||||
|
|
||||||
import cn.wildfirechat.pojos.MessagePayload;
|
import cn.wildfirechat.pojos.MessagePayload;
|
||||||
|
import cn.wildfirechat.pojos.OutputClient;
|
||||||
import cn.wildfirechat.proto.ProtoConstants;
|
import cn.wildfirechat.proto.ProtoConstants;
|
||||||
import cn.wildfirechat.proto.WFCMessage;
|
import cn.wildfirechat.proto.WFCMessage;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.hazelcast.util.StringUtil;
|
import com.hazelcast.util.StringUtil;
|
||||||
import io.moquette.BrokerConstants;
|
import io.moquette.BrokerConstants;
|
||||||
|
import io.moquette.persistence.MemorySessionStore;
|
||||||
import io.moquette.spi.impl.Qos1PublishHandler;
|
import io.moquette.spi.impl.Qos1PublishHandler;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import cn.wildfirechat.common.ErrorCode;
|
import cn.wildfirechat.common.ErrorCode;
|
||||||
@@ -171,12 +173,20 @@ public class SendMessageHandler extends IMHandler<WFCMessage.Message> {
|
|||||||
}
|
}
|
||||||
message = message.toBuilder().setFromUser(fromUser).setMessageId(messageId).setServerTimestamp(timestamp).build();
|
message = message.toBuilder().setFromUser(fromUser).setMessageId(messageId).setServerTimestamp(timestamp).build();
|
||||||
|
|
||||||
|
OutputClient outputClient = null;
|
||||||
|
if(m_messagesStore.isForwardMessageWithClientInfo() && requestSourceType == ProtoConstants.RequestSourceType.Request_From_User && !StringUtil.isNullOrEmpty(clientID)) {
|
||||||
|
MemorySessionStore.Session session = m_sessionsStore.getSession(clientID);
|
||||||
|
if(session != null && session.getUsername().equals(fromUser)) {
|
||||||
|
outputClient = new OutputClient(session.getPlatform(), clientID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!StringUtil.isNullOrEmpty(mForwardUrl) && (mForwardMessageTypes.isEmpty() || mForwardMessageTypes.contains(message.getContent().getType())) && !(isAdmin && mNoForwardAdminMessage)) {
|
if (!StringUtil.isNullOrEmpty(mForwardUrl) && (mForwardMessageTypes.isEmpty() || mForwardMessageTypes.contains(message.getContent().getType())) && !(isAdmin && mNoForwardAdminMessage)) {
|
||||||
publisher.forwardMessage(message, mForwardUrl);
|
publisher.forwardMessage(message, mForwardUrl, outputClient);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!StringUtil.isNullOrEmpty(mMentionForwardUrl) && message.hasContent() && message.getContent().getMentionedType() != 0 && !(isAdmin && mNoForwardAdminMessage)) {
|
if(!StringUtil.isNullOrEmpty(mMentionForwardUrl) && message.hasContent() && message.getContent().getMentionedType() != 0 && !(isAdmin && mNoForwardAdminMessage)) {
|
||||||
publisher.forwardMessage(message, mMentionForwardUrl);
|
publisher.forwardMessage(message, mMentionForwardUrl, outputClient);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isAdmin) {
|
if (!isAdmin) {
|
||||||
|
|||||||
@@ -167,6 +167,10 @@ public class MemoryMessagesStore implements IMessagesStore {
|
|||||||
private int mSyncDataPartSize = 0;
|
private int mSyncDataPartSize = 0;
|
||||||
private boolean keepDisplayNameWhenDestroyUser = true;
|
private boolean keepDisplayNameWhenDestroyUser = true;
|
||||||
|
|
||||||
|
private boolean mForwardMessageWithClientInfo = false;
|
||||||
|
private boolean mRobotCallbackWithClientInfo = false;
|
||||||
|
private boolean mChannelCallbackWithClientInfo = false;
|
||||||
|
|
||||||
private Set<Integer> mUserHideProperties = new HashSet<>();
|
private Set<Integer> mUserHideProperties = new HashSet<>();
|
||||||
|
|
||||||
MemoryMessagesStore(Server server, DatabaseStore databaseStore) {
|
MemoryMessagesStore(Server server, DatabaseStore databaseStore) {
|
||||||
@@ -446,6 +450,23 @@ public class MemoryMessagesStore implements IMessagesStore {
|
|||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
mForwardMessageWithClientInfo = Boolean.parseBoolean(server.getConfig().getProperty(BrokerConstants.MESSAGE_Forward_With_Client_Info, "false"));
|
||||||
|
} catch (Exception e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
mRobotCallbackWithClientInfo = Boolean.parseBoolean(server.getConfig().getProperty(BrokerConstants.ROBOT_Callback_With_Client_Info, "false"));
|
||||||
|
} catch (Exception e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
mChannelCallbackWithClientInfo = Boolean.parseBoolean(server.getConfig().getProperty(BrokerConstants.CHANNEL_Callback_With_Client_Info, "false"));
|
||||||
|
} catch (Exception e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void printMissConfigLog(String config, String defaultValue) {
|
private void printMissConfigLog(String config, String defaultValue) {
|
||||||
@@ -4066,6 +4087,20 @@ public class MemoryMessagesStore implements IMessagesStore {
|
|||||||
return mGroupVisibleQuitKickoffNotification;
|
return mGroupVisibleQuitKickoffNotification;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isForwardMessageWithClientInfo() {
|
||||||
|
return mForwardMessageWithClientInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isRobotCallbackWithClientInfo() {
|
||||||
|
return mRobotCallbackWithClientInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isChannelCallbackWithClientInfo() {
|
||||||
|
return mChannelCallbackWithClientInfo;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Integer> getClientForbiddenSendTypes() {
|
public List<Integer> getClientForbiddenSendTypes() {
|
||||||
|
|||||||
@@ -233,6 +233,10 @@ public interface IMessagesStore {
|
|||||||
boolean isAllowRobotCustomGroupNotification();
|
boolean isAllowRobotCustomGroupNotification();
|
||||||
int getVisibleQuitKickoffNotification();
|
int getVisibleQuitKickoffNotification();
|
||||||
|
|
||||||
|
boolean isForwardMessageWithClientInfo();
|
||||||
|
boolean isRobotCallbackWithClientInfo();
|
||||||
|
boolean isChannelCallbackWithClientInfo();
|
||||||
|
|
||||||
List<Integer> getClientForbiddenSendTypes();
|
List<Integer> getClientForbiddenSendTypes();
|
||||||
List<Integer> getBlackListExceptionTypes();
|
List<Integer> getBlackListExceptionTypes();
|
||||||
List<Integer> getGroupMuteExceptionTypes();
|
List<Integer> getGroupMuteExceptionTypes();
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package io.moquette.spi.impl;
|
package io.moquette.spi.impl;
|
||||||
|
|
||||||
|
import cn.wildfirechat.pojos.OutputClient;
|
||||||
import cn.wildfirechat.pojos.OutputMessageData;
|
import cn.wildfirechat.pojos.OutputMessageData;
|
||||||
import cn.wildfirechat.proto.ProtoConstants;
|
import cn.wildfirechat.proto.ProtoConstants;
|
||||||
import cn.wildfirechat.proto.WFCMessage;
|
import cn.wildfirechat.proto.WFCMessage;
|
||||||
@@ -175,10 +176,19 @@ public class MessagesPublisher {
|
|||||||
if (message == null) {
|
if (message == null) {
|
||||||
message = m_messagesStore.getMessage(messageId);
|
message = m_messagesStore.getMessage(messageId);
|
||||||
}
|
}
|
||||||
|
OutputClient outputClient = null;
|
||||||
|
if(m_messagesStore.isRobotCallbackWithClientInfo() && !StringUtil.isNullOrEmpty(exceptClientId)) {
|
||||||
|
Session session = m_sessionsStore.getSession(exceptClientId);
|
||||||
|
if(session != null && session.getUsername().equals(sender)) {
|
||||||
|
outputClient = new OutputClient(session.getPlatform(), exceptClientId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
final WFCMessage.Message finalMsg = message;
|
final WFCMessage.Message finalMsg = message;
|
||||||
|
OutputClient finalOutputClient = outputClient;
|
||||||
Server.getServer().getCallbackScheduler().execute(() -> {
|
Server.getServer().getCallbackScheduler().execute(() -> {
|
||||||
try {
|
try {
|
||||||
HttpUtils.httpJsonPost(robot.getCallback(), new Gson().toJson(OutputMessageData.fromProtoMessage(finalMsg), OutputMessageData.class), HttpUtils.HttpPostType.POST_TYPE_Robot_Message_Callback);
|
HttpUtils.httpJsonPost(robot.getCallback(), new Gson().toJson(OutputMessageData.fromProtoMessage(finalMsg, finalOutputClient), OutputMessageData.class), HttpUtils.HttpPostType.POST_TYPE_Robot_Message_Callback);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
Utility.printExecption(LOG, e, EVENT_CALLBACK_Exception);
|
Utility.printExecption(LOG, e, EVENT_CALLBACK_Exception);
|
||||||
@@ -595,9 +605,18 @@ public class MessagesPublisher {
|
|||||||
if (message.getConversation().getType() == ProtoConstants.ConversationType.ConversationType_Channel) {
|
if (message.getConversation().getType() == ProtoConstants.ConversationType.ConversationType_Channel) {
|
||||||
WFCMessage.ChannelInfo channelInfo = m_messagesStore.getChannelInfo(message.getConversation().getTarget());
|
WFCMessage.ChannelInfo channelInfo = m_messagesStore.getChannelInfo(message.getConversation().getTarget());
|
||||||
if (channelInfo != null && !StringUtil.isNullOrEmpty(channelInfo.getCallback())) {
|
if (channelInfo != null && !StringUtil.isNullOrEmpty(channelInfo.getCallback())) {
|
||||||
|
OutputClient outputClient = null;
|
||||||
|
if(m_messagesStore.isChannelCallbackWithClientInfo() && !StringUtil.isNullOrEmpty(exceptClientId)) {
|
||||||
|
Session session = m_sessionsStore.getSession(exceptClientId);
|
||||||
|
if(session != null && session.getUsername().equals(message.getFromUser())) {
|
||||||
|
outputClient = new OutputClient(session.getPlatform(), exceptClientId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
OutputClient finalOutputClient = outputClient;
|
||||||
Server.getServer().getCallbackScheduler().execute(() -> {
|
Server.getServer().getCallbackScheduler().execute(() -> {
|
||||||
try {
|
try {
|
||||||
HttpUtils.httpJsonPost(channelInfo.getCallback() + "/message", new Gson().toJson(OutputMessageData.fromProtoMessage(message), OutputMessageData.class), HttpUtils.HttpPostType.POST_TYPE_Channel_Message_Callback);
|
HttpUtils.httpJsonPost(channelInfo.getCallback() + "/message", new Gson().toJson(OutputMessageData.fromProtoMessage(message, finalOutputClient), OutputMessageData.class), HttpUtils.HttpPostType.POST_TYPE_Channel_Message_Callback);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
Utility.printExecption(LOG, e, EVENT_CALLBACK_Exception);
|
Utility.printExecption(LOG, e, EVENT_CALLBACK_Exception);
|
||||||
@@ -647,10 +666,10 @@ public class MessagesPublisher {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void forwardMessage(final WFCMessage.Message message, String forwardUrl) {
|
public void forwardMessage(final WFCMessage.Message message, String forwardUrl, OutputClient outputClient) {
|
||||||
Server.getServer().getCallbackScheduler().execute(() -> {
|
Server.getServer().getCallbackScheduler().execute(() -> {
|
||||||
try {
|
try {
|
||||||
HttpUtils.httpJsonPost(forwardUrl, new Gson().toJson(OutputMessageData.fromProtoMessage(message), OutputMessageData.class), HttpUtils.HttpPostType.POST_TYPE_Forward_Message_Callback);
|
HttpUtils.httpJsonPost(forwardUrl, new Gson().toJson(OutputMessageData.fromProtoMessage(message, outputClient), OutputMessageData.class), HttpUtils.HttpPostType.POST_TYPE_Forward_Message_Callback);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
Utility.printExecption(LOG, e, EVENT_CALLBACK_Exception);
|
Utility.printExecption(LOG, e, EVENT_CALLBACK_Exception);
|
||||||
|
|||||||
@@ -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 cn.wildfirechat.pojos;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class OutputClient {
|
||||||
|
private int platform;
|
||||||
|
private String clientId;
|
||||||
|
|
||||||
|
public OutputClient() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public OutputClient(int platform, String clientId) {
|
||||||
|
this.platform = platform;
|
||||||
|
this.clientId = clientId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPlatform() {
|
||||||
|
return platform;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPlatform(int platform) {
|
||||||
|
this.platform = platform;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getClientId() {
|
||||||
|
return clientId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setClientId(String clientId) {
|
||||||
|
this.clientId = clientId;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -20,6 +20,7 @@ public class OutputMessageData {
|
|||||||
private MessagePayload payload;
|
private MessagePayload payload;
|
||||||
private List<String> toUsers;
|
private List<String> toUsers;
|
||||||
private long timestamp;
|
private long timestamp;
|
||||||
|
private OutputClient client;
|
||||||
|
|
||||||
public String getSender() {
|
public String getSender() {
|
||||||
return sender;
|
return sender;
|
||||||
@@ -69,7 +70,19 @@ public class OutputMessageData {
|
|||||||
this.timestamp = timestamp;
|
this.timestamp = timestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public OutputClient getClient() {
|
||||||
|
return client;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setClient(OutputClient client) {
|
||||||
|
this.client = client;
|
||||||
|
}
|
||||||
|
|
||||||
public static OutputMessageData fromProtoMessage(WFCMessage.Message protoMessage) {
|
public static OutputMessageData fromProtoMessage(WFCMessage.Message protoMessage) {
|
||||||
|
return fromProtoMessage(protoMessage, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static OutputMessageData fromProtoMessage(WFCMessage.Message protoMessage, OutputClient fromClient) {
|
||||||
OutputMessageData data = new OutputMessageData();
|
OutputMessageData data = new OutputMessageData();
|
||||||
data.messageId = protoMessage.getMessageId();
|
data.messageId = protoMessage.getMessageId();
|
||||||
data.sender = protoMessage.getFromUser();
|
data.sender = protoMessage.getFromUser();
|
||||||
@@ -80,6 +93,7 @@ public class OutputMessageData {
|
|||||||
data.payload = MessagePayload.fromProtoMessageContent(protoMessage.getContent());
|
data.payload = MessagePayload.fromProtoMessageContent(protoMessage.getContent());
|
||||||
data.timestamp = protoMessage.getServerTimestamp();
|
data.timestamp = protoMessage.getServerTimestamp();
|
||||||
data.toUsers = protoMessage.getToList();
|
data.toUsers = protoMessage.getToList();
|
||||||
|
data.client = fromClient;
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -104,6 +104,15 @@ message.global_mute_exception_types 401,402,403,404,405,407,408,410,411
|
|||||||
## 当为true时,不转发server api发送的消息;当为false时,转发server api发送的消息。
|
## 当为true时,不转发server api发送的消息;当为false时,转发server api发送的消息。
|
||||||
message.no_forward_admin_message false
|
message.no_forward_admin_message false
|
||||||
|
|
||||||
|
## 消息转发功能开启时,转发信息是否带上用户clientId和平台类型。
|
||||||
|
message.forward_with_client_info false
|
||||||
|
|
||||||
|
## 机器人回调信息是否带上用户clientId和平台类型。
|
||||||
|
robot.callback_with_client_info false
|
||||||
|
|
||||||
|
## 频道回调信息是否带上用户clientId和平台类型。
|
||||||
|
channel.callback_with_client_info false
|
||||||
|
|
||||||
##禁止搜索用户
|
##禁止搜索用户
|
||||||
friend.disable_search false
|
friend.disable_search false
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user