MM-34549 shared channels; add users to channel that were already sync'd (#17361)

Fixes a bug and adds a feature for shared channels:
- The Bug: when creating new shared channels, users that had already been sync'd via another channel were not added to the new channel's member list, since the users were not sync'd again. This PR sync's users per channel.
- The Feature: support custom statuses
Этот коммит содержится в:
Doug Lauder
2021-04-14 14:59:26 -04:00
коммит произвёл GitHub
родитель 81c40174e6
Коммит 9799fe9be6
19 изменённых файлов: 123 добавлений и 52 удалений

Просмотреть файл

@@ -47,7 +47,8 @@ func newSqlSharedChannelStore(sqlStore *SqlStore) store.SharedChannelStore {
tableSharedChannelUsers.ColMap("Id").SetMaxSize(26)
tableSharedChannelUsers.ColMap("UserId").SetMaxSize(26)
tableSharedChannelUsers.ColMap("RemoteId").SetMaxSize(26)
tableSharedChannelUsers.SetUniqueTogether("UserId", "RemoteId")
tableSharedChannelUsers.ColMap("ChannelId").SetMaxSize(26)
tableSharedChannelUsers.SetUniqueTogether("UserId", "ChannelId", "RemoteId")
tableSharedChannelFiles := db.AddTableWithName(model.SharedChannelAttachment{}, "SharedChannelAttachments").SetKeys(false, "Id")
tableSharedChannelFiles.ColMap("Id").SetMaxSize(26)
@@ -557,14 +558,15 @@ func (s SqlSharedChannelStore) SaveUser(scUser *model.SharedChannelUser) (*model
}
// GetUser fetches a shared channel user based on user_id and remoteId.
func (s SqlSharedChannelStore) GetUser(userId string, remoteId string) (*model.SharedChannelUser, error) {
func (s SqlSharedChannelStore) GetUser(userID string, channelID string, remoteID string) (*model.SharedChannelUser, error) {
var scu model.SharedChannelUser
squery, args, err := s.getQueryBuilder().
Select("*").
From("SharedChannelUsers").
Where(sq.Eq{"SharedChannelUsers.UserId": userId}).
Where(sq.Eq{"SharedChannelUsers.RemoteId": remoteId}).
Where(sq.Eq{"SharedChannelUsers.UserId": userID}).
Where(sq.Eq{"SharedChannelUsers.RemoteId": remoteID}).
Where(sq.Eq{"SharedChannelUsers.ChannelId": channelID}).
ToSql()
if err != nil {
@@ -573,9 +575,9 @@ func (s SqlSharedChannelStore) GetUser(userId string, remoteId string) (*model.S
if err := s.GetReplica().SelectOne(&scu, squery, args...); err != nil {
if err == sql.ErrNoRows {
return nil, store.NewErrNotFound("SharedChannelUser", userId)
return nil, store.NewErrNotFound("SharedChannelUser", userID)
}
return nil, errors.Wrapf(err, "failed to find shared channel user with UserId=%s, RemoteId=%s", userId, remoteId)
return nil, errors.Wrapf(err, "failed to find shared channel user with UserId=%s, ChannelId=%s, RemoteId=%s", userID, channelID, remoteID)
}
return &scu, nil
}

Просмотреть файл

@@ -1030,6 +1030,7 @@ func upgradeDatabaseToVersion535(sqlStore *SqlStore) {
uniquenessColumns = []string{"RemoteTeamId", "SiteUrl(168)"}
}
sqlStore.CreateUniqueCompositeIndexIfNotExists(RemoteClusterSiteURLUniqueIndex, "RemoteClusters", uniquenessColumns)
sqlStore.CreateColumnIfNotExists("SharedChannelUsers", "ChannelId", "VARCHAR(26)", "VARCHAR(26)", "")
// note: setting default 0 on pre-5.0 tables causes test-db-migration script to fail, so this column will be added to ignore list
sqlStore.CreateColumnIfNotExists("ChannelMembers", "MentionCountRoot", "bigint", "bigint", "0")