func unsubscribe(pfc *PFContext) (interface{}, error) { r := pfc.R subscriptionID := r.PostFormValue("subscription") folderID := r.PostFormValue("folder") // Remove a subscription ref := storage.SubscriptionRef{ FolderRef: storage.FolderRef{ UserID: pfc.UserID, FolderID: folderID, }, SubscriptionID: subscriptionID, } if exists, err := storage.SubscriptionExists(pfc.C, ref); err != nil { return nil, err } else if !exists { return nil, NewReadableError(_l("Subscription not found"), nil) } if err := storage.Unsubscribe(pfc.C, ref); err != nil { return nil, err } params := taskParams{ "subscriptionID": subscriptionID, "folderID": folderID, } if err := startTask(pfc, "unsubscribe", params, modificationQueue); err != nil { return nil, NewReadableError(_l("Cannot unsubscribe - too busy"), &err) } return storage.NewUserSubscriptions(pfc.C, pfc.UserID) }
func moveSubscription(pfc *PFContext) (interface{}, error) { r := pfc.R subscriptionID := r.PostFormValue("subscription") folderID := r.PostFormValue("folder") destinationID := r.PostFormValue("destination") destination := storage.FolderRef{ UserID: pfc.UserID, FolderID: destinationID, } if destinationID != "" { if exists, err := storage.FolderExists(pfc.C, destination); err != nil { return nil, err } else if !exists { return nil, NewReadableError(_l("Folder not found"), nil) } } ref := storage.SubscriptionRef{ FolderRef: storage.FolderRef{ UserID: pfc.UserID, FolderID: folderID, }, SubscriptionID: subscriptionID, } if exists, err := storage.SubscriptionExists(pfc.C, ref); err != nil { return nil, err } else if !exists { return nil, NewReadableError(_l("Subscription not found"), nil) } if err := storage.MoveSubscription(pfc.C, ref, destination); err != nil { return nil, err } params := taskParams{ "subscriptionID": subscriptionID, "folderID": folderID, "destinationID": destinationID, } if err := startTask(pfc, "moveSubscription", params, modificationQueue); err != nil { return nil, err } return storage.NewUserSubscriptions(pfc.C, pfc.UserID) }
func rename(pfc *PFContext) (interface{}, error) { r := pfc.R title := r.PostFormValue("title") if title == "" { return nil, NewReadableError(_l("Name not specified"), nil) } ref, err := storage.SubscriptionRefFromJSON(pfc.UserID, r.PostFormValue("ref")) if err != nil { return nil, err } if ref.IsSubscriptionExplicit() { if exists, err := storage.SubscriptionExists(pfc.C, ref); err != nil { return nil, err } else if !exists { return nil, NewReadableError(_l("Subscription not found"), nil) } if err := storage.RenameSubscription(pfc.C, ref, title); err != nil { return nil, NewReadableError(_l("Error renaming subscription"), &err) } } else { if exists, err := storage.FolderExists(pfc.C, ref.FolderRef); err != nil { return nil, err } else if !exists { return nil, NewReadableError(_l("Folder not found"), nil) } if isDupe, err := storage.IsFolderDuplicate(pfc.C, pfc.UserID, title); err != nil { return nil, err } else if isDupe { return nil, NewReadableError(_l("A folder with that name already exists"), nil) } if err := storage.RenameFolder(pfc.C, ref.FolderRef, title); err != nil { return nil, NewReadableError(_l("Error renaming folder"), &err) } } return storage.NewUserSubscriptions(pfc.C, pfc.UserID) }
func markAllAsRead(pfc *PFContext) (interface{}, error) { r := pfc.R subscriptionID := r.PostFormValue("subscription") folderID := r.PostFormValue("folder") if subscriptionID != "" { ref := storage.SubscriptionRef{ FolderRef: storage.FolderRef{ UserID: pfc.UserID, FolderID: folderID, }, SubscriptionID: subscriptionID, } if exists, err := storage.SubscriptionExists(pfc.C, ref); err != nil { return nil, err } else if !exists { return nil, NewReadableError(_l("Subscription not found"), nil) } } else if folderID != "" { ref := storage.FolderRef{ UserID: pfc.UserID, FolderID: folderID, } if exists, err := storage.FolderExists(pfc.C, ref); err != nil { return nil, err } else if !exists { return nil, NewReadableError(_l("Folder not found"), nil) } } params := taskParams{ "subscriptionID": subscriptionID, "folderID": folderID, } if err := startTask(pfc, "markAllAsRead", params, modificationQueue); err != nil { return nil, err } return _l("Please wait…"), nil }
func subscribeTask(pfc *PFContext) (TaskMessage, error) { subscriptionURL := pfc.R.PostFormValue("url") folderID := pfc.R.PostFormValue("folderID") if subscriptionURL == "" { return TaskMessage{}, errors.New("Missing subscription URL") } subscriptionRef := storage.SubscriptionRef{ FolderRef: storage.FolderRef{ UserID: pfc.UserID, FolderID: folderID, }, SubscriptionID: subscriptionURL, } if exists, err := storage.SubscriptionExists(pfc.C, subscriptionRef); err != nil { return TaskMessage{}, err } else if !exists { pfc.C.Warningf("No longer subscribed to %s", subscriptionURL, err) return TaskMessage{}, nil } if feed, err := storage.FeedByURL(pfc.C, subscriptionURL); err != nil { return TaskMessage{}, err } else if feed == nil { // Feed not available locally - fetch it client := createHttpClient(pfc.C) if response, err := client.Get(subscriptionURL); err != nil { pfc.C.Errorf("Error downloading feed (%s): %s", subscriptionURL, err) return TaskMessage{}, NewReadableError(_l("An error occurred while downloading the feed"), &err) } else { defer response.Body.Close() if parsedFeed, err := rss.UnmarshalStream(subscriptionURL, response.Body); err != nil { pfc.C.Errorf("Error reading RSS content (%s): %s", subscriptionURL, err) return TaskMessage{}, NewReadableError(_l("Error reading RSS content"), &err) } else { favIconURL := "" if parsedFeed.WWWURL != "" { if url, err := locateFavIconURL(pfc.C, parsedFeed.WWWURL); err != nil { // Not critical pfc.C.Warningf("FavIcon retrieval error: %s", err) } else if url != "" { favIconURL = url } } if err := storage.UpdateFeed(pfc.C, parsedFeed, favIconURL, time.Now()); err != nil { return TaskMessage{}, err } } } } if _, err := storage.UpdateSubscription(pfc.C, subscriptionURL, subscriptionRef); err != nil { return TaskMessage{}, err } return TaskMessage{ Refresh: true, }, nil }