IMessagesStore.java 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. /*
  2. * Copyright (c) 2012-2017 The original author or authors
  3. * ------------------------------------------------------
  4. * All rights reserved. This program and the accompanying materials
  5. * are made available under the terms of the Eclipse Public License v1.0
  6. * and Apache License v2.0 which accompanies this distribution.
  7. *
  8. * The Eclipse Public License is available at
  9. * http://www.eclipse.org/legal/epl-v10.html
  10. *
  11. * The Apache License v2.0 is available at
  12. * http://www.opensource.org/licenses/apache2.0.php
  13. *
  14. * You may elect to redistribute this code under either of these licenses.
  15. */
  16. package io.moquette.spi;
  17. import cn.wildfirechat.pojos.InputOutputUserInfo;
  18. import cn.wildfirechat.pojos.SystemSettingPojo;
  19. import cn.wildfirechat.proto.ProtoConstants;
  20. import cn.wildfirechat.proto.WFCMessage;
  21. import com.xiaoleilu.loServer.model.FriendData;
  22. import cn.wildfirechat.pojos.InputOutputUserBlockStatus;
  23. import io.moquette.persistence.DatabaseStore;
  24. import io.moquette.persistence.MemorySessionStore;
  25. import io.moquette.persistence.UserClientEntry;
  26. import io.moquette.spi.impl.subscriptions.Topic;
  27. import io.netty.buffer.ByteBuf;
  28. import io.netty.buffer.Unpooled;
  29. import io.netty.handler.codec.mqtt.MqttQoS;
  30. import cn.wildfirechat.common.ErrorCode;
  31. import java.util.Collection;
  32. import java.util.Date;
  33. import java.util.List;
  34. import java.util.Set;
  35. /**
  36. * Defines the SPI to be implemented by a StorageService that handle persistence of messages
  37. */
  38. public interface IMessagesStore {
  39. class StoredMessage {
  40. final MqttQoS m_qos;
  41. final byte[] m_payload;
  42. final String m_topic;
  43. private boolean m_retained;
  44. private String m_clientID;
  45. private MessageGUID m_guid;
  46. public StoredMessage(byte[] message, MqttQoS qos, String topic) {
  47. m_qos = qos;
  48. m_payload = message;
  49. m_topic = topic;
  50. }
  51. public MqttQoS getQos() {
  52. return m_qos;
  53. }
  54. public String getTopic() {
  55. return m_topic;
  56. }
  57. public void setGuid(MessageGUID guid) {
  58. this.m_guid = guid;
  59. }
  60. public MessageGUID getGuid() {
  61. return m_guid;
  62. }
  63. public String getClientID() {
  64. return m_clientID;
  65. }
  66. public void setClientID(String m_clientID) {
  67. this.m_clientID = m_clientID;
  68. }
  69. public ByteBuf getPayload() {
  70. return Unpooled.copiedBuffer(m_payload);
  71. }
  72. public void setRetained(boolean retained) {
  73. this.m_retained = retained;
  74. }
  75. public boolean isRetained() {
  76. return m_retained;
  77. }
  78. @Override
  79. public String toString() {
  80. return "PublishEvent{clientID='" + m_clientID + '\'' + ", m_retain="
  81. + m_retained + ", m_qos=" + m_qos + ", m_topic='" + m_topic + '\'' + '}';
  82. }
  83. }
  84. DatabaseStore getDatabaseStore();
  85. WFCMessage.Message storeMessage(String fromUser, String fromClientId, WFCMessage.Message message);
  86. void storeSensitiveMessage(WFCMessage.Message message);
  87. int getNotifyReceivers(String fromUser, WFCMessage.Message.Builder message, Set<String> notifyReceivers, ProtoConstants.RequestSourceType requestSourceType);
  88. Set<String> getAllEnds();
  89. WFCMessage.PullMessageResult fetchMessage(String user, String exceptClientId, long fromMessageId, int pullType);
  90. WFCMessage.PullMessageResult loadRemoteMessages(String user, WFCMessage.Conversation conversation, long beforeUid, int count, Collection<Integer> contentTypes);
  91. long insertUserMessages(String sender, int conversationType, String target, int line, int messageContentType, String userId, long messageId, boolean directing);
  92. WFCMessage.GroupInfo createGroup(String operator, WFCMessage.GroupInfo groupInfo, List<WFCMessage.GroupMember> memberList, String memberExtra, boolean isAdmin);
  93. ErrorCode addGroupMembers(String operator, boolean isAdmin, String groupId, List<WFCMessage.GroupMember> memberList, String extra);
  94. ErrorCode kickoffGroupMembers(String operator, boolean isAdmin, String groupId, List<String> memberList);
  95. ErrorCode quitGroup(String operator, String groupId, boolean admin);
  96. void clearUserGroups(String userId);
  97. ErrorCode dismissGroup(String operator, String groupId, boolean isAdmin);
  98. ErrorCode modifyGroupInfo(String operator, String groupId, int modifyType, String value, boolean isAdmin);
  99. ErrorCode modifyGroupMemberAlias(String operator, String groupId, String alias, String memberId, boolean isAdmin);
  100. ErrorCode modifyGroupMemberExtra(String operator, String groupId, String extra, String memberId, boolean isAdmin);
  101. List<WFCMessage.GroupInfo> getGroupInfos(List<WFCMessage.UserRequest> requests, String fromUser, boolean isAdmin);
  102. WFCMessage.GroupInfo getGroupInfo(String groupId);
  103. Set<String> getUserGroupIds(String userId);
  104. Set<String> getCommonGroupIds(String userId1, String userId2);
  105. ErrorCode getGroupMembers(String fromUser, String groupId, long maxDt, List<WFCMessage.GroupMember> members);
  106. WFCMessage.GroupMember getGroupMember(String groupId, String memberId);
  107. ErrorCode transferGroup(String operator, String groupId, String newOwner, boolean isAdmin);
  108. ErrorCode setGroupManager(String operator, String groupId, int type, List<String> userList, boolean isAdmin);
  109. boolean isMemberInGroup(String member, String groupId);
  110. ErrorCode canSendMessageInGroup(String member, String groupId);
  111. Set<String> getGroupManagers(String groupId, boolean includeOwner);
  112. ErrorCode recallMessage(long messageUid, String operatorId, String clientId, boolean isAdmin, ByteBuf ackPayload);
  113. ErrorCode recallCastMessage(long messageUid, String operatorId);
  114. void clearUserMessages(String userId);
  115. WFCMessage.Robot getRobot(String robotId);
  116. void addRobot(WFCMessage.Robot robot);
  117. void destroyRobot(String robotId);
  118. ErrorCode getUserInfo(String fromUser, List<WFCMessage.UserRequest> requestList, WFCMessage.PullUserResult.Builder builder);
  119. ErrorCode modifyUserInfo(String userId, WFCMessage.ModifyMyInfoRequest request) throws Exception;
  120. void forceCleanOnlineStatus(String userId, String clientId);
  121. void updateUserOnlineSetting(MemorySessionStore.Session session, boolean online);
  122. ErrorCode modifyUserStatus(String userId, int status);
  123. int getUserStatus(String userId);
  124. List<InputOutputUserBlockStatus> getUserStatusList();
  125. ErrorCode updateUserInfo(InputOutputUserInfo userInfo, int flag);
  126. void addUserInfo(WFCMessage.User user, String password) throws Exception;
  127. void destroyUser(String userId);
  128. void updateUserInfo(WFCMessage.User user) throws Exception;
  129. WFCMessage.User getUserInfo(String userId);
  130. WFCMessage.User getUserInfoByName(String name);
  131. WFCMessage.User getUserInfoByMobile(String mobile);
  132. List<WFCMessage.User> searchUser(String keyword, int searchType, int page);
  133. List<WFCMessage.User> getUserInfoList(int count, int offset);
  134. boolean updateSystemSetting(int id, String value, String desc);
  135. SystemSettingPojo getSystemSetting(int id);
  136. void createChatroom(String chatroomId, WFCMessage.ChatroomInfo chatroomInfo);
  137. void destoryChatroom(String chatroomId);
  138. WFCMessage.ChatroomInfo getChatroomInfo(String chatroomId);
  139. WFCMessage.ChatroomMemberInfo getChatroomMemberInfo(String chatroomId, final int maxMemberCount);
  140. int getChatroomMemberCount(String chatroomId);
  141. Collection<String> getChatroomMemberClient(String userId);
  142. boolean checkUserClientInChatroom(String user, String clientId, String chatroomId);
  143. long insertChatroomMessages(String target, int line, long messageId);
  144. Collection<UserClientEntry> getChatroomMembers(String chatroomId);
  145. WFCMessage.PullMessageResult fetchChatroomMessage(String fromUser, String chatroomId, String exceptClientId, long fromMessageId);
  146. ErrorCode verifyToken(String userId, String token, List<String> serverIPs, List<Integer> ports);
  147. List<FriendData> getFriendList(String userId, String clientId, long version);
  148. void clearUserFriend(String userId);
  149. List<WFCMessage.FriendRequest> getFriendRequestList(String userId, long version);
  150. ErrorCode saveAddFriendRequest(String userId, WFCMessage.AddFriendRequest request, long[] head, boolean isAdmin);
  151. ErrorCode handleFriendRequest(String userId, WFCMessage.HandleFriendRequest request, WFCMessage.Message.Builder msgBuilder, long[] heads, boolean isAdmin);
  152. ErrorCode deleteFriend(String userId, String friendUid, long[] head);
  153. ErrorCode blackUserRequest(String fromUser, String targetUserId, int status, long[] head);
  154. FriendData getFriendData(String fromUser, String targetUserId);
  155. ErrorCode SyncFriendRequestUnread(String userId, long unreadDt, long[] head);
  156. ErrorCode isAllowUserMessage(String fromUser, String userId);
  157. ErrorCode setFriendAliasRequest(String fromUser, String targetUserId, String alias, long[] head);
  158. ErrorCode setFriendExtraRequest(String fromUser, String targetUserId, String extra, long[] head);
  159. ErrorCode handleJoinChatroom(String userId, String clientId, String chatroomId);
  160. ErrorCode handleQuitChatroom(String userId, String clientId, String chatroomId);
  161. boolean checkChatroomParticipantIdelTime(MemorySessionStore.Session session);
  162. String getApplicationAuthCode(String fromUser, String applicationId, int appType, String host);
  163. String verifyApplicationAuthCode(String token, String applicationId, int type);
  164. ErrorCode configApplication(String appId, int appType, long timestamp, String nonce, String signature);
  165. ErrorCode getUserSettings(String userId, long version, WFCMessage.GetUserSettingResult.Builder builder);
  166. WFCMessage.UserSettingEntry getUserSetting(String userId, int scope, String key);
  167. List<WFCMessage.UserSettingEntry> getUserSetting(String userId, int scope);
  168. long updateUserSettings(String userId, WFCMessage.ModifyUserSettingReq request, String clientId);
  169. void clearUserSettings(String userId);
  170. boolean getUserGlobalSilent(String userId);
  171. boolean getUserVoipSilent(String userId);
  172. boolean getUserPushHiddenDetail(String userId);
  173. boolean getUserConversationSilent(String userId, WFCMessage.Conversation conversation);
  174. boolean getSilentWhenPcOnline(String userId);
  175. boolean isUserNoDisturbing(String userId);
  176. ErrorCode createChannel(String operator, WFCMessage.ChannelInfo channelInfo);
  177. void clearUserChannels(String userId);
  178. ErrorCode modifyChannelInfo(String operator, String channelId, int modifyType, String value);
  179. ErrorCode transferChannel(String operator, String channelId, String newOwner);
  180. ErrorCode destroyChannel(String operator, String channelId, boolean isAdmin);
  181. List<WFCMessage.ChannelInfo> searchChannel(String keyword, boolean buzzy, int page);
  182. List<String> getListenedChannels(String userId);
  183. ErrorCode listenChannel(String operator, String channelId, boolean listen);
  184. WFCMessage.ChannelInfo getChannelInfo(String channelId);
  185. boolean canSendMessageInChannel(String user, String channelId);
  186. boolean checkUserInChannel(String user, String channelId);
  187. Collection<String> getChannelSubscriber(String channelId);
  188. Set<String> handleSensitiveWord(String message);
  189. boolean addSensitiveWords(List<String> words);
  190. boolean removeSensitiveWords(List<String> words);
  191. List<String> getAllSensitiveWords();
  192. WFCMessage.Message getMessage(long messageId);
  193. boolean isAllowClientCustomGroupNotification();
  194. boolean isAllowRobotCustomGroupNotification();
  195. int getVisibleQuitKickoffNotification();
  196. int getGroupForbiddenClientOperation();
  197. boolean isForwardMessageWithClientInfo();
  198. boolean isRobotCallbackWithClientInfo();
  199. boolean isChannelCallbackWithClientInfo();
  200. boolean isRobotAutoAcceptFriendRequest();
  201. long getPushExpiredTimes();
  202. List<Integer> getClientForbiddenSendTypes();
  203. List<Integer> getBlackListExceptionTypes();
  204. List<Integer> getGroupMuteExceptionTypes();
  205. List<Integer> getGlobalMuteExceptionTypes();
  206. long getMessageHead(String user);
  207. long getFriendHead(String user);
  208. long getFriendRqHead(String user);
  209. long getSettingHead(String user);
  210. //使用了数据库,会比较慢,仅能用户用户/群组等id的生成
  211. String getShortUUID();
  212. boolean checkSignature(String signature);
  213. boolean existSignatures();
  214. /**
  215. * Used to initialize all persistent store structures
  216. */
  217. void initStore();
  218. /**
  219. * Return a list of retained messages that satisfy the condition.
  220. *
  221. * @param condition
  222. * the condition to match during the search.
  223. * @return the collection of matching messages.
  224. */
  225. Collection<StoredMessage> searchMatching(IMatchingCondition condition);
  226. void cleanRetained(Topic topic);
  227. void storeRetained(Topic topic, StoredMessage storedMessage);
  228. }