Skip to content

Commit bf70a1e

Browse files
committed
退出群组时,删掉群相关用户设置
1 parent 512d797 commit bf70a1e

2 files changed

Lines changed: 48 additions & 1 deletion

File tree

broker/src/main/java/io/moquette/persistence/DatabaseStore.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -911,6 +911,40 @@ List<WFCMessage.UserSettingEntry> getPersistUserSetting(final String userId) {
911911
}
912912

913913

914+
void removeGroupUserSettings(String groupId, List<String> users) {
915+
Connection connection = null;
916+
PreparedStatement statement = null;
917+
try {
918+
connection = DBUtil.getConnection();
919+
920+
StringBuilder sb = new StringBuilder("delete t_user_setting where _scope in (1,3,5,7) and _uid in (");
921+
for (int i = 0; i < users.size(); i++) {
922+
sb.append("?");
923+
if (i != users.size() - 1) {
924+
sb.append(",");
925+
}
926+
}
927+
sb.append(") and _key like '1-_-?'");
928+
929+
930+
statement = connection.prepareStatement(sb.toString());
931+
int index = 1;
932+
for (String userId:users) {
933+
statement.setString(index++, userId);
934+
}
935+
statement.setString(index++, groupId);
936+
937+
int count = statement.executeUpdate();
938+
LOG.info("Update rows {}", count);
939+
} catch (SQLException e) {
940+
// TODO Auto-generated catch block
941+
e.printStackTrace();
942+
Utility.printExecption(LOG, e);
943+
} finally {
944+
DBUtil.closeDB(connection, statement);
945+
}
946+
}
947+
914948
void persistGroupInfo(final WFCMessage.GroupInfo groupInfo) {
915949
mScheduler.execute(()->{
916950
Connection connection = null;

broker/src/main/java/io/moquette/persistence/MemoryMessagesStore.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,7 @@ public ErrorCode kickoffGroupMembers(String operator, boolean isAdmin, String gr
758758
}
759759

760760
removeFavGroup(groupId, removedIds);
761-
761+
removeGroupUserSettings(groupId, removedIds);
762762
return ErrorCode.ERROR_CODE_SUCCESS;
763763
}
764764

@@ -827,9 +827,21 @@ public ErrorCode quitGroup(String operator, String groupId) {
827827
}
828828

829829
removeFavGroup(groupId, Arrays.asList(operator));
830+
removeGroupUserSettings(groupId, Arrays.asList(operator));
830831
return ErrorCode.ERROR_CODE_SUCCESS;
831832
}
832833

834+
private void removeGroupUserSettings(String groupId, List<String> users) {
835+
HazelcastInstance hzInstance = m_Server.getHazelcastInstance();
836+
MultiMap<String, WFCMessage.UserSettingEntry> userSettingMap = hzInstance.getMultiMap(USER_SETTING);
837+
838+
databaseStore.removeGroupUserSettings(groupId, users);
839+
for (String userId:users) {
840+
userSettingMap.remove(userId);
841+
}
842+
843+
}
844+
833845
@Override
834846
public ErrorCode dismissGroup(String operator, String groupId, boolean isAdmin) {
835847
HazelcastInstance hzInstance = m_Server.getHazelcastInstance();
@@ -869,6 +881,7 @@ public ErrorCode dismissGroup(String operator, String groupId, boolean isAdmin)
869881
}
870882
}
871883
removeFavGroup(groupId, ids);
884+
removeGroupUserSettings(groupId, ids);
872885

873886
return ErrorCode.ERROR_CODE_SUCCESS;
874887
}

0 commit comments

Comments
 (0)