NIMSDK-AOS  10.5.0
QuickCommentOption.java
浏览该文件的文档.
1 package com.netease.nimlib.sdk.msg.model;
2 
3 import com.netease.nimlib.biz.constant.ITalkExtensionService;
4 import com.netease.nimlib.push.packet.marshal.Property;
5 import com.netease.nimlib.session.MsgHelper;
6 
7 import org.json.JSONObject;
8 
9 import java.io.Serializable;
10 import java.util.Map;
11 
19 public class QuickCommentOption implements Serializable {
20  private final String fromAccount;
21  private final long replyType;
22  private final long time;
23  private final String ext;
24  private final boolean needPush;
25  private final boolean needBadge;
26  private final String pushTitle;
27  private final String pushContent;
28  private final Map<String, Object> pushPayloadMap;
29  private final String pushPayload;
30 
31  public static QuickCommentOption fromProperty(Property property) {
32  String fromAccount = property.get(ITalkExtensionService.QuickCommentTag.fromAccount);
33  long replyType = property.getLong(ITalkExtensionService.QuickCommentTag.replyType);
34  long time = property.getLong(ITalkExtensionService.QuickCommentTag.time);
35  String ext = property.get(ITalkExtensionService.QuickCommentTag.ext);
36  boolean needPush = property.getInteger(ITalkExtensionService.QuickCommentTag.needPush) == 1;
37  boolean needBadge = property.getInteger(ITalkExtensionService.QuickCommentTag.needBadge) == 1;
38  String pushTitle = property.get(ITalkExtensionService.QuickCommentTag.pushTitle);
39  String pushContent = property.get(ITalkExtensionService.QuickCommentTag.pushContent);
40  String pushPayload = property.get(ITalkExtensionService.QuickCommentTag.pushPayload);
41  Map<String, Object> pushPayloadMap = MsgHelper.getMapFromJsonString(pushPayload);
42  return new QuickCommentOption(fromAccount, replyType, time, ext, needPush, needBadge, pushTitle, pushContent, pushPayloadMap, pushPayload);
43  }
44 
45  public static QuickCommentOption fromJson(final JSONObject obj) {
46  String fromAccount = obj.optString(String.valueOf(ITalkExtensionService.QuickCommentTag.fromAccount));
47  long replyType = obj.optLong(String.valueOf(ITalkExtensionService.QuickCommentTag.replyType));
48  long time = obj.optLong(String.valueOf(ITalkExtensionService.QuickCommentTag.time));
49  String ext = obj.optString(String.valueOf(ITalkExtensionService.QuickCommentTag.ext));
50  boolean needPush = obj.optInt(String.valueOf(ITalkExtensionService.QuickCommentTag.needPush)) == 1;
51  boolean needBadge = obj.optInt(String.valueOf(ITalkExtensionService.QuickCommentTag.needBadge)) == 1;
52  String pushTitle = obj.optString(String.valueOf(ITalkExtensionService.QuickCommentTag.pushTitle));
53  String pushContent = obj.optString(String.valueOf(ITalkExtensionService.QuickCommentTag.pushContent));
54  String pushPayload = obj.optString(String.valueOf(ITalkExtensionService.QuickCommentTag.pushPayload));
55  Map<String, Object> pushPayloadMap = MsgHelper.getMapFromJsonString(pushPayload);
56  return new QuickCommentOption(fromAccount, replyType, time, ext, needPush, needBadge, pushTitle, pushContent, pushPayloadMap, pushPayload);
57  }
58 
59  public QuickCommentOption(String fromAccount, long replyType, long time, String ext) {
60  this(fromAccount, replyType, time, ext, false, false, "", "", null, "");
61  }
62 
63  public QuickCommentOption(String fromAccount, long replyType, long time, String ext, boolean needPush,
64  boolean needBadge, String pushTitle, String pushContent, Map<String, Object> pushPayload) {
65  this(fromAccount, replyType, time, ext, needPush, needBadge, pushTitle, pushContent, pushPayload, pushContent == null ? "" : MsgHelper.getJsonStringFromMap(pushPayload));
66  }
67 
68  public QuickCommentOption(String fromAccount, long replyType, long time, String ext, boolean needPush,
69  boolean needBadge, String pushTitle, String pushContent, String pushPayload) {
70  this(fromAccount, replyType, time, ext, needPush, needBadge, pushTitle, pushContent, null, pushPayload);
71  }
72 
73  private QuickCommentOption(String fromAccount, long replyType, long time, String ext, boolean needPush,
74  boolean needBadge, String pushTitle, String pushContent, Map<String, Object> pushPayloadMap, String pushPayload) {
75  this.fromAccount = fromAccount;
76  this.replyType = replyType;
77  this.time = time;
78  this.ext = ext;
79  this.needPush = needPush;
80  this.needBadge = needBadge;
81  this.pushTitle = pushTitle;
82  this.pushContent = pushContent;
83  this.pushPayloadMap = pushPayloadMap;
84  this.pushPayload = pushPayload;
85  }
86 
87  public String getFromAccount() {
88  return fromAccount;
89  }
90 
91  public long getReplyType() {
92  return replyType;
93  }
94 
95  public long getTime() {
96  return time;
97  }
98 
99  public String getExt() {
100  return ext;
101  }
102 
103  public boolean isNeedPush() {
104  return needPush;
105  }
106 
107  public boolean isNeedBadge() {
108  return needBadge;
109  }
110 
111  public String getPushTitle() {
112  return pushTitle;
113  }
114 
115  public String getPushContent() {
116  return pushContent;
117  }
118 
119  // V2不再限制pushPayload的格式,可以为任意字符串
120  // 通过V2添加的QuickComment请使用getPushPayloadV2来获取pushPayload
121  @Deprecated
122  public Map<String, Object> getPushPayload() {
123  return pushPayloadMap;
124  }
125 
126  public String getPushPayloadV2() {
127  return pushPayload;
128  }
129 }
QuickCommentOption(String fromAccount, long replyType, long time, String ext)
QuickCommentOption(String fromAccount, long replyType, long time, String ext, boolean needPush, boolean needBadge, String pushTitle, String pushContent, Map< String, Object > pushPayload)
static QuickCommentOption fromProperty(Property property)
QuickCommentOption(String fromAccount, long replyType, long time, String ext, boolean needPush, boolean needBadge, String pushTitle, String pushContent, String pushPayload)
static QuickCommentOption fromJson(final JSONObject obj)