MM-47171 Export direct channel favorites (#21570)

Этот коммит содержится в:
Tim Scheuermann
2022-11-04 17:13:14 +01:00
коммит произвёл GitHub
родитель 279754c6b0
Коммит b73bf144aa
9 изменённых файлов: 150 добавлений и 4 удалений

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

@@ -626,7 +626,12 @@ func (a *App) exportAllDirectChannels(writer io.Writer) *model.AppError {
continue
}
channelLine := ImportLineFromDirectChannel(channel)
favoritedBy, err := a.buildFavoritedByList(channel.Id)
if err != nil {
return err
}
channelLine := ImportLineFromDirectChannel(channel, favoritedBy)
if err := a.exportWriteLine(writer, channelLine); err != nil {
return err
}
@@ -636,6 +641,29 @@ func (a *App) exportAllDirectChannels(writer io.Writer) *model.AppError {
return nil
}
func (a *App) buildFavoritedByList(channelID string) ([]string, *model.AppError) {
prefs, err := a.Srv().Store().Preference().GetCategoryAndName(model.PreferenceCategoryFavoriteChannel, channelID)
if err != nil {
return nil, model.NewAppError("buildFavoritedByList", "app.preference.get_category.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
}
userIDs := make([]string, 0, len(prefs))
for _, pref := range prefs {
if pref.Value != "true" {
continue
}
user, err := a.Srv().Store().User().Get(context.Background(), pref.UserId)
if err != nil {
return nil, model.NewAppError("buildFavoritedByList", "app.user.get.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
}
userIDs = append(userIDs, user.Username)
}
return userIDs, nil
}
func (a *App) exportAllDirectPosts(ctx request.CTX, writer io.Writer, withAttachments bool) ([]imports.AttachmentImportData, *model.AppError) {
var attachments []imports.AttachmentImportData
afterId := strings.Repeat("0", 26)