NIMSDK-AOS  10.5.0
GetMessagesDynamicallyParam.java
浏览该文件的文档.
1 package com.netease.nimlib.sdk.msg.model;
2 
3 import androidx.annotation.NonNull;
4 import androidx.annotation.Nullable;
5 
9 import com.netease.nimlib.session.IMMessageImpl;
10 import com.netease.nimlib.session.MsgDBHelper;
11 import com.netease.nimlib.util.StringUtil;
12 
13 import java.io.Serializable;
14 import java.util.ArrayList;
15 import java.util.List;
16 
17 public class GetMessagesDynamicallyParam implements Serializable {
18 
20  public static final int MAX_LIMIT = 100;
24  @NonNull
25  private final String sessionId;
29  @NonNull
30  private final SessionTypeEnum sessionType;
34  private long fromTime;
38  private long toTime;
39 
46  private long anchorServerId;
51  private String anchorClientId;
56  private int limit;
57 
61  @Nullable
62  private GetMessageDirectionEnum direction;
63 
64  private List<MsgTypeEnum> messageTypes;
65  private boolean strictMode;
66 
67  public GetMessagesDynamicallyParam(@NonNull String sessionId, @NonNull SessionTypeEnum sessionType) {
68  this(sessionId, sessionType, 0, 0, 0, null, 0, GetMessageDirectionEnum.FORWARD, null, false);
69  }
70 
71  public GetMessagesDynamicallyParam(@NonNull String sessionId, @NonNull SessionTypeEnum sessionType, long fromTime, long toTime, long anchorServerId, String anchorClientId, int limit, @Nullable GetMessageDirectionEnum direction) {
72  this(sessionId, sessionType, fromTime, toTime, anchorServerId, anchorClientId, limit, direction, null, false);
73  }
74 
75  public GetMessagesDynamicallyParam(@NonNull String sessionId, @NonNull SessionTypeEnum sessionType, long fromTime, long toTime, long anchorServerId, String anchorClientId, int limit, @Nullable GetMessageDirectionEnum direction, @Nullable List<MsgTypeEnum> messageTypes, boolean strictMode) {
76  this.sessionId = sessionId;
77  this.sessionType = sessionType;
78  this.fromTime = fromTime;
79  this.toTime = toTime;
80  this.anchorServerId = anchorServerId;
81  this.anchorClientId = anchorClientId;
82  this.limit = limit;
83  this.direction = direction;
84  this.messageTypes = messageTypes;
85  this.strictMode = strictMode;
86  }
87 
88  @NonNull
89  public String getSessionId() {
90  return sessionId;
91  }
92 
93  @NonNull
95  return sessionType;
96  }
97 
98  public long getFromTime() {
99  return fromTime;
100  }
101 
102  public void setFromTime(long fromTime) {
103  this.fromTime = fromTime;
104  }
105 
106  public long getToTime() {
107  return toTime;
108  }
109 
110  public void setToTime(long toTime) {
111  this.toTime = toTime;
112  }
113 
114  public long getAnchorServerId() {
115  return anchorServerId;
116  }
117 
118  public void setAnchorServerId(long anchorServerId) {
119  this.anchorServerId = anchorServerId;
120  }
121 
122  public String getAnchorClientId() {
123  return anchorClientId;
124  }
125 
126  public void setAnchorClientId(String anchorClientId) {
127  this.anchorClientId = anchorClientId;
128  }
129 
130  public int getLimit() {
131  return limit;
132  }
133 
134  public void setLimit(int limit) {
135  this.limit = limit;
136  }
137 
139  return direction;
140  }
141 
142  public void setDirection(GetMessageDirectionEnum direction) {
143  this.direction = direction;
144  }
145 
146  public List<MsgTypeEnum> getMessageTypes() {
147  return messageTypes;
148  }
149 
150  public void setMessageTypes(List<MsgTypeEnum> messageTypes) {
151  this.messageTypes = messageTypes;
152  }
153 
154  public boolean isStrictMode() {
155  return strictMode;
156  }
157 
158  public void setStrictMode(boolean strictMode) {
159  this.strictMode = strictMode;
160  }
161 
165  @NonNull
166  public IMMessage getAnchor() {
167  String clientId = this.getAnchorClientId();
168  if (StringUtil.isNotEmpty(clientId)) {
169  IMMessage anchor = MsgDBHelper.queryMessageByUuid(clientId);
170  if (anchor != null) {
171  return anchor;
172  }
173  }
174  long anchorTime = this.getDirection() == GetMessageDirectionEnum.BACKWARD ? this.getFromTime() : this.getToTime();
175  IMMessageImpl anchor = (IMMessageImpl) MessageBuilder.createEmptyMessage(this.getSessionId(), this.getSessionType(), anchorTime);
176  anchor.setUuid(this.getAnchorClientId());
177  anchor.setServerId(this.getAnchorServerId());
178  return anchor;
179  }
180 
182  return createStandardizedParam(true);
183  }
184 
186  String formedSessionId = this.sessionId;
187  SessionTypeEnum formedSessionType = this.sessionType == null ? SessionTypeEnum.None : this.sessionType;
188  long formedFromTime = this.fromTime;
189  long formedToTime = this.toTime;
190  long formedExcludeServerId = this.anchorServerId;
191  String formedExcludeClientId = this.anchorClientId;
192  int formedLimit = this.limit;
193  if (checkLimit) {
194  formedLimit = formedLimit <= 0 ? GetMessagesDynamicallyParam.MAX_LIMIT : formedLimit;
195  formedLimit = Math.min(formedLimit, GetMessagesDynamicallyParam.MAX_LIMIT);
196  }
197  GetMessageDirectionEnum formedDirection = this.direction == null ? GetMessageDirectionEnum.FORWARD : this.direction;
198  List<MsgTypeEnum>msgTypes = this.messageTypes == null ? new ArrayList<>(0) : this.messageTypes;
199  return new GetMessagesDynamicallyParam(formedSessionId, formedSessionType, formedFromTime, formedToTime, formedExcludeServerId, formedExcludeClientId, formedLimit, formedDirection, msgTypes, this.strictMode);
200  }
201 
207  public boolean isValid() {
208  return StringUtil.isNotEmpty(sessionId)
209  && (sessionType == SessionTypeEnum.P2P || sessionType == SessionTypeEnum.Team || sessionType == SessionTypeEnum.SUPER_TEAM)
210  && fromTime >= 0
211  && toTime >= 0
212  && (toTime == 0 || toTime >= fromTime)
213  && limit >= 0 && limit <= MAX_LIMIT
214  && (anchorServerId == 0 || StringUtil.isNotEmpty(anchorClientId));
215  }
216 
217  @Override
218  public String toString() {
219  return "GetMessagesDynamicallyParam{" +
220  "sessionId='" + sessionId + '\'' +
221  ", sessionType=" + sessionType +
222  ", fromTime=" + fromTime +
223  ", toTime=" + toTime +
224  ", excludeServerId=" + anchorServerId +
225  ", excludeClientId='" + anchorClientId + '\'' +
226  ", limit=" + limit +
227  ", direction=" + direction +
228  ", messageTypes=" + messageTypes +
229  ", strictMode=" + strictMode +
230  '}';
231  }
232 }
GetMessagesDynamicallyParam(@NonNull String sessionId, @NonNull SessionTypeEnum sessionType, long fromTime, long toTime, long anchorServerId, String anchorClientId, int limit, @Nullable GetMessageDirectionEnum direction, @Nullable List< MsgTypeEnum > messageTypes, boolean strictMode)
云信 IM 消息构造器,提供构建各类型消息的接口。
NIM消息实体数据结构。 第三方APP不要调用设置类接口,调用之后不会被持久化
Definition: IMMessage.java:12
GetMessagesDynamicallyParam createStandardizedParam(boolean checkLimit)
static IMMessage createEmptyMessage(String sessionId, SessionTypeEnum sessionType, long time)
创建一条空消息。
GetMessagesDynamicallyParam(@NonNull String sessionId, @NonNull SessionTypeEnum sessionType, long fromTime, long toTime, long anchorServerId, String anchorClientId, int limit, @Nullable GetMessageDirectionEnum direction)
GetMessagesDynamicallyParam(@NonNull String sessionId, @NonNull SessionTypeEnum sessionType)