添加免打扰功能及优化推送逻辑
This commit is contained in:
@@ -2914,7 +2914,7 @@ public class MemoryMessagesStore implements IMessagesStore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean getUserGlobalSlient(String userId) {
|
public boolean getUserGlobalSilent(String userId) {
|
||||||
Boolean slient = userGlobalSlientMap.get(userId);
|
Boolean slient = userGlobalSlientMap.get(userId);
|
||||||
if (slient == null) {
|
if (slient == null) {
|
||||||
WFCMessage.UserSettingEntry entry = getUserSetting(userId, UserSettingScope.kUserSettingGlobalSilent, null);
|
WFCMessage.UserSettingEntry entry = getUserSetting(userId, UserSettingScope.kUserSettingGlobalSilent, null);
|
||||||
@@ -2944,7 +2944,7 @@ public class MemoryMessagesStore implements IMessagesStore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean getUserConversationSlient(String userId, WFCMessage.Conversation conversation) {
|
public boolean getUserConversationSilent(String userId, WFCMessage.Conversation conversation) {
|
||||||
String key = userId + "|" + conversation.getType() + "|" + conversation.getTarget() + "|" + conversation.getLine();
|
String key = userId + "|" + conversation.getType() + "|" + conversation.getTarget() + "|" + conversation.getLine();
|
||||||
Boolean slient = userConvSlientMap.get(key);
|
Boolean slient = userConvSlientMap.get(key);
|
||||||
if (slient == null) {
|
if (slient == null) {
|
||||||
@@ -2969,6 +2969,42 @@ public class MemoryMessagesStore implements IMessagesStore {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private Date getTodayDate() {
|
||||||
|
Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
|
||||||
|
int year = calendar.get(Calendar.YEAR);
|
||||||
|
int month = calendar.get(Calendar.MONTH);
|
||||||
|
int day = calendar.get(Calendar.DATE);
|
||||||
|
calendar.set(year, month, day, 0, 0, 0);
|
||||||
|
return calendar.getTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isUserNoDisturbing(String userId) {
|
||||||
|
WFCMessage.UserSettingEntry entry = getUserSetting(userId, UserSettingScope.kUserSettingNoDisturbing, "");
|
||||||
|
if (entry != null && !StringUtil.isNullOrEmpty(entry.getValue())) {
|
||||||
|
String[] arr = entry.getValue().split("\\|");
|
||||||
|
|
||||||
|
if (arr.length == 2) {
|
||||||
|
int nowMins = (int)((System.currentTimeMillis() - getTodayDate().getTime())/1000/60);
|
||||||
|
try {
|
||||||
|
int startMins = Integer.parseInt(arr[0]);
|
||||||
|
int endMins = Integer.parseInt(arr[1]);
|
||||||
|
if (endMins > startMins) {
|
||||||
|
if (endMins > nowMins && nowMins > startMins) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (endMins > nowMins || nowMins > startMins) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ErrorCode createChannel(String operator, WFCMessage.ChannelInfo channelInfo) {
|
public ErrorCode createChannel(String operator, WFCMessage.ChannelInfo channelInfo) {
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ import io.netty.handler.codec.mqtt.MqttQoS;
|
|||||||
import cn.wildfirechat.common.ErrorCode;
|
import cn.wildfirechat.common.ErrorCode;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@@ -184,12 +185,12 @@ public interface IMessagesStore {
|
|||||||
List<WFCMessage.UserSettingEntry> getUserSetting(String userId, int scope);
|
List<WFCMessage.UserSettingEntry> getUserSetting(String userId, int scope);
|
||||||
long updateUserSettings(String userId, WFCMessage.ModifyUserSettingReq request);
|
long updateUserSettings(String userId, WFCMessage.ModifyUserSettingReq request);
|
||||||
void clearUserSettings(String userId);
|
void clearUserSettings(String userId);
|
||||||
|
boolean getUserGlobalSilent(String userId);
|
||||||
|
|
||||||
boolean getUserGlobalSlient(String userId);
|
|
||||||
boolean getUserPushHiddenDetail(String userId);
|
boolean getUserPushHiddenDetail(String userId);
|
||||||
boolean getUserConversationSlient(String userId, WFCMessage.Conversation conversation);
|
boolean getUserConversationSilent(String userId, WFCMessage.Conversation conversation);
|
||||||
boolean getSilentWhenPcOnline(String userId);
|
boolean getSilentWhenPcOnline(String userId);
|
||||||
|
boolean isUserNoDisturbing(String userId);
|
||||||
ErrorCode createChannel(String operator, WFCMessage.ChannelInfo channelInfo);
|
ErrorCode createChannel(String operator, WFCMessage.ChannelInfo channelInfo);
|
||||||
void clearUserChannels(String userId);
|
void clearUserChannels(String userId);
|
||||||
ErrorCode modifyChannelInfo(String operator, String channelId, int modifyType, String value);
|
ErrorCode modifyChannelInfo(String operator, String channelId, int modifyType, String value);
|
||||||
|
|||||||
@@ -244,11 +244,13 @@ public class MessagesPublisher {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isSlient;
|
boolean isSilent;
|
||||||
|
boolean isConvSilent = false;
|
||||||
if (pullType == ProtoConstants.PullType.Pull_ChatRoom) {
|
if (pullType == ProtoConstants.PullType.Pull_ChatRoom) {
|
||||||
isSlient = true;
|
isSilent = true;
|
||||||
|
isConvSilent = true;
|
||||||
} else {
|
} else {
|
||||||
isSlient = false;
|
isSilent = false;
|
||||||
|
|
||||||
if (!user.equals(sender)) {
|
if (!user.equals(sender)) {
|
||||||
WFCMessage.Conversation conversation;
|
WFCMessage.Conversation conversation;
|
||||||
@@ -258,34 +260,32 @@ public class MessagesPublisher {
|
|||||||
conversation = WFCMessage.Conversation.newBuilder().setType(conversationType).setLine(line).setTarget(target).build();
|
conversation = WFCMessage.Conversation.newBuilder().setType(conversationType).setLine(line).setTarget(target).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (m_messagesStore.getUserConversationSilent(user, conversation)) {
|
||||||
if (m_messagesStore.getUserConversationSlient(user, conversation)) {
|
|
||||||
LOG.info("The conversation {}-{}-{} is slient", conversation.getType(), conversation.getTarget(), conversation.getLine());
|
LOG.info("The conversation {}-{}-{} is slient", conversation.getType(), conversation.getTarget(), conversation.getLine());
|
||||||
isSlient = true;
|
isConvSilent = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_messagesStore.getUserGlobalSlient(user)) {
|
if (m_messagesStore.getUserGlobalSilent(user)) {
|
||||||
LOG.info("The user {} is global sliented", user);
|
LOG.info("The user {} is global sliented", user);
|
||||||
isSlient = true;
|
isSilent = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isPcOnline && m_messagesStore.getSilentWhenPcOnline(user)) {
|
if (!isSilent && isPcOnline && m_messagesStore.getSilentWhenPcOnline(user)) {
|
||||||
LOG.info("The user {} pc online and silent when pc online", user);
|
LOG.info("The user {} pc online and silent when pc online", user);
|
||||||
isSlient = true;
|
isSilent = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isSilent && m_messagesStore.isUserNoDisturbing(user)) {
|
||||||
|
LOG.info("The user {} is no disturbing", user);
|
||||||
|
isSilent = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!StringUtil.isNullOrEmpty(pushContent) || messageContentType == 400) {
|
if (!StringUtil.isNullOrEmpty(pushContent) || messageContentType == 400) {
|
||||||
if (!isSlient && (persistFlag & 0x02) > 0) {
|
if (!isConvSilent && (persistFlag & 0x02) > 0) {
|
||||||
targetSession.setUnReceivedMsgs(targetSession.getUnReceivedMsgs() + 1);
|
targetSession.setUnReceivedMsgs(targetSession.getUnReceivedMsgs() + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isSlient) {
|
|
||||||
if (mentionType == 2 || (mentionType == 1 && mentionTargets.contains(user))) {
|
|
||||||
isSlient = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean needPush = !user.equals(sender);
|
boolean needPush = !user.equals(sender);
|
||||||
@@ -316,11 +316,11 @@ public class MessagesPublisher {
|
|||||||
int curMentionType = 0;
|
int curMentionType = 0;
|
||||||
if (mentionType == 2) {
|
if (mentionType == 2) {
|
||||||
curMentionType = 2;
|
curMentionType = 2;
|
||||||
isSlient = false;
|
isConvSilent = false;
|
||||||
} else if (mentionType == 1){
|
} else if (mentionType == 1){
|
||||||
if (mentionTargets != null && mentionTargets.contains(user)) {
|
if (mentionTargets != null && mentionTargets.contains(user)) {
|
||||||
curMentionType = 1;
|
curMentionType = 1;
|
||||||
isSlient = false;
|
isConvSilent = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -334,8 +334,13 @@ public class MessagesPublisher {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isSlient) {
|
if (isConvSilent) {
|
||||||
LOG.info("Slient of user or conversation");
|
LOG.info("Silent of user or conversation");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isSilent) {
|
||||||
|
LOG.info("Silent of user");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,16 +3,11 @@ package win.liyufan.im;
|
|||||||
public interface UserSettingScope {
|
public interface UserSettingScope {
|
||||||
int kUserSettingConversationSilent = 1;
|
int kUserSettingConversationSilent = 1;
|
||||||
int kUserSettingGlobalSilent = 2;
|
int kUserSettingGlobalSilent = 2;
|
||||||
int kUserSettingConversationTop = 3;
|
|
||||||
|
|
||||||
int kUserSettingHiddenNotificationDetail = 4;
|
int kUserSettingHiddenNotificationDetail = 4;
|
||||||
int kUserSettinGroupHideNickname = 5;
|
|
||||||
int kUserSettingFavouriteGroup = 6;
|
|
||||||
int kUserSettingConversationSync = 7;
|
int kUserSettingConversationSync = 7;
|
||||||
int kUserSettingMyChannels = 8;
|
int kUserSettingMyChannels = 8;
|
||||||
int kUserSettingListenedChannels = 9;
|
int kUserSettingListenedChannels = 9;
|
||||||
int kUserSettingPCOnline = 10;
|
int kUserSettingPCOnline = 10;
|
||||||
int kUserSettingMuteWhenPCOnline = 15;
|
int kUserSettingMuteWhenPCOnline = 15;
|
||||||
|
int kUserSettingNoDisturbing = 17;
|
||||||
int kUserSettingCustomBegin = 1000;
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user