mute notification when pc online settings

This commit is contained in:
imhao183
2020-10-05 17:24:18 +08:00
parent 0a5c8a67bb
commit ef1f25dab1
5 changed files with 38 additions and 1 deletions
@@ -1051,6 +1051,10 @@ public class DatabaseStore {
out.add(builder.build());
}
if (out.isEmpty()) {
WFCMessage.UserSettingEntry.Builder builder = WFCMessage.UserSettingEntry.newBuilder().setScope(999).setKey("").setValue("").setUpdateDt(0);
out.add(builder.build());
}
return out;
} catch (SQLException e) {
// TODO Auto-generated catch block
@@ -2743,6 +2743,16 @@ public class MemoryMessagesStore implements IMessagesStore {
return slient;
}
@Override
public boolean getSilentWhenPcOnline(String userId) {
WFCMessage.UserSettingEntry entry = getUserSetting(userId, UserSettingScope.kUserSettingMuteWhenPCOnline, null);
if (entry == null || !entry.getValue().equals("0")) {
return false;
} else {
return true;
}
}
@Override
public ErrorCode createChannel(String operator, WFCMessage.ChannelInfo channelInfo) {
HazelcastInstance hzInstance = m_Server.getHazelcastInstance();
@@ -188,6 +188,7 @@ public interface IMessagesStore {
boolean getUserGlobalSlient(String userId);
boolean getUserPushHiddenDetail(String userId);
boolean getUserConversationSlient(String userId, WFCMessage.Conversation conversation);
boolean getSilentWhenPcOnline(String userId);
ErrorCode createChannel(String operator, WFCMessage.ChannelInfo channelInfo);
void clearUserChannels(String userId);
@@ -25,7 +25,6 @@ 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;
@@ -198,6 +197,23 @@ public class MessagesPublisher {
if (pullType == ProtoConstants.PullType.Pull_ChatRoom) {
targetClients = m_messagesStore.getChatroomMemberClient(user);
}
boolean isPcOnline = false;
if (!user.equals(sender)) {
for (Session targetSession : sessions) {
if (targetSession.getPlatform() == ProtoConstants.Platform.Platform_WEB
|| targetSession.getPlatform() == ProtoConstants.Platform.Platform_Windows
|| targetSession.getPlatform() == ProtoConstants.Platform.Platform_LINUX
|| targetSession.getPlatform() == ProtoConstants.Platform.Platform_OSX) {
boolean targetIsActive = this.connectionDescriptors.isConnected(targetSession.getClientSession().clientID);
if (targetIsActive) {
isPcOnline = true;
break;
}
}
}
}
for (Session targetSession : sessions) {
//超过7天不活跃的用户忽略
if(System.currentTimeMillis() - targetSession.getLastActiveTime() > 7 * 24 * 60 * 60 * 1000) {
@@ -251,6 +267,11 @@ public class MessagesPublisher {
LOG.info("The user {} is global sliented", user);
isSlient = true;
}
if (isPcOnline && m_messagesStore.getSilentWhenPcOnline(user)) {
LOG.info("The user {} pc online and silent when pc online", user);
isSlient = true;
}
}
if (!StringUtil.isNullOrEmpty(pushContent) || messageContentType == 400) {
@@ -12,6 +12,7 @@ public interface UserSettingScope {
int kUserSettingMyChannels = 8;
int kUserSettingListenedChannels = 9;
int kUserSettingPCOnline = 10;
int kUserSettingMuteWhenPCOnline = 15;
int kUserSettingCustomBegin = 1000;
}