NIMSDK-AOS  10.9.90
V2NIMMessageInsertParams.java
浏览该文件的文档.
1 package com.netease.nimlib.sdk.v2.message.params;
2 
3 /**
4  * 本地消息插入参数类
5  * 用于 insertMessageToLocalEx 接口
6  */
8 
9  /**
10  * 会话ID(必填)
11  */
12  private String conversationId;
13 
14  /**
15  * 消息发送者账号
16  * 传空表示当前用户
17  */
18  private String senderId;
19 
20  /**
21  * 指定插入消息时间
22  * 传 0 则 sdk 使用当前 ntp 时间插入
23  */
24  private long createTime;
25 
26  /**
27  * 是否需要更新会话的最后一条信息
28  * 默认为 true
29  */
30  private boolean lastMessageUpdateEnabled = true;
31 
33  }
34 
35  /**
36  * 构造函数
37  *
38  * @param conversationId 会话ID
39  * @param senderId 消息发送者账号,传空表示当前用户
40  * @param createTime 指定插入消息时间,传 0 则 sdk 使用当前 ntp 时间插入
41  * @param lastMessageUpdateEnabled 是否需要更新会话的最后一条信息
42  */
43  public V2NIMMessageInsertParams(String conversationId, String senderId, long createTime, boolean lastMessageUpdateEnabled) {
44  this.conversationId = conversationId;
45  this.senderId = senderId;
46  this.createTime = createTime;
47  this.lastMessageUpdateEnabled = lastMessageUpdateEnabled;
48  }
49 
50  /**
51  * 获取会话ID
52  *
53  * @return 会话ID
54  */
55  public String getConversationId() {
56  return conversationId;
57  }
58 
59  /**
60  * 设置会话ID
61  *
62  * @param conversationId 会话ID
63  */
64  public void setConversationId(String conversationId) {
65  this.conversationId = conversationId;
66  }
67 
68  /**
69  * 获取消息发送者账号
70  *
71  * @return 消息发送者账号,可能为 null
72  */
73  public String getSenderId() {
74  return senderId;
75  }
76 
77  /**
78  * 设置消息发送者账号
79  *
80  * @param senderId 消息发送者账号,传空表示当前用户
81  */
82  public void setSenderId(String senderId) {
83  this.senderId = senderId;
84  }
85 
86  /**
87  * 获取指定插入消息时间
88  *
89  * @return 插入消息时间
90  */
91  public long getCreateTime() {
92  return createTime;
93  }
94 
95  /**
96  * 设置指定插入消息时间
97  *
98  * @param createTime 指定插入消息时间,传 0 则 sdk 使用当前 ntp 时间插入
99  */
100  public void setCreateTime(long createTime) {
101  this.createTime = createTime;
102  }
103 
104  /**
105  * 获取是否需要更新会话的最后一条信息
106  *
107  * @return 是否需要更新会话的最后一条信息
108  */
109  public boolean isLastMessageUpdateEnabled() {
110  return lastMessageUpdateEnabled;
111  }
112 
113  /**
114  * 设置是否需要更新会话的最后一条信息
115  *
116  * @param lastMessageUpdateEnabled true: 需要,false: 不需要
117  */
118  public void setLastMessageUpdateEnabled(boolean lastMessageUpdateEnabled) {
119  this.lastMessageUpdateEnabled = lastMessageUpdateEnabled;
120  }
121 
122  /**
123  * Builder 模式构建器,用于链式创建 V2NIMMessageInsertParams 实例
124  */
125  public static class V2NIMMessageInsertParamsBuilder {
126  private String conversationId;
127  private String senderId;
128  private long createTime = 0;
129  private boolean lastMessageUpdateEnabled = true;
130 
131  private V2NIMMessageInsertParamsBuilder() {}
132 
133  public static V2NIMMessageInsertParamsBuilder builder() {
134  return new V2NIMMessageInsertParamsBuilder();
135  }
136 
137  /**
138  * 设置会话ID(必填)
139  *
140  * @param conversationId 会话ID
141  * @return Builder 自身实例
142  */
143  public V2NIMMessageInsertParamsBuilder withConversationId(String conversationId) {
144  this.conversationId = conversationId;
145  return this;
146  }
147 
148  /**
149  * 设置消息发送者账号
150  *
151  * @param senderId 消息发送者账号,传空表示当前用户
152  * @return Builder 自身实例
153  */
154  public V2NIMMessageInsertParamsBuilder withSenderId(String senderId) {
155  this.senderId = senderId;
156  return this;
157  }
158 
159  /**
160  * 设置指定插入消息时间
161  *
162  * @param createTime 指定插入消息时间,传 0 则 sdk 使用当前 ntp 时间插入
163  * @return Builder 自身实例
164  */
165  public V2NIMMessageInsertParamsBuilder withCreateTime(long createTime) {
166  this.createTime = createTime;
167  return this;
168  }
169 
170  /**
171  * 设置是否需要更新会话的最后一条信息
172  *
173  * @param lastMessageUpdateEnabled true: 需要,false: 不需要
174  * @return Builder 自身实例
175  */
176  public V2NIMMessageInsertParamsBuilder withLastMessageUpdateEnabled(boolean lastMessageUpdateEnabled) {
177  this.lastMessageUpdateEnabled = lastMessageUpdateEnabled;
178  return this;
179  }
180 
181  /**
182  * 构建最终的 V2NIMMessageInsertParams 对象
183  *
184  * @return 构造完成的对象
185  */
186  public V2NIMMessageInsertParams build() {
187  return new V2NIMMessageInsertParams(conversationId, senderId, createTime, lastMessageUpdateEnabled);
188  }
189  }
190 }
void setLastMessageUpdateEnabled(boolean lastMessageUpdateEnabled)
设置是否需要更新会话的最后一条信息
本地消息插入参数类 用于 insertMessageToLocalEx 接口
void setCreateTime(long createTime)
设置指定插入消息时间
V2NIMMessageInsertParams(String conversationId, String senderId, long createTime, boolean lastMessageUpdateEnabled)
构造函数
boolean isLastMessageUpdateEnabled()
获取是否需要更新会话的最后一条信息
void setSenderId(String senderId)
设置消息发送者账号