NIMSDK-AOS  9.16.0
ChatRoomTagsUpdateEventImpl.java
浏览该文件的文档.
1 package com.netease.nimlib.sdk.chatroom.model;
2 
3 import com.netease.nimlib.biz.constant.IChatRoomService;
4 import com.netease.nimlib.log.NimLog;
5 import com.netease.nimlib.push.packet.marshal.Property;
6 import com.netease.nimlib.util.StringUtil;
7 
8 import org.json.JSONArray;
9 
10 import java.util.ArrayList;
11 import java.util.List;
12 
14 
15  private static final String TAG = "ChatRoomTagsUpdateEventImpl";
16  private final String roomId;
17  private final List<String> tags;
18 
19  public ChatRoomTagsUpdateEventImpl(String roomId, Property tagsProperty) {
20  this.roomId = roomId;
21  this.tags = new ArrayList<>();
22  String tagsString = tagsProperty.get(IChatRoomService.ChatRoomTagUpdateChatroomTag.CURRENT_TAGS);
23  if (!StringUtil.isNotEmpty(tagsString)) {
24  return;
25  }
26  JSONArray tagArray = null;
27  try {
28  tagArray = new JSONArray(tagsString);
29  } catch (Throwable e) {
30  NimLog.w(TAG, "the format of tags is unexpected. " + tagsString);
31  }
32  if (tagArray == null) {
33  return;
34  }
35  int len = tagArray.length();
36  for (int i = 0; i < len; ++i) {
37  String tag = tagArray.optString(i);
38  if (tag != null) {
39  this.tags.add(tag);
40  }
41  }
42  }
43 
44  @Override
45  public String getRoomId() {
46  return roomId;
47  }
48 
49  @Override
50  public List<String> getTags() {
51  return tags;
52  }
53 
54  @Override
55  public String toString() {
56  return "ChatRoomTagsUpdateEventImpl{" +
57  "roomId='" + roomId + '\'' +
58  ", tags=" + tags +
59  '}';
60  }
61 }