NIMSDK-AOS  10.11.10
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  NimLog.i(TAG, "parse json string err when " + i, e);
61  return new ArrayList<>(0);
62  }
63  }
64 
65  /**
66  * 从Property中获取MessageKey
67  *
68  * @param property {@link ITalkExtensionService.QuickCommentResponseTag}
69  * @return MessageKey
70  */
71  private static MessageKey getMessageKey(Property property) {
72  SessionTypeEnum sessionType = SessionTypeEnum.typeOfValue(property.getInteger(ITalkExtensionService.QuickCommentResponseTag.toType));
73  String fromAccount = property.get(ITalkExtensionService.QuickCommentResponseTag.fromAccount);
74  String toAccount = property.get(ITalkExtensionService.QuickCommentResponseTag.toAccount);
75  long time = property.getLong(ITalkExtensionService.QuickCommentResponseTag.time);
76  long serverId = property.getLong(ITalkExtensionService.QuickCommentResponseTag.msgid_server);
77  String uuid = property.get(ITalkExtensionService.QuickCommentResponseTag.msgid_client);
78  return new MessageKey(sessionType, fromAccount, toAccount, time, serverId, uuid);
79  }
80 
81  public MessageKey getKey() {
82  return key;
83  }
84 
85  public ArrayList<QuickCommentOption> getQuickCommentList() {
86  return quickCommentList;
87  }
88 
89  public boolean isModify() {
90  return modify;
91  }
92 
93  public long getTime() {
94  return time;
95  }
96 }
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