NIMSDK-AOS  10.6.0
ChatRoomNotificationAttachment.java
浏览该文件的文档.
1 package com.netease.nimlib.sdk.chatroom.model;
2 
3 import androidx.annotation.NonNull;
4 
5 import com.netease.nimlib.log.model.LogDesensitizationConfigHelper;
7 import com.netease.nimlib.session.MsgHelper;
8 import com.netease.nimlib.util.JSONHelper;
9 
10 import org.json.JSONArray;
11 import org.json.JSONObject;
12 
13 import java.util.ArrayList;
14 import java.util.Map;
15 
20 
21  private static final String TAG_TARGET = "target";
22  private static final String TAG_TARGET_NICK = "tarNick";
23  private static final String TAG_OPERATOR = "operator";
24  private static final String TAG_OPERATOR_NICK = "opeNick";
25  private static final String TAG_EXTENSION = "ext";
26  private static final String TAG_TAGS = "tags";
27 
31  private ArrayList<String> targets;
32 
36  private ArrayList<String> targetNicks;
37 
41  private String operator;
42 
46  private String operatorNick;
47 
51  private Map<String, Object> extension;
55  private ArrayList<String> tags;
56 
57  public ArrayList<String> getTargets() {
58  return targets;
59  }
60 
61  public ArrayList<String> getTargetNicks() {
62  return targetNicks;
63  }
64 
65  public String getOperator() {
66  return operator;
67  }
68 
69  public String getOperatorNick() {
70  return operatorNick;
71  }
72 
73  public Map<String, Object> getExtension() {
74  return extension;
75  }
76 
77  public ArrayList<String> getTags() {
78  return tags;
79  }
80 
81  @Override
82  public void parse(JSONObject json) {
83  if (json.has(TAG_TARGET)) {
84  JSONArray array = JSONHelper.getJSONArray(json, TAG_TARGET);
85  targets = new ArrayList<>(array.length());
86  for (int i = 0; i < array.length(); ++i) {
87  targets.add(JSONHelper.getString(array, i));
88  }
89  }
90 
91  if (json.has(TAG_TARGET_NICK)) {
92  JSONArray array = JSONHelper.getJSONArray(json, TAG_TARGET_NICK);
93  targetNicks = new ArrayList<>(array.length());
94  for (int i = 0; i < array.length(); ++i) {
95  targetNicks.add(JSONHelper.getString(array, i));
96  }
97  }
98 
99  if (json.has(TAG_OPERATOR)) {
100  operator = JSONHelper.getString(json, TAG_OPERATOR);
101  }
102 
103  if (json.has(TAG_OPERATOR_NICK)) {
104  operatorNick = JSONHelper.getString(json, TAG_OPERATOR_NICK);
105  }
106 
107  if (json.has(TAG_EXTENSION)) {
108  extension = MsgHelper.getMapFromJsonString(JSONHelper.getString(json, TAG_EXTENSION));
109  }
110 
111  if (json.has(TAG_TAGS)) {
112  String tagsString = JSONHelper.getString(json, TAG_TAGS);
113  JSONArray array = JSONHelper.parseArray(tagsString);
114  if (array != null) {
115  tags = new ArrayList<>(array.length());
116  for (int i = 0; i < array.length(); ++i) {
117  tags.add(JSONHelper.getString(array, i));
118  }
119  }
120  }
121  }
122 
123  @NonNull
124  @Override
125  public String toString() {
126  return "ChatRoomNotificationAttachment{" +
127  "targets=" + (targets == null ? "null" : targets.toString()) +
128  ", targetNicks=" + (targetNicks == null ? "null" : LogDesensitizationConfigHelper.getPrintTextOfNick(targetNicks.toString())) +
129  ", operator='" + operator + '\'' +
130  ", operatorNick='" + LogDesensitizationConfigHelper.getPrintTextOfNick(operatorNick) + '\'' +
131  ", extension=" + extension +
132  ", tags=" + (tags == null ? "null" : tags.toString()) +
133  '}';
134  }
135 }