NIMSDK-AOS  10.9.50
V2NIMConversationFilter.java
浏览该文件的文档.
1 package com.netease.nimlib.sdk.v2.conversation.params;
2 
3 import android.text.TextUtils;
5 import com.netease.nimlib.util.CollectionUtil;
6 import java.util.HashSet;
7 import java.util.List;
8 import java.util.Objects;
9 import java.util.Set;
10 
11 /**
12  * 会话过滤器
13  */
15 
16  /**
17  * 会话类型列表,为空表示查询所有类型,否则查询指定对话类型
18  */
19  private List<V2NIMConversationType> conversationTypes = null;
20  /**
21  * 会话分组id
22  */
23  private String conversationGroupId = null;
24  /**
25  * 是否忽略免打扰
26  */
27  private boolean ignoreMuted = false;
28  /**
29  * 内部去重处理Set
30  */
31  private Set<V2NIMConversationType> conversationTypeSet = null;
32 
34  }
35 
36  /**
37  * @param types 会话类型列表,为空表示查询所有类型,否则查询指定对话类型
38  */
39  public V2NIMConversationFilter(List<V2NIMConversationType> types) {
40  this.conversationTypes = types;
41  if(types != null)
42  {
43  this.conversationTypeSet = new HashSet<>(types);
44  }
45  }
46 
47  /**
48  * @param types 会话类型列表,为空表示查询所有类型,否则查询指定对话类型
49  * @param groupId 会话分组id
50  */
51  public V2NIMConversationFilter(List<V2NIMConversationType> types, String groupId) {
52  this.conversationTypes = types;
53  if(types != null)
54  {
55  this.conversationTypeSet = new HashSet<>(types);
56  }
57  this.conversationGroupId = groupId;
58  }
59 
60  /**
61  * @param types 会话类型列表,为空表示查询所有类型,否则查询指定对话类型
62  * @param groupId 会话分组id
63  * @param ignoreMuted 是否忽略免打扰
64  */
65  public V2NIMConversationFilter(List<V2NIMConversationType> types, String groupId, boolean ignoreMuted) {
66  this.conversationTypes = types;
67  if(types != null)
68  {
69  this.conversationTypeSet = new HashSet<>(types);
70  }
71  this.conversationGroupId = groupId;
72  this.ignoreMuted = ignoreMuted;
73  }
74 
75 
76 
77 
78  /**
79  * 获取会话类型列表,为空表示查询所有类型,否则查询指定对话类型
80  * @return 会话类型列表,为空表示查询所有类型,否则查询指定对话类型
81  */
82  public List<V2NIMConversationType> getConversationTypes() {
83  return conversationTypes;
84  }
85 
86  /**
87  * 获取会话类型集合
88  * @return
89  */
90  public Set<V2NIMConversationType> getConversationTypeSet() {
91  if(CollectionUtil.isNotEmpty(conversationTypes) && CollectionUtil.isEmpty(conversationTypeSet))
92  {
93  conversationTypeSet = new HashSet<>(conversationTypes);
94  }
95  return conversationTypeSet;
96  }
97 
98  /**
99  * 设置会话类型列表
100  * @param conversationTypes 会话类型列表,为空表示查询所有类型,否则查询指定对话类型
101  */
102  public void setConversationTypes(List<V2NIMConversationType> conversationTypes) {
103  this.conversationTypes = conversationTypes;
104  }
105 
106  /**
107  * 获取会话分组id
108  * @return 会话分组id
109  */
110  public String getConversationGroupId() {
111  return this.conversationGroupId;
112  }
113 
114  /**
115  * 设置会话分组id
116  * @param conversationGroupId 会话分组id
117  */
118  public void setConversationGroupId(String conversationGroupId) {
119  this.conversationGroupId = conversationGroupId;
120  }
121 
122  /**
123  * 获取是否忽略免打扰
124  * @return 是否忽略免打扰
125  */
126  public boolean isIgnoreMuted() {
127  return ignoreMuted;
128  }
129 
130  /**
131  * 设置是否忽略免打扰
132  * @param ignoreMuted 是否忽略免打扰
133  */
134  public void setIgnoreMuted(boolean ignoreMuted) {
135  this.ignoreMuted = ignoreMuted;
136  }
137 
138  @Override
139  public boolean equals(Object o) {
140  if (this == o) {
141  return true;
142  }
143  if (!(o instanceof V2NIMConversationFilter)) {
144  return false;
145  }
146  V2NIMConversationFilter that = (V2NIMConversationFilter) o;
147  return ignoreMuted == that.ignoreMuted && Objects.equals(conversationGroupId, that.conversationGroupId) && Objects.equals(getConversationTypeSet(),
148  that.getConversationTypeSet());
149  }
150 
151  @Override
152  public int hashCode() {
153  return Objects.hash(conversationGroupId, ignoreMuted, getConversationTypeSet());
154  }
155 
156  @Override
157  public String toString() {
158  return "V2NIMConversationFilter{" + "conversationTypes=" + conversationTypes + ", conversationGroupId='" + conversationGroupId + '\''
159  + ", ignoreMuted=" + ignoreMuted + '}';
160  }
161 
162  public boolean isValid()
163  {
164  return !CollectionUtil.isEmpty(conversationTypes) || !TextUtils.isEmpty(conversationGroupId) || ignoreMuted;
165  }
166 
167  public String getInvalidMsg(){
168  if(CollectionUtil.isEmpty(conversationTypes) && TextUtils.isEmpty(conversationGroupId) && !ignoreMuted){
169  return "conversationTypes and conversationGroupId and ignoreMuted are all empty";
170  }
171  return null;
172  }
173 }
Set< V2NIMConversationType > getConversationTypeSet()
获取会话类型集合
List< V2NIMConversationType > getConversationTypes()
获取会话类型列表,为空表示查询所有类型,否则查询指定对话类型
void setIgnoreMuted(boolean ignoreMuted)
设置是否忽略免打扰
V2NIMConversationFilter(List< V2NIMConversationType > types, String groupId, boolean ignoreMuted)
V2NIMConversationFilter(List< V2NIMConversationType > types, String groupId)
void setConversationTypes(List< V2NIMConversationType > conversationTypes)
设置会话类型列表
void setConversationGroupId(String conversationGroupId)
设置会话分组id