好友请求推送

This commit is contained in:
imhao183
2020-03-26 13:31:35 +08:00
parent 2f554bd046
commit d099c2aa14
5 changed files with 44 additions and 3 deletions
@@ -46,4 +46,13 @@ public class PushMessage {
this.isHiddenDetail = isHiddenDetail;
this.language = language;
}
public PushMessage(String sender, String target, long serverTime, String senderName, int unReceivedMsg, String language, int pushMessageType) {
this.sender = sender;
this.target = target;
this.senderName = senderName;
this.serverTime = serverTime;
this.unReceivedMsg = unReceivedMsg;
this.pushMessageType = pushMessageType;
this.language = language;
}
}
@@ -34,6 +34,7 @@ public class PushServer {
int PUSH_MESSAGE_TYPE_NORMAL = 0;
int PUSH_MESSAGE_TYPE_VOIP_INVITE = 1;
int PUSH_MESSAGE_TYPE_VOIP_BYE = 2;
int PUSH_MESSAGE_TYPE_FRIEND_REQUEST = 3;
}
private static PushServer INSTANCE = new PushServer();
@@ -27,7 +27,7 @@ public class AddFriendHandler extends GroupHandler<WFCMessage.AddFriendRequest>
if (errorCode == ERROR_CODE_SUCCESS) {
WFCMessage.User user = m_messagesStore.getUserInfo(request.getTargetUid());
if (user != null && user.getType() == ProtoConstants.UserType.UserType_Normal) {
publisher.publishNotification(IMTopic.NotifyFriendRequestTopic, request.getTargetUid(), head[0]);
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.internalRpcMsg(request.getTargetUid(), null, handleFriendRequest.toByteArray(), 0, fromUser, HandleFriendRequestTopic, false);
@@ -18,11 +18,13 @@ package io.moquette.spi.impl;
import cn.wildfirechat.proto.ProtoConstants;
import cn.wildfirechat.proto.WFCMessage;
import cn.wildfirechat.push.PushServer;
import com.google.gson.Gson;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.util.StringUtil;
import cn.wildfirechat.pojos.OutputNotifyChannelSubscribeStatus;
import cn.wildfirechat.pojos.SendMessageData;
import com.xiaoleilu.hutool.system.UserInfo;
import com.xiaoleilu.loServer.model.FriendData;
import io.moquette.persistence.*;
import io.moquette.persistence.MemorySessionStore.Session;
@@ -402,12 +404,18 @@ public class MessagesPublisher {
}
public void publishNotification(String topic, String receiver, long head) {
publishNotificationLocal(topic, receiver, head);
publishNotification(topic, receiver, head, null, null);
}
void publishNotificationLocal(String topic, String receiver, long head) {
public void publishNotification(String topic, String receiver, long head, String fromUser, String pushContent) {
publishNotificationLocal(topic, receiver, head, fromUser, pushContent);
}
void publishNotificationLocal(String topic, String receiver, long head, String fromUser, String pushContent) {
Collection<Session> sessions = m_sessionsStore.sessionForUser(receiver);
String fromUserName = null;
for (Session targetSession : sessions) {
boolean needPush = !StringUtil.isNullOrEmpty(pushContent);
boolean targetIsActive = this.connectionDescriptors.isConnected(targetSession.getClientSession().clientID);
if (targetIsActive) {
ByteBuf payload = Unpooled.buffer();
@@ -418,9 +426,24 @@ public class MessagesPublisher {
boolean result = this.messageSender.sendPublish(targetSession.getClientSession(), publishMsg);
if (!result) {
LOG.warn("Publish friend request failure");
} else {
needPush = false;
}
}
if (needPush) {
if (fromUserName == null) {
WFCMessage.User userInfo = m_messagesStore.getUserInfo(fromUser);
if (userInfo == null) {
fromUserName = "";
} else {
fromUserName = userInfo.getDisplayName();
}
}
if (IMTopic.NotifyFriendRequestTopic.equals(topic)) {
messageSender.sendPush(fromUser, receiver, targetSession.getClientID(), pushContent, PushServer.PushMessageType.PUSH_MESSAGE_TYPE_FRIEND_REQUEST, System.currentTimeMillis(), fromUserName, targetSession.getUnReceivedMsgs() + 1, targetSession.getLanguage());
}
}
}
}
@@ -40,6 +40,14 @@ class PersistentQueueMessageSender {
void sendPush(String sender, int conversationType, String target, int line, long messageHead, String deviceId, String pushContent, int messageContentType, long serverTime, String senderName, String targetName, int unReceivedMsg, int mentionType, boolean isHiddenDetail, String language) {
LOG.info("Send push to {}, message from {}", deviceId, sender);
PushMessage pushMessage = new PushMessage(sender, conversationType, target, line, messageContentType, serverTime, senderName, targetName, unReceivedMsg, mentionType, isHiddenDetail, language);
pushMessage.pushContent = pushContent;
PushServer.getServer().pushMessage(pushMessage, deviceId, pushContent);
}
void sendPush(String sender, String target, String deviceId, String pushContent, int pushContentType, long serverTime, String senderName, int unReceivedMsg, String language) {
LOG.info("Send push to {}, message from {}", deviceId, sender);
PushMessage pushMessage = new PushMessage(sender, target, serverTime, senderName, unReceivedMsg, language, pushContentType);
pushMessage.pushContent = pushContent;
PushServer.getServer().pushMessage(pushMessage, deviceId, pushContent);
}