支持客户端上传本地角标,当需要推送时会把角标数字带上

This commit is contained in:
heavyrian2012
2025-07-29 11:51:11 +08:00
parent 1359ce5250
commit 7e73c2880b
8 changed files with 38 additions and 16 deletions
@@ -37,6 +37,7 @@ public class PushMessage {
public boolean republish;
public long messageId;
public long callStartUid;
public int existBadgeNumber;
public PushMessage(String sender, int conversationType, String target, int line, int messageContentType, long serverTime, String senderName, String senderPortrait, String targetName, String targetPortrait, int unReceivedMsg, int mentionedType, boolean isHiddenDetail, String language) {
this.sender = sender;
@@ -81,10 +81,6 @@ public class PushServer {
}
MemorySessionStore.Session session = sessionsStore.getSession(deviceId);
int badge = session.getUnReceivedMsgs();
if (badge <= 0) {
badge = 1;
}
if (StringUtil.isNullOrEmpty(session.getDeviceToken())) {
LOG.warn("Device token is empty for device {}", deviceId);
return;
@@ -94,7 +90,6 @@ public class PushServer {
pushMessage.pushType = session.getPushType();
pushMessage.pushContent = pushContent;
pushMessage.deviceToken = session.getDeviceToken();
pushMessage.unReceivedMsg = badge;
pushMessage.userId = session.getUsername();
if (session.getPlatform() == ProtoConstants.Platform.Platform_iOS ||
session.getPlatform() == ProtoConstants.Platform.Platform_iPad ||
@@ -56,6 +56,7 @@ import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import static cn.wildfirechat.common.IMExceptionEvent.EventType.EVENT_CALLBACK_Exception;
@@ -844,6 +845,18 @@ public class MemoryMessagesStore implements IMessagesStore {
return pullType;
}
private final Map<String, Integer> unreceivedMsgCount = new ConcurrentHashMap<>();
@Override
public void increaseUnreceivedMsgCount(String user) {
unreceivedMsgCount.compute(user, (s, integer) -> integer == null ? 1 : integer+1);
}
@Override
public int getUnreceivedMsgCount(String user) {
return unreceivedMsgCount.getOrDefault(user, 0);
}
@Override
public Set<String> getAllEnds() {
return databaseStore.getAllEnds(mBroadcastTargetFromUserTable);
@@ -858,7 +871,7 @@ public class MemoryMessagesStore implements IMessagesStore {
MemorySessionStore.Session session = m_Server.getStore().sessionsStore().getSession(exceptClientId);
session.refreshLastActiveTime();
if (pullType != ProtoConstants.PullType.Pull_ChatRoom) {
session.setUnReceivedMsgs(0);
unreceivedMsgCount.put(user, 0);
} else {
session.refreshLastChatroomActiveTime();
}
@@ -92,10 +92,6 @@ public class MemorySessionStore implements ISessionsStore {
return unReceivedMsgs;
}
public void setUnReceivedMsgs(int unReceivedMsgs) {
this.unReceivedMsgs = unReceivedMsgs;
}
public int getPushType() {
return pushType;
}
@@ -235,6 +235,9 @@ public interface IMessagesStore {
WFCMessage.Message getMessage(long messageId);
void increaseUnreceivedMsgCount(String user);
int getUnreceivedMsgCount(String user);
boolean isAllowClientCustomGroupNotification();
boolean isAllowRobotCustomGroupNotification();
int getVisibleQuitKickoffNotification();
@@ -324,7 +324,7 @@ public class MessagesPublisher {
if (!StringUtil.isNullOrEmpty(pushContent) || messageContentType == 400) {
if (!isConvSilent && (persistFlag & 0x02) > 0) {
targetSession.setUnReceivedMsgs(targetSession.getUnReceivedMsgs() + 1);
m_messagesStore.increaseUnreceivedMsgCount(user);
}
}
}
@@ -423,13 +423,25 @@ public class MessagesPublisher {
name = fd.getAlias();
}
}
this.messageSender.sendPush(sender, conversationType, target, line, messageId, targetSession.getClientID(), pushContent, pushData, callStartUid, messageContentType, serverTime, name, senderPortrait, targetName, targetPortrait, targetSession.getUnReceivedMsgs(), curMentionType, isHiddenDetail, targetSession.getLanguage());
this.messageSender.sendPush(sender, conversationType, target, line, messageId, targetSession.getClientID(), pushContent, pushData, callStartUid, messageContentType, serverTime, name, senderPortrait, targetName, targetPortrait, m_messagesStore.getUnreceivedMsgCount(user), curMentionType, isHiddenDetail, targetSession.getLanguage(), getExistBadgeNumber(user));
}
}
}
}
private int getExistBadgeNumber(String user) {
int existBadgeNumber = 0;
WFCMessage.UserSettingEntry userSettingData = m_messagesStore.getUserSetting(user, UserSettingScope.kUserSettingScopeSyncBadge, "");
if(userSettingData != null && !StringUtil.isNullOrEmpty(userSettingData.getValue())) {
try {
existBadgeNumber = Integer.parseInt(userSettingData.getValue());
} catch (NumberFormatException e) {}
}
return existBadgeNumber;
}
public boolean sendOfflineNotify(String clientId) {
boolean targetIsActive = this.connectionDescriptors.isConnected(clientId);
if (targetIsActive) {
@@ -595,7 +607,7 @@ public class MessagesPublisher {
}
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());
messageSender.sendPush(fromUser, receiver, targetSession.getClientID(), pushContent, PushServer.PushMessageType.PUSH_MESSAGE_TYPE_FRIEND_REQUEST, System.currentTimeMillis(), fromUserName, m_messagesStore.getUnreceivedMsgCount(receiver) + 1, targetSession.getLanguage(), getExistBadgeNumber(receiver));
}
}
}
@@ -37,17 +37,18 @@ class PersistentQueueMessageSender {
this.connectionDescriptorStore = connectionDescriptorStore;
}
void sendPush(String sender, int conversationType, String target, int line, long messageId, String deviceId, String pushContent, String pushData, long callStartUid, int messageContentType, long serverTime, String senderName, String senderPortrait, String targetName, String targetPortrait, int unReceivedMsg, int mentionType, boolean isHiddenDetail, String language) {
void sendPush(String sender, int conversationType, String target, int line, long messageId, String deviceId, String pushContent, String pushData, long callStartUid, int messageContentType, long serverTime, String senderName, String senderPortrait, String targetName, String targetPortrait, int unReceivedMsg, int mentionType, boolean isHiddenDetail, String language, int existBadgeNumber) {
LOG.info("Send push to {}, message from {}", deviceId, sender);
PushMessage pushMessage = new PushMessage(sender, conversationType, target, line, messageContentType, serverTime, senderName, senderPortrait, targetName, targetPortrait, unReceivedMsg, mentionType, isHiddenDetail, language);
pushMessage.pushContent = pushContent;
pushMessage.pushData = pushData;
pushMessage.messageId = messageId;
pushMessage.callStartUid = callStartUid;
pushMessage.existBadgeNumber = existBadgeNumber;
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) {
void sendPush(String sender, String target, String deviceId, String pushContent, int pushContentType, long serverTime, String senderName, int unReceivedMsg, String language, int existBadgeNumber) {
LOG.info("Send push to {}, message from {}", deviceId, sender);
PushMessage pushMessage = new PushMessage(sender, target, serverTime, senderName, unReceivedMsg, language, pushContentType);
pushMessage.pushContent = pushContent;
@@ -21,4 +21,5 @@ public interface UserSettingScope {
int kUserSettingGroupRemark = 26;
int kUserSettingPrivacySearchable = 27;
int kUserSettingAddFriendStrategy = 28;
int kUserSettingScopeSyncBadge = 29;
}