refactor: settings format picker redesign with Audio/Video sub-pickers, fix delete routing
All checks were successful
CI / build (push) Successful in 48s
All checks were successful
CI / build (push) Successful in 48s
- Replace Type/Quality settings with single Format button -> Audio/Video sub-pickers - Each sub-picker shows format options (bitrates for audio, resolutions for video) - Replace DefaultQuality with DefaultAudioFormat/DefaultVideoFormat in UserPreferences - Add DB migration 002 for new preference columns - Update repo layer SQL queries for new schema - Update playlist flow to use new preference fields - Fix missing deleteaccount and delaccount_ callback routing - Add back_format routing for format picker navigation
This commit is contained in:
@@ -12,16 +12,13 @@ import (
|
||||
)
|
||||
|
||||
func (h *Handler) buildSettingsKeyboard(userID int64, prefs *domain.UserPreferences) (string, models.InlineKeyboardMarkup) {
|
||||
mediaTypeLabel := "Video+Audio"
|
||||
switch prefs.DefaultMediaType {
|
||||
case domain.MediaTypeAudio:
|
||||
mediaTypeLabel = "Audio Only"
|
||||
case domain.MediaTypeVideo:
|
||||
mediaTypeLabel = "Video Only"
|
||||
audioFmt := prefs.DefaultAudioFormat
|
||||
if audioFmt == "" {
|
||||
audioFmt = "best"
|
||||
}
|
||||
qualityLabel := prefs.DefaultQuality
|
||||
if qualityLabel == "" {
|
||||
qualityLabel = "best"
|
||||
videoFmt := prefs.DefaultVideoFormat
|
||||
if videoFmt == "" {
|
||||
videoFmt = "best"
|
||||
}
|
||||
containerLabel := prefs.DefaultContainer
|
||||
if containerLabel == "" {
|
||||
@@ -34,8 +31,7 @@ func (h *Handler) buildSettingsKeyboard(userID int64, prefs *domain.UserPreferen
|
||||
|
||||
rows := [][]models.InlineKeyboardButton{
|
||||
{
|
||||
{Text: fmt.Sprintf("Type: %s", mediaTypeLabel), CallbackData: "settings_media_type"},
|
||||
{Text: fmt.Sprintf("Quality: %s", qualityLabel), CallbackData: "settings_quality"},
|
||||
{Text: fmt.Sprintf("Format: %s/%s", audioFmt, videoFmt), CallbackData: "settings_format"},
|
||||
},
|
||||
{
|
||||
{Text: fmt.Sprintf("Container: %s", containerLabel), CallbackData: "settings_container"},
|
||||
@@ -73,11 +69,14 @@ func (h *Handler) handleSettingsSelection(ctx context.Context, chatID int64, msg
|
||||
}
|
||||
|
||||
switch setting {
|
||||
case "media_type":
|
||||
text, kb := h.buildMediaTypePicker(prefs)
|
||||
case "format":
|
||||
text, kb := h.buildFormatPicker(prefs)
|
||||
h.editText(ctx, chatID, msgID, text, &kb)
|
||||
case "quality":
|
||||
text, kb := h.buildQualityPicker(prefs)
|
||||
case "format_audio":
|
||||
text, kb := h.buildAudioFormatPicker(prefs)
|
||||
h.editText(ctx, chatID, msgID, text, &kb)
|
||||
case "format_video":
|
||||
text, kb := h.buildVideoFormatPicker(prefs)
|
||||
h.editText(ctx, chatID, msgID, text, &kb)
|
||||
case "container":
|
||||
text, kb := h.buildContainerPicker(prefs)
|
||||
@@ -88,53 +87,54 @@ func (h *Handler) handleSettingsSelection(ctx context.Context, chatID int64, msg
|
||||
}
|
||||
}
|
||||
|
||||
func (h *Handler) buildMediaTypePicker(prefs *domain.UserPreferences) (string, models.InlineKeyboardMarkup) {
|
||||
options := []struct {
|
||||
label string
|
||||
value domain.MediaType
|
||||
data string
|
||||
}{
|
||||
{"Audio Only", domain.MediaTypeAudio, "settings_set_type_audio"},
|
||||
{"Video Only", domain.MediaTypeVideo, "settings_set_type_video"},
|
||||
{"Video+Audio", domain.MediaTypeVideoAudio, "settings_set_type_both"},
|
||||
func (h *Handler) buildFormatPicker(prefs *domain.UserPreferences) (string, models.InlineKeyboardMarkup) {
|
||||
rows := [][]models.InlineKeyboardButton{
|
||||
{{Text: "Audio", CallbackData: "settings_format_audio"}},
|
||||
{{Text: "Video", CallbackData: "settings_format_video"}},
|
||||
{{Text: "Back to Settings", CallbackData: "back_settings"}},
|
||||
}
|
||||
return "Choose format type to set default:", models.InlineKeyboardMarkup{InlineKeyboard: rows}
|
||||
}
|
||||
|
||||
func (h *Handler) buildAudioFormatPicker(prefs *domain.UserPreferences) (string, models.InlineKeyboardMarkup) {
|
||||
bitrates := []string{"best", "128k", "192k", "256k", "320k"}
|
||||
rows := [][]models.InlineKeyboardButton{}
|
||||
for _, opt := range options {
|
||||
label := opt.label
|
||||
if opt.value == prefs.DefaultMediaType {
|
||||
for _, b := range bitrates {
|
||||
label := b
|
||||
if b == prefs.DefaultAudioFormat {
|
||||
label = "> " + label
|
||||
}
|
||||
rows = append(rows, []models.InlineKeyboardButton{
|
||||
{Text: label, CallbackData: opt.data},
|
||||
{Text: label, CallbackData: "settings_set_audioformat_" + b},
|
||||
})
|
||||
}
|
||||
rows = append(rows, []models.InlineKeyboardButton{
|
||||
{Text: "Back to Settings", CallbackData: "back_settings"},
|
||||
{Text: "Back", CallbackData: "back_format"},
|
||||
})
|
||||
return "Select default media type:", models.InlineKeyboardMarkup{InlineKeyboard: rows}
|
||||
return "Select default audio format:", models.InlineKeyboardMarkup{InlineKeyboard: rows}
|
||||
}
|
||||
|
||||
func (h *Handler) buildQualityPicker(prefs *domain.UserPreferences) (string, models.InlineKeyboardMarkup) {
|
||||
qualities := []string{"best", "2160p", "1080p", "720p", "480p", "360p"}
|
||||
func (h *Handler) buildVideoFormatPicker(prefs *domain.UserPreferences) (string, models.InlineKeyboardMarkup) {
|
||||
resolutions := []string{"best", "2160p", "1440p", "1080p", "720p", "480p", "360p"}
|
||||
rows := [][]models.InlineKeyboardButton{}
|
||||
row := []models.InlineKeyboardButton{}
|
||||
for i, q := range qualities {
|
||||
label := q
|
||||
if q == prefs.DefaultQuality {
|
||||
for i, r := range resolutions {
|
||||
label := r
|
||||
if r == prefs.DefaultVideoFormat {
|
||||
label = "> " + label
|
||||
}
|
||||
row = append(row, models.InlineKeyboardButton{
|
||||
Text: label, CallbackData: "settings_set_quality_" + q,
|
||||
Text: label, CallbackData: "settings_set_videoformat_" + r,
|
||||
})
|
||||
if len(row) == 3 || i == len(qualities)-1 {
|
||||
if len(row) == 3 || i == len(resolutions)-1 {
|
||||
rows = append(rows, row)
|
||||
row = nil
|
||||
}
|
||||
}
|
||||
rows = append(rows, []models.InlineKeyboardButton{
|
||||
{Text: "Back to Settings", CallbackData: "back_settings"},
|
||||
{Text: "Back", CallbackData: "back_format"},
|
||||
})
|
||||
return "Select default quality:", models.InlineKeyboardMarkup{InlineKeyboard: rows}
|
||||
return "Select default video format:", models.InlineKeyboardMarkup{InlineKeyboard: rows}
|
||||
}
|
||||
|
||||
func (h *Handler) buildContainerPicker(prefs *domain.UserPreferences) (string, models.InlineKeyboardMarkup) {
|
||||
@@ -203,18 +203,11 @@ func (h *Handler) handleSettingsSet(ctx context.Context, chatID int64, msgID int
|
||||
|
||||
changed := false
|
||||
switch action {
|
||||
case "type":
|
||||
switch value {
|
||||
case "audio":
|
||||
prefs.DefaultMediaType = domain.MediaTypeAudio
|
||||
case "video":
|
||||
prefs.DefaultMediaType = domain.MediaTypeVideo
|
||||
case "both":
|
||||
prefs.DefaultMediaType = domain.MediaTypeVideoAudio
|
||||
}
|
||||
case "audioformat":
|
||||
prefs.DefaultAudioFormat = value
|
||||
changed = true
|
||||
case "quality":
|
||||
prefs.DefaultQuality = value
|
||||
case "videoformat":
|
||||
prefs.DefaultVideoFormat = value
|
||||
changed = true
|
||||
case "container":
|
||||
prefs.DefaultContainer = value
|
||||
|
||||
Reference in New Issue
Block a user