NIMSDK-AOS  10.9.90
V2NIMUpdateTopicParams.java
浏览该文件的文档.
1 package com.netease.nimlib.sdk.v2.topic.params;
2 
3 import android.text.TextUtils;
5 
6 /**
7  * 更新 Topic 参数。
8  */
9 public class V2NIMUpdateTopicParams {
10  private static final int MAX_TOPIC_NAME_LENGTH = 128;
11 
12  /**
13  * 待更新的 Topic。
14  */
15  private final V2NIMTopic topic;
16  /**
17  * 新的 Topic 名称。
18  */
19  private final String topicName;
20  /**
21  * 新的服务端扩展字段。
22  */
23  private final String serverExtension;
24 
25  /**
26  * 构造更新 Topic 参数。
27  *
28  * @param topic 待更新的 Topic
29  * @param topicName 新的 Topic 名称,最大长度为 128 个字符
30  * @param serverExtension 新的服务端扩展字段
31  */
32  public V2NIMUpdateTopicParams(V2NIMTopic topic, String topicName, String serverExtension) {
33  this.topic = topic;
34  this.topicName = topicName;
35  this.serverExtension = serverExtension;
36  }
37 
38  /**
39  * 返回待更新的 Topic。
40  *
41  * @return 待更新的 Topic
42  */
43  public V2NIMTopic getTopic() {
44  return topic;
45  }
46 
47  /**
48  * 返回新的 Topic 名称。
49  *
50  * @return 新的 Topic 名称,最大长度为 128 个字符
51  */
52  public String getTopicName() {
53  return topicName;
54  }
55 
56  /**
57  * 返回新的服务端扩展字段。
58  *
59  * @return 新的服务端扩展字段
60  */
61  public String getServerExtension() {
62  return serverExtension;
63  }
64 
65  /**
66  * 返回参数非法原因。
67  *
68  * @return 参数合法时返回 `null`,否则返回具体错误原因
69  */
70  public String isValidWithErrorMsg() {
71  if (topic == null) {
72  return "topic is null";
73  }
74  if (TextUtils.isEmpty(topic.getConversationId())) {
75  return "topic conversationId is empty";
76  }
77  if (topic.getTopicId() <= 0) {
78  return "topicId must be greater than 0";
79  }
80  if (topic.getCreateTime() <= 0) {
81  return "topic createTime must be greater than 0";
82  }
83  if (topicName == null && serverExtension == null) {
84  return "topicName and serverExtension cannot both be null";
85  }
86  if (topicName != null && topicName.length() > MAX_TOPIC_NAME_LENGTH) {
87  return "topicName length must be less than or equal to 128";
88  }
89  return null;
90  }
91 
92  /**
93  * 参数是否合法。
94  *
95  * @return `true` 表示参数合法,否则为 `false`
96  */
97  public boolean isValid() {
98  return isValidWithErrorMsg() == null;
99  }
100 }
V2NIMUpdateTopicParams(V2NIMTopic topic, String topicName, String serverExtension)
构造更新 Topic 参数。
String getConversationId()
返回 Topic 所属会话 ID。
String getServerExtension()
返回新的服务端扩展字段。
long getCreateTime()
返回 Topic 创建时间。