Fix invalid domain error in collect input.

This commit is contained in:
Naoki Kosaka 2019-02-11 17:44:16 +09:00
parent 234dcbf99a
commit 664d0cf3b3
4 changed files with 47 additions and 15 deletions

View File

@ -106,6 +106,16 @@ func (config *RelayState) DelSubscription(domain string) {
config.Load()
}
// SelectSubscription : Select instance from string
func (config *RelayState) SelectSubscription(domain string) *Subscription {
for _, subscription := range config.Subscriptions {
if domain == subscription.Domain {
return &subscription
}
}
return nil
}
// SetBlockedDomain : Set/Unset instance for blocked domain
func (config *RelayState) SetBlockedDomain(domain string, value bool) {
if value {

24
cli/contain.go Normal file
View File

@ -0,0 +1,24 @@
package main
import state "github.com/yukimochi/Activity-Relay/State"
func contains(entries interface{}, finder string) bool {
switch entry := entries.(type) {
case string:
return entry == finder
case []string:
for i := 0; i < len(entry); i++ {
if entry[i] == finder {
return true
}
}
case []state.Subscription:
for i := 0; i < len(entry); i++ {
if entry[i].Domain == finder {
return true
}
}
return false
}
return false
}

View File

@ -119,15 +119,15 @@ func setDomainType(cmd *cobra.Command, args []string) error {
func unfollowDomains(cmd *cobra.Command, args []string) error {
subscriptions := relayState.Subscriptions
for _, domain := range args {
for _, subscription := range subscriptions {
if domain == subscription.Domain {
cmd.Println("Unfollow [" + domain + "]")
createUnfollowRequestResponse(subscription)
relayState.DelSubscription(subscription.Domain)
break
}
if contains(subscriptions, domain) {
subscription := *relayState.SelectSubscription(domain)
cmd.Println("Unfollow [" + subscription.Domain + "]")
createUnfollowRequestResponse(subscription)
relayState.DelSubscription(subscription.Domain)
break
} else {
cmd.Println("Invalid domain [" + domain + "] given")
}
cmd.Println("Invalid domain [" + domain + "] given")
}
return nil

View File

@ -130,14 +130,12 @@ func acceptFollow(cmd *cobra.Command, args []string) error {
}
for _, domain := range args {
for _, request := range domains {
if domain == request {
cmd.Println("Accept [" + domain + "] follow request")
createFollowRequestResponse(domain, "Accept")
break
}
if contains(domains, domain) {
cmd.Println("Accept [" + domain + "] follow request")
createFollowRequestResponse(domain, "Accept")
} else {
cmd.Println("Invalid domain [" + domain + "] given")
}
cmd.Println("Invalid domain [" + domain + "] given")
}
return nil