NIMSDK-AOS  9.19.0
QuickCommentOptionWrapper.java
浏览该文件的文档.
1 package com.netease.nimlib.sdk.msg.model;
2 
3 import android.text.TextUtils;
4 
5 import com.netease.nimlib.biz.constant.ITalkExtensionService;
6 import com.netease.nimlib.log.NimLog;
7 import com.netease.nimlib.push.packet.marshal.Property;
9 
10 import org.json.JSONArray;
11 import org.json.JSONException;
12 import org.json.JSONObject;
13 
14 import java.io.Serializable;
15 import java.util.ArrayList;
16 
17 /**
18  * @author chenjili
19  * @date 2020/4/2
20  * @see ITalkExtensionService.QuickCommentResponseTag
21  */
22 public class QuickCommentOptionWrapper implements Serializable {
23  private static final String TAG = "QuickCommentOptionWrapper";
24  private MessageKey key;
25  private ArrayList<QuickCommentOption> quickCommentList;
26  private boolean modify;
27  private long time;
28 
29  public QuickCommentOptionWrapper(MessageKey key, ArrayList<QuickCommentOption> quickCommentList, boolean modify, long time) {
30  this.key = key;
31  this.modify = modify;
32  this.time = time;
33  this.quickCommentList = quickCommentList;
34  }
35 
36  public static QuickCommentOptionWrapper fromProperty(Property property) {
37  MessageKey key = getMessageKey(property);
38  boolean modify = property.getInteger(ITalkExtensionService.QuickCommentResponseTag.modify) == 1;
39  long time = property.getLong(ITalkExtensionService.QuickCommentResponseTag.timestamp);
40  ArrayList<QuickCommentOption> quickCommentList = getCommentListFromJsonStr(property.get(ITalkExtensionService.QuickCommentResponseTag.detail));
41  return new QuickCommentOptionWrapper(key, quickCommentList, modify, time);
42  }
43 
44  private static ArrayList<QuickCommentOption> getCommentListFromJsonStr(String jsonStr) {
45  if (TextUtils.isEmpty(jsonStr)) {
46  return new ArrayList<>(0);
47  }
48  int i = 0;
49  try {
50  final JSONArray array = new JSONArray(jsonStr);
51  final int len = array.length();
52  ArrayList<QuickCommentOption> result = new ArrayList<>(len);
53  for (i = 0; i < len; ++i) {
54  JSONObject obj = (JSONObject) array.get(i);
56  result.add(option);
57  }
58  return result;
59  } catch (JSONException e) {
60  e.printStackTrace();
61  NimLog.i(TAG, "parse json string err when " + i);
62  return new ArrayList<>(0);
63  }
64  }
65 
66  /**
67  * 从Property中获取MessageKey
68  *
69  * @param property {@link ITalkExtensionService.QuickCommentResponseTag}
70  * @return MessageKey
71  */
72  private static MessageKey getMessageKey(Property property) {
73  SessionTypeEnum sessionType = SessionTypeEnum.typeOfValue(property.getInteger(ITalkExtensionService.QuickCommentResponseTag.toType));
74  String fromAccount = property.get(ITalkExtensionService.QuickCommentResponseTag.fromAccount);
75  String toAccount = property.get(ITalkExtensionService.QuickCommentResponseTag.toAccount);
76  long time = property.getLong(ITalkExtensionService.QuickCommentResponseTag.time);
77  long serverId = property.getLong(ITalkExtensionService.QuickCommentResponseTag.msgid_server);
78  String uuid = property.get(ITalkExtensionService.QuickCommentResponseTag.msgid_client);
79  return new MessageKey(sessionType, fromAccount, toAccount, time, serverId, uuid);
80  }
81 
82  public MessageKey getKey() {
83  return key;
84  }
85 
86  public ArrayList<QuickCommentOption> getQuickCommentList() {
87  return quickCommentList;
88  }
89 
90  public boolean isModify() {
91  return modify;
92  }
93 
94  public long getTime() {
95  return time;
96  }
97 }
static QuickCommentOptionWrapper fromProperty(Property property)
QuickCommentOptionWrapper(MessageKey key, ArrayList< QuickCommentOption > quickCommentList, boolean modify, long time)
static QuickCommentOption fromJson(final JSONObject obj)
消息的关键信息,通过这些信息可以从服务端查询到该消息的完整部分
Definition: MessageKey.java:17