Rework FreeTube subscription import

This commit is contained in:
Preston 2020-10-08 21:19:29 -04:00
parent 9872f175d3
commit d19615121d
1 changed files with 38 additions and 8 deletions

View File

@ -118,6 +118,8 @@ export default Vue.extend({
importingOldFormat = true importingOldFormat = true
} }
const primaryProfile = JSON.parse(JSON.stringify(this.profileList[0]))
textDecode.forEach((profileData) => { textDecode.forEach((profileData) => {
// We would technically already be done by the time the data is parsed, // We would technically already be done by the time the data is parsed,
// however we want to limit the possibility of malicious data being sent // however we want to limit the possibility of malicious data being sent
@ -149,18 +151,46 @@ export default Vue.extend({
message: message message: message
}) })
} else { } else {
if (importingOldFormat && profileObject.name === 'All Channels') { if (profileObject.name === 'All Channels' || profileObject._id === 'allChannels') {
const primaryProfile = JSON.parse(JSON.stringify(this.profileList[0]))
// filter out subscriptions that already exist before concatenating
profileObject.subscriptions = profileObject.subscriptions.filter(newSub => {
const subExists = primaryProfile.subscriptions.find(existingSub => existingSub.id === newSub.id)
return !subExists // return false if sub already exists in default profile
})
primaryProfile.subscriptions = primaryProfile.subscriptions.concat(profileObject.subscriptions) primaryProfile.subscriptions = primaryProfile.subscriptions.concat(profileObject.subscriptions)
primaryProfile.subscriptions = primaryProfile.subscriptions.filter((sub, index) => {
const profileIndex = primaryProfile.subscriptions.findIndex((x) => {
return x.name === sub.name
})
return profileIndex === index
})
this.updateProfile(primaryProfile) this.updateProfile(primaryProfile)
} else {
const existingProfileIndex = this.profileList.findIndex((profile) => {
return profile.name.includes(profileObject.name)
})
if (existingProfileIndex !== -1) {
const existingProfile = JSON.parse(JSON.stringify(this.profileList[existingProfileIndex]))
existingProfile.subscriptions = existingProfile.subscriptions.concat(profileObject.subscriptions)
existingProfile.subscriptions = existingProfile.subscriptions.filter((sub, index) => {
const profileIndex = existingProfile.subscriptions.findIndex((x) => {
return x.name === sub.name
})
return profileIndex === index
})
this.updateProfile(existingProfile)
} else { } else {
this.updateProfile(profileObject) this.updateProfile(profileObject)
} }
primaryProfile.subscriptions = primaryProfile.subscriptions.concat(profileObject.subscriptions)
primaryProfile.subscriptions = primaryProfile.subscriptions.filter((sub, index) => {
const profileIndex = primaryProfile.subscriptions.findIndex((x) => {
return x.name === sub.name
})
return profileIndex === index
})
this.updateProfile(primaryProfile)
}
} }
}) })