NIMSDK-AOS  10.9.90
V2NIMTopicListOption.java
浏览该文件的文档.
1 package com.netease.nimlib.sdk.v2.topic.option;
2 
3 import android.text.TextUtils;
5 
6 /**
7  * Topic 列表查询参数。
8  *
9  * <p>用于按会话、时间范围和方向分页查询 Topic 列表。</p>
10  */
11 public class V2NIMTopicListOption {
12  /**
13  * 单次查询上限最大值。
14  */
15  public static final int MAX_LIMIT = 100;
16  /**
17  * 目标会话 ID。
18  */
19  private final String conversationId;
20  /**
21  * 查询起始时间,单位毫秒。
22  */
23  private final long beginTime;
24  /**
25  * 查询结束时间,单位毫秒,0 表示不限制。
26  */
27  private final long endTime;
28  /**
29  * 分页 token,首次查询可传空。
30  */
31  private final String nextToken;
32  /**
33  * 单次查询上限。
34  */
35  private final int limit;
36  /**
37  * 查询方向,传空时默认为倒序方向。
38  */
39  private final V2NIMQueryDirection direction;
40 
41  /**
42  * 构造 Topic 列表查询参数。
43  *
44  * @param conversationId 会话 ID
45  * @param beginTime 查询起始时间,单位毫秒
46  * @param endTime 查询结束时间,单位毫秒,0 表示不限制
47  * @param nextToken 分页 token
48  * @param limit 单次查询上限
49  * @param direction 查询方向,传空时默认 {@link V2NIMQueryDirection#V2NIM_QUERY_DIRECTION_DESC}
50  */
51  public V2NIMTopicListOption(String conversationId, long beginTime, long endTime, String nextToken, int limit, V2NIMQueryDirection direction) {
52  this.conversationId = conversationId;
53  this.beginTime = beginTime;
54  this.endTime = endTime;
55  this.nextToken = nextToken;
56  this.limit = limit;
57  this.direction = direction == null ? V2NIMQueryDirection.V2NIM_QUERY_DIRECTION_DESC : direction;
58  }
59 
60  /**
61  * 返回会话 ID。
62  *
63  * @return 会话 ID
64  */
65  public String getConversationId() {
66  return conversationId;
67  }
68 
69  /**
70  * 返回起始时间。
71  *
72  * @return 起始时间,单位毫秒
73  */
74  public long getBeginTime() {
75  return beginTime;
76  }
77 
78  /**
79  * 返回结束时间。
80  *
81  * @return 结束时间,单位毫秒
82  */
83  public long getEndTime() {
84  return endTime;
85  }
86 
87  /**
88  * 返回分页 token。
89  *
90  * @return 分页 token
91  */
92  public String getNextToken() {
93  return nextToken;
94  }
95 
96  /**
97  * 返回查询上限。
98  *
99  * @return 单次查询上限
100  */
101  public int getLimit() {
102  return limit;
103  }
104 
105  /**
106  * 返回查询方向。
107  *
108  * @return 查询方向
109  */
111  return direction;
112  }
113 
114  /**
115  * 返回参数非法原因。
116  *
117  * @return 参数合法时返回 `null`,否则返回具体错误原因
118  */
119  public String isValidWithErrorMsg() {
120  if (TextUtils.isEmpty(conversationId)) {
121  return "conversationId is empty";
122  }
123  if (limit <= 0) {
124  return "limit must be greater than 0";
125  }
126  if (limit > MAX_LIMIT) {
127  return "limit must be less than or equal to " + MAX_LIMIT;
128  }
129  if (beginTime < 0) {
130  return "beginTime must be greater than or equal to 0";
131  }
132  if (endTime < 0) {
133  return "endTime must be greater than or equal to 0";
134  }
135  if (endTime != 0 && beginTime > endTime) {
136  return "beginTime must be less than or equal to endTime";
137  }
138  return null;
139  }
140 
141  /**
142  * 参数是否合法。
143  *
144  * @return `true` 表示参数合法,否则为 `false`
145  */
146  public boolean isValid() {
147  return isValidWithErrorMsg() == null;
148  }
149 }
static final int MAX_LIMIT
单次查询上限最大值。
V2NIMTopicListOption(String conversationId, long beginTime, long endTime, String nextToken, int limit, V2NIMQueryDirection direction)
构造 Topic 列表查询参数。
V2NIMQueryDirection getDirection()
返回查询方向。