mirror of
https://github.com/hanzoai/team.git
synced 2026-10-30 14:49:35 +00:00
* Refactor shared channel membership sync to use ChannelMemberHistory (MM-67616) Replace the trigger-time membership sync mechanism with a cursor-based approach using ChannelMemberHistory, aligning membership sync with the established pattern used by posts and reactions. Previously, membership changes were built into SyncMsg at trigger time and sent via a separate TopicChannelMembership code path. This meant removals were lost if a remote was offline, since ChannelMembers hard-deletes rows. Now, membership changes are fetched from ChannelMemberHistory at sync time using the LastMembersSyncAt cursor, detecting both joins and leaves reliably. The data flows through the normal syncForRemote pipeline alongside posts, reactions, and other sync data. Key changes: - Add GetMembershipChanges store method for ChannelMemberHistory - Add fetchMembershipsForSync and sendMembershipSyncData to sync pipeline - Replace HandleMembershipChange with NotifyMembershipChanged (trigger-only) - Remove conflict detection (idempotent add/remove resolves naturally) - Remove per-user membership tracking (GetUserChanges, UpdateUserLastMembershipSyncAt) - Add MembershipErrors to SyncResponse - Keep TopicChannelMembership receiver for one release cycle (backward compat)
91 lines
3.3 KiB
Go
91 lines
3.3 KiB
Go
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
package platform
|
|
|
|
import (
|
|
"github.com/mattermost/mattermost/server/public/model"
|
|
"github.com/mattermost/mattermost/server/public/shared/request"
|
|
"github.com/mattermost/mattermost/server/v8/platform/services/sharedchannel"
|
|
)
|
|
|
|
// SharedChannelServiceIFace is the interface to the shared channel service
|
|
type SharedChannelServiceIFace interface {
|
|
Shutdown() error
|
|
Start() error
|
|
NotifyChannelChanged(channelId string)
|
|
NotifyUserProfileChanged(userID string)
|
|
NotifyUserStatusChanged(status *model.Status)
|
|
SendChannelInvite(channel *model.Channel, userId string, rc *model.RemoteCluster, options ...sharedchannel.InviteOption) error
|
|
Active() bool
|
|
InviteRemoteToChannel(channelID, remoteID, userID string, shareIfNotShared bool) error
|
|
UninviteRemoteFromChannel(channelID, remoteID string) error
|
|
ShareChannel(sc *model.SharedChannel) (*model.SharedChannel, error)
|
|
CheckChannelNotShared(channelID string) error
|
|
CheckChannelIsShared(channelID string) error
|
|
CheckCanInviteToSharedChannel(channelId string) error
|
|
NotifyMembershipChanged(channelID string, originRemoteID string)
|
|
TransformMentionsOnReceiveForTesting(rctx request.CTX, post *model.Post, targetChannel *model.Channel, rc *model.RemoteCluster, mentionTransforms map[string]string)
|
|
}
|
|
|
|
type MockOptionSharedChannelService func(service *mockSharedChannelService)
|
|
|
|
func MockOptionSharedChannelServiceWithActive(active bool) MockOptionSharedChannelService {
|
|
return func(mrcs *mockSharedChannelService) {
|
|
mrcs.active = active
|
|
}
|
|
}
|
|
|
|
func NewMockSharedChannelService(service SharedChannelServiceIFace, options ...MockOptionSharedChannelService) *mockSharedChannelService {
|
|
mrcs := &mockSharedChannelService{service, true, []string{}, []string{}, 0}
|
|
for _, option := range options {
|
|
option(mrcs)
|
|
}
|
|
return mrcs
|
|
}
|
|
|
|
type mockSharedChannelService struct {
|
|
SharedChannelServiceIFace
|
|
active bool
|
|
channelNotifications []string
|
|
userProfileNotifications []string
|
|
numInvitations int
|
|
}
|
|
|
|
func (mrcs *mockSharedChannelService) NotifyChannelChanged(channelId string) {
|
|
mrcs.channelNotifications = append(mrcs.channelNotifications, channelId)
|
|
}
|
|
|
|
func (mrcs *mockSharedChannelService) NotifyUserProfileChanged(userId string) {
|
|
mrcs.userProfileNotifications = append(mrcs.userProfileNotifications, userId)
|
|
}
|
|
|
|
func (mrcs *mockSharedChannelService) Shutdown() error {
|
|
return nil
|
|
}
|
|
|
|
func (mrcs *mockSharedChannelService) Start() error {
|
|
return nil
|
|
}
|
|
|
|
func (mrcs *mockSharedChannelService) Active() bool {
|
|
return mrcs.active
|
|
}
|
|
|
|
func (mrcs *mockSharedChannelService) SendChannelInvite(channel *model.Channel, userId string, rc *model.RemoteCluster, options ...sharedchannel.InviteOption) error {
|
|
mrcs.numInvitations += 1
|
|
return nil
|
|
}
|
|
|
|
func (mrcs *mockSharedChannelService) NumInvitations() int {
|
|
return mrcs.numInvitations
|
|
}
|
|
|
|
func (mrcs *mockSharedChannelService) NotifyMembershipChanged(channelID string, originRemoteID string) {
|
|
// This is a mock implementation - it doesn't need to do anything
|
|
}
|
|
|
|
func (mrcs *mockSharedChannelService) TransformMentionsOnReceiveForTesting(rctx request.CTX, post *model.Post, targetChannel *model.Channel, rc *model.RemoteCluster, mentionTransforms map[string]string) {
|
|
// This is a mock implementation - it doesn't need to do anything
|
|
}
|