NIMSDK-AOS  9.21.10
NIMMessagePushConfig.java
浏览该文件的文档.
1 package com.netease.nimlib.sdk.msg.config;
2 
3 import com.netease.nimlib.log.NimLog;
4 import com.netease.nimlib.util.EncryptUtil;
5 import java.io.Serializable;
6 import java.util.List;
7 
8 /**
9  * NIMMessagePushConfig 类
10  * <p>
11  * 该类用于配置网易云信消息推送的相关参数。
12  * 它实现了 Serializable 接口,可以进行序列化。
13  */
14 public class NIMMessagePushConfig implements Serializable {
15 
16  /**
17  * 是否需要推送消息。
18  */
19  private final boolean pushEnabled;
20 
21  /**
22  * 是否需要推送消息发送者昵称。
23  */
24  private final boolean pushNickEnabled;
25 
26  /**
27  * 推送文案
28  */
29  private final String pushContent;
30 
31  /**
32  * 推送数据
33  */
34  private final String pushPayload;
35 
36  /**
37  * 强制推送,忽略用户消息提醒相关设置,只对消息类型有效
38  */
39  private final boolean forcePush;
40 
41  /**
42  * 强制推送文案,只对消息类型有效
43  */
44  private final String forcePushContent;
45 
46  /**
47  * 强制推送目标账号列表,只对消息类型有效
48  */
49  private final List<String> forcePushAccountIds;
50 
51 
52  /**
53  * 私有构造函数
54  * 使用默认值初始化对象
55  */
56  private NIMMessagePushConfig() {
57  this(DEFAULT_PUSH_ENABLE, DEFAULT_PUSH_NICK_ENABLE, null, null, false, null, null);
58  }
59 
60  /**
61  * 私有构造函数
62  *
63  * @param pushEnabled 是否启用推送
64  * @param pushNickEnabled 是否推送发送者昵称
65  * @param pushContent 推送内容
66  * @param pushPayload 推送数据
67  * @param forcePush 是否强制推送
68  * @param forcePushContent 强制推送内容
69  * @param forcePushAccountIds 强制推送目标账号列表
70  */
71  private NIMMessagePushConfig(boolean pushEnabled, boolean pushNickEnabled, String pushContent, String pushPayload, boolean forcePush,
72  String forcePushContent, List<String> forcePushAccountIds) {
73  this.pushEnabled = pushEnabled;
74  this.pushNickEnabled = pushNickEnabled;
75  this.pushContent = pushContent;
76  this.pushPayload = pushPayload;
77  this.forcePush = forcePush;
78  this.forcePushContent = forcePushContent;
79  this.forcePushAccountIds = forcePushAccountIds;
80  }
81 
82  /**
83  * 获取是否启用推送
84  *
85  * @return 是否启用推送
86  */
87  public boolean isPushEnabled() {
88  return pushEnabled;
89  }
90 
91  /**
92  * 获取是否推送发送者昵称
93  *
94  * @return 是否推送发送者昵称
95  */
96  public boolean isPushNickEnabled() {
97  return pushNickEnabled;
98  }
99 
100  /**
101  * 获取推送内容
102  *
103  * @return 推送内容
104  */
105  public String getPushContent() {
106  return pushContent;
107  }
108 
109  /**
110  * 获取推送数据
111  *
112  * @return 推送数据
113  */
114  public String getPushPayload() {
115  return pushPayload;
116  }
117 
118  /**
119  * 获取是否强制推送
120  *
121  * @return 是否强制推送
122  */
123  public boolean isForcePush() {
124  return forcePush;
125  }
126 
127  /**
128  * 获取强制推送内容
129  *
130  * @return 强制推送内容
131  */
132  public String getForcePushContent() {
133  return forcePushContent;
134  }
135 
136  /**
137  * 获取强制推送目标账号列表
138  *
139  * @return 强制推送目标账号列表
140  */
141  public List<String> getForcePushAccountIds() {
142  return forcePushAccountIds;
143  }
144 
145  /**
146  * 重写toString方法
147  *
148  * @return 对象的字符串表示
149  */
150  @Override
151  public String toString() {
152  if (NimLog.isDebugLog()) {
153  return "NIMMessagePushConfig{" + "pushEnabled=" + pushEnabled + ", pushNickEnabled=" + pushNickEnabled + ", content='" + pushContent + '\''
154  + ", payload='" + pushPayload + '\'' + ", forcePush=" + forcePush + ", forcePushContent='" + forcePushContent + '\''
155  + ", forcePushAccountIds=" + forcePushAccountIds + '}';
156  }
157  else {
158  return "NIMMessagePushConfig{" + "pushEnabled=" + pushEnabled + ", pushNickEnabled=" + pushNickEnabled + ", content='"
159  + EncryptUtil.encryptBase64(pushContent) + '\'' + ", payload='" + EncryptUtil.encryptBase64(pushPayload) + '\'' + ", forcePush=" + forcePush
160  + ", forcePushContent='" + "*******" + '\'' + ", forcePushAccountIds=" + forcePushAccountIds + '}';
161  }
162 
163  }
164 
165  public static final boolean DEFAULT_PUSH_ENABLE = true;
166  public static final boolean DEFAULT_PUSH_NICK_ENABLE = true;
167 
168  /**
169  * NIMMessagePushConfigBuilder 内部类
170  * <p>
171  * 用于构建 NIMMessagePushConfig 对象的 Builder 类
172  */
173  public static final class NIMMessagePushConfigBuilder {
174 
175  private boolean pushEnabled = DEFAULT_PUSH_ENABLE;
176  private boolean pushNickEnabled = DEFAULT_PUSH_NICK_ENABLE;
177  private String content;
178  private String payload;
179  private boolean forcePush;
180  private String forcePushContent;
181  private List<String> forcePushAccountIds;
182 
183  private NIMMessagePushConfigBuilder() {
184  }
185 
186  /**
187  * 创建 NIMMessagePushConfigBuilder 实例
188  *
189  * @return NIMMessagePushConfigBuilder 实例
190  */
191  public static NIMMessagePushConfigBuilder builder() {
192  return new NIMMessagePushConfigBuilder();
193  }
194 
195  /**
196  * 设置是否启用推送
197  *
198  * @param pushEnabled 是否启用推送
199  *
200  * @return NIMMessagePushConfigBuilder 实例
201  */
202  public NIMMessagePushConfigBuilder withPushEnabled(boolean pushEnabled) {
203  this.pushEnabled = pushEnabled;
204  return this;
205  }
206 
207  /**
208  * 设置是否推送发送者昵称
209  *
210  * @param pushNickEnabled 是否推送发送者昵称
211  *
212  * @return NIMMessagePushConfigBuilder 实例
213  */
214  public NIMMessagePushConfigBuilder withPushNickEnabled(boolean pushNickEnabled) {
215  this.pushNickEnabled = pushNickEnabled;
216  return this;
217  }
218 
219  /**
220  * 设置推送内容
221  *
222  * @param content 推送内容
223  *
224  * @return NIMMessagePushConfigBuilder 实例
225  */
226  public NIMMessagePushConfigBuilder withContent(String content) {
227  this.content = content;
228  return this;
229  }
230 
231  /**
232  * 设置推送数据
233  *
234  * @param payload 推送数据
235  *
236  * @return NIMMessagePushConfigBuilder 实例
237  */
238  public NIMMessagePushConfigBuilder withPayload(String payload) {
239  this.payload = payload;
240  return this;
241  }
242 
243  /**
244  * 设置是否强制推送
245  *
246  * @param forcePush 是否强制推送
247  *
248  * @return NIMMessagePushConfigBuilder 实例
249  */
250  public NIMMessagePushConfigBuilder withForcePush(boolean forcePush) {
251  this.forcePush = forcePush;
252  return this;
253  }
254 
255  /**
256  * 设置强制推送内容
257  *
258  * @param forcePushContent 强制推送内容
259  *
260  * @return NIMMessagePushConfigBuilder 实例
261  */
262  public NIMMessagePushConfigBuilder withForcePushContent(String forcePushContent) {
263  this.forcePushContent = forcePushContent;
264  return this;
265  }
266 
267  /**
268  * 设置强制推送目标账号列表
269  *
270  * @param forcePushAccountIds 强制推送目标账号列表
271  *
272  * @return NIMMessagePushConfigBuilder 实例
273  */
274  public NIMMessagePushConfigBuilder withForcePushAccountIds(List<String> forcePushAccountIds) {
275  this.forcePushAccountIds = forcePushAccountIds;
276  return this;
277  }
278 
279  /**
280  * 构建 NIMMessagePushConfig 对象
281  *
282  * @return NIMMessagePushConfig 对象
283  */
284  public NIMMessagePushConfig build() {
285  return new NIMMessagePushConfig(pushEnabled, pushNickEnabled, content, payload, forcePush, forcePushContent, forcePushAccountIds);
286  }
287  }
288 }
List< String > getForcePushAccountIds()
获取强制推送目标账号列表
boolean isPushNickEnabled()
获取是否推送发送者昵称