mirror of
https://gitee.com/WuKongDev/WuKongIM.git
synced 2025-12-06 14:59:08 +08:00
feat: implement cache deletion for subscribers and blacklist removal
This commit is contained in:
@@ -481,6 +481,17 @@ func (ch *channel) removeSubscriber(c *wkhttp.Context) {
|
||||
c.ResponseError(err)
|
||||
return
|
||||
}
|
||||
|
||||
// 删除订阅者的会话缓存
|
||||
for _, subscriber := range req.Subscribers {
|
||||
err = service.ConversationManager.DeleteFromCache(subscriber, req.ChannelId, req.ChannelType)
|
||||
if err != nil {
|
||||
ch.Error("删除订阅者的会话失败!", zap.Error(err))
|
||||
c.ResponseError(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
err = ch.updateTagBySubscribers(req.ChannelId, req.ChannelType, req.Subscribers, true)
|
||||
if err != nil {
|
||||
ch.Error("removeSubscriber: update tag failed", zap.Error(err))
|
||||
@@ -670,6 +681,16 @@ func (ch *channel) blacklistRemove(c *wkhttp.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// 删除黑名单的会话缓存
|
||||
for _, uid := range req.UIDs {
|
||||
err = service.ConversationManager.DeleteFromCache(uid, req.ChannelId, req.ChannelType)
|
||||
if err != nil {
|
||||
ch.Error("删除订阅者的会话失败!", zap.Error(err))
|
||||
c.ResponseError(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
c.ResponseOK()
|
||||
}
|
||||
|
||||
|
||||
@@ -107,6 +107,15 @@ func (c *ConversationManager) Stop() {
|
||||
c.saveToFile()
|
||||
}
|
||||
|
||||
func (c *ConversationManager) DeleteFromCache(uid string, channelId string, channelType uint8) error {
|
||||
if channelType == wkproto.ChannelTypeLive { // 直播频道不删除会话
|
||||
return nil
|
||||
}
|
||||
index := c.getUpdaterIndex(channelId)
|
||||
c.updaters[index].removeUserChannelUpdate(channelId, channelType, uid)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *ConversationManager) saveToFile() {
|
||||
|
||||
conversationDir := path.Join(options.G.DataDir, "conversationv2")
|
||||
@@ -336,3 +345,20 @@ func (c *conversationUpdater) removeChannelUpdate(fakeChannelId string, channelT
|
||||
delete(c.waitUpdates, wkutil.ChannelToKey(fakeChannelId, channelType))
|
||||
c.Unlock()
|
||||
}
|
||||
|
||||
func (c *conversationUpdater) removeUserChannelUpdate(fakeChannelId string, channelType uint8, uid string) {
|
||||
c.Lock()
|
||||
defer c.Unlock()
|
||||
for _, update := range c.waitUpdates {
|
||||
if update.ChannelId == fakeChannelId && update.ChannelType == channelType && slices.Contains(update.Uids, uid) {
|
||||
filteredUids := make([]string, 0, len(update.Uids))
|
||||
for _, u := range update.Uids {
|
||||
if u != uid {
|
||||
filteredUids = append(filteredUids, u)
|
||||
}
|
||||
}
|
||||
update.Uids = filteredUids
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,4 +13,7 @@ type IConversationManager interface {
|
||||
Push(fakeChannelId string, channelType uint8, tagKey string, events []*eventbus.Event)
|
||||
// GetUserChannelsFromCache 从缓存中获取用户的某一类型的最近会话集合
|
||||
GetUserChannelsFromCache(uid string, conversationType wkdb.ConversationType) ([]wkproto.Channel, error)
|
||||
|
||||
// DeleteFromCache 删除用户的某个频道的最近会话
|
||||
DeleteFromCache(uid string, channelId string, channelType uint8) error
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user