Skip to content

Commit

Permalink
fix: rename query back to subscription
Browse files Browse the repository at this point in the history
  • Loading branch information
akurilov committed Apr 5, 2024
1 parent 63f8ac1 commit bd2798e
Show file tree
Hide file tree
Showing 13 changed files with 33 additions and 33 deletions.
2 changes: 1 addition & 1 deletion api/grpc/tgbot/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func (c controller) Subscribe(ctx context.Context, req *SubscribeRequest) (resp
var d subscription.Data
d, err = c.clientAwk.ReadSubscription(groupIdCtx, userId, subId)
if err == nil {
_ = tgCtx.Send(fmt.Sprintf("New query \"%s\" is linked to this chat", d.Description))
_ = tgCtx.Send(fmt.Sprintf("New subscription \"%s\" is linked to this chat", d.Description))
}
}
return
Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,15 +239,15 @@ func main() {
},
{
Text: "app",
Description: "Manage Queries and Publishing in Application",
Description: "Manage Subscriptions and Publishing in Application",
},
{
Text: "pub",
Description: "Publish a basic Message",
},
{
Text: "sub",
Description: "Query for Keywords",
Description: "Subscribe for Keywords",
},
{
Text: "donate",
Expand Down
2 changes: 1 addition & 1 deletion service/chats/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ package chats
import "errors"

var ErrAlreadyExists = errors.New("chat already exists")
var ErrNotFound = errors.New("chat or query not found")
var ErrNotFound = errors.New("chat or subscription not found")
var ErrInternal = errors.New("internal failure")
8 changes: 4 additions & 4 deletions service/chats/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ const msgFmtReadOnceFailed = "unexpected failure: %s\ndon't worry, retrying in %
const backOffInit = 1 * time.Second
const backOffFactor = 3
const backOffMax = 24 * time.Hour
const msgExpired = "⚠ The query has been expired."
const msgExpiresSoon = "⏳ The query expires in %s."
const msgExpired = "⚠ The subscription has been expired."
const msgExpiresSoon = "⏳ The subscription expires in %s."
const msgFmtExtendSteps = " Please extend it."
const resumeBatchSize = 16
const minIntervalLimit = 1 * time.Second
Expand Down Expand Up @@ -191,7 +191,7 @@ func (r *reader) runOnce() (err error) {
case errors.Is(err, api.ErrApiDisabled):
fallthrough
case errors.Is(err, clientAwkApiReader.ErrNotFound):
_ = r.tgCtx.Send(fmt.Sprintf("failed to read by query: %s, cause: %s, stopping", err, r.subId))
_ = r.tgCtx.Send(fmt.Sprintf("failed to read by subscription: %s, cause: %s, stopping", err, r.subId))
_ = r.chatStor.UnlinkSubscription(ctx, r.subId)
r.stop = true
err = nil
Expand Down Expand Up @@ -250,7 +250,7 @@ func (r *reader) deliverEventsRead(
}
}
case codes.NotFound:
_ = r.tgCtx.Send(fmt.Sprintf("query %s doesn't exist, stopping", r.subId))
_ = r.tgCtx.Send(fmt.Sprintf("subscription %s doesn't exist, stopping", r.subId))
_ = r.chatStor.UnlinkSubscription(ctx, r.subId)
r.stop = true
err = nil
Expand Down
2 changes: 1 addition & 1 deletion service/messages/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (f Format) convert(evt *pb.CloudEvent, subDescr string, mode FormatMode, tr
if txt == "" && attrNameFound {
txt = fmt.Sprintf("%s\n\n", attrName.GetCeString())
}
txt += fmt.Sprintf("Query: %s\n\nsource: %s\n", subDescr, evt.Source)
txt += fmt.Sprintf("Subscription: %s\n\nsource: %s\n", subDescr, evt.Source)
var attrsTxt string
if attrs {
attrsTxt = f.convertExtraAttrs(evt, mode, trunc)
Expand Down
2 changes: 1 addition & 1 deletion service/subscriptions/condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (ch ConditionHandler) Update(tgCtx telebot.Context, args ...string) (err er
err = ch.ClientAwk.UpdateSubscription(groupIdCtx, userId, subId, sd)
}
if err == nil {
_ = tgCtx.Send("Query updated.")
_ = tgCtx.Send("Subscription updated.")
}
return
}
Expand Down
14 changes: 7 additions & 7 deletions service/subscriptions/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ const maxTextCondTermsLength = 256
const expiresDefaultDuration = time.Hour * 24 * usage.ExpiresDefaultDays // ~ month

const ReqSubCreate = "sub_create"
const msgSubCreate = "Creating a simple text query. " +
const msgSubCreate = "Creating a simple text subscription. " +
"Reply a name followed by keywords to the next message. Example:\n" +
"<pre>Wishlist1 tesla iphone</pre>"
const msgSubCreated = "If you want to read it in another chat, unlink it first using the <pre>/start</pre> command."

var errCreateSubNotEnoughArgs = errors.New("not enough arguments to create a text query")
var errInvalidCondition = errors.New("invalid query condition")
var errCreateSubNotEnoughArgs = errors.New("not enough arguments to create a text subscription")
var errInvalidCondition = errors.New("invalid subscription condition")
var errLimitReached = errors.New("limit reached")
var whiteSpaceRegex = regexp.MustCompile(`\p{Zs}+`)

Expand Down Expand Up @@ -71,12 +71,12 @@ func CreateBasicReplyHandlerFunc(clientAwk api.Client, groupId string) service.A
if err == nil {
err = requestDeliveryInterval(tgCtx, subId)
} else {
err = fmt.Errorf("failed to create the query:\n%w", err)
err = fmt.Errorf("failed to create the subscription:\n%w", err)
}
if err == nil {
err = tgCtx.Send(msgSubCreated, telebot.ModeHTML)
} else {
err = fmt.Errorf("failed to link the created query to this chat:\n%w", err)
err = fmt.Errorf("failed to link the created subscription to this chat:\n%w", err)
}
return
}
Expand Down Expand Up @@ -127,7 +127,7 @@ func decodeNumOp(src subscriptions.Operation) (dst condition.NumOp) {

func validateSubscriptionData(sd subscription.Data) (err error) {
if sd.Description == "" {
err = errors.New("invalid query:\nempty description")
err = errors.New("invalid subscription:\nempty description")
}
if err == nil {
err = validateCondition(sd.Condition)
Expand All @@ -142,7 +142,7 @@ func validateCondition(cond condition.Condition) (err error) {
countChildren := len(children)
if tc.GetLogic() == condition.GroupLogicOr && countChildren > limitGroupOrCondChildrenCount {
err = fmt.Errorf(
"%w:\nchildren condition count for the group condition with \"Or\" logic is %d, limit is %d,\nconsider to use an additional query instead",
"%w:\nchildren condition count for the group condition with \"Or\" logic is %d, limit is %d,\nconsider to use an additional subscription instead",
errInvalidCondition,
countChildren,
limitGroupOrCondChildrenCount,
Expand Down
2 changes: 1 addition & 1 deletion service/subscriptions/description.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func DescriptionReplyHandlerFunc(clientAwk api.Client, groupId string) service.A
}
if err == nil {
// force reply removes the keyboard, hence don't forget to restore it
err = tgCtx.Send(fmt.Sprintf("Query description changed to \"%s\"", descr))
err = tgCtx.Send(fmt.Sprintf("Subscription description changed to \"%s\"", descr))
}
return
}
Expand Down
10 changes: 5 additions & 5 deletions service/subscriptions/extend.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const CmdExtend = "extend"
const ReqSubExtend = "sub_extend"
const daysMin = 10
const daysMax = 365
const msgFmtRunOnceFailed = "failed to extend the query, id: %s, user id: %s, cause: %s, retrying in: %s"
const msgFmtRunOnceFailed = "failed to extend the subscription, id: %s, user id: %s, cause: %s, retrying in: %s"

type ExtendHandler struct {
CfgPayment config.PaymentConfig
Expand Down Expand Up @@ -90,8 +90,8 @@ func (eh ExtendHandler) HandleExtensionReply(tgCtx telebot.Context, args ...stri
price := int(float64(countDays) * eh.CfgPayment.Price.Subscription.Extension * eh.CfgPayment.Currency.SubFactor)
invoice := telebot.Invoice{
Start: uuid.NewString(),
Title: "Query Extension",
Description: fmt.Sprintf("Query %s: extend by %d days", subId, countDays),
Title: "Subscription Extension",
Description: fmt.Sprintf("Subscription %s: extend by %d days", subId, countDays),
Payload: string(orderData),
Currency: eh.CfgPayment.Currency.Code,
Prices: []telebot.Price{
Expand Down Expand Up @@ -146,12 +146,12 @@ func (eh ExtendHandler) ExtendPaid(tgCtx telebot.Context, args ...string) (err e
err = backoff.RetryNotify(e.runOnce, b, func(err error, d time.Duration) {
eh.Log.Warn(fmt.Sprintf(msgFmtRunOnceFailed, op.SubId, userId, err, d))
if d > 1*time.Second {
_ = tgCtx.Send("Extending the query, please wait...")
_ = tgCtx.Send("Extending the subscription, please wait...")
}
})
}
if err == nil {
err = tgCtx.Send(fmt.Sprintf("Query has been successfully extended by %d days", op.DaysAdd))
err = tgCtx.Send(fmt.Sprintf("Subscription has been successfully extended by %d days", op.DaysAdd))
}
return
}
Expand Down
4 changes: 2 additions & 2 deletions service/subscriptions/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func ListOnGroupStartHandlerFunc(clientAwk api.Client, chatStor chats.Storage, g
m, err = listButtons(groupIdCtx, userId, clientAwk, chatStor, tgCtx.Chat().ID, CmdStart, "")
if err == nil {
err = tgCtx.Send(
"Own queries list. "+
"Own subscriptions list. "+
"Use the <a href=\"https://awakari.com/login.html\" target=\"_blank\">app</a> to manage. "+
"Select one or more to read in this chat:",
m, telebot.ModeHTML,
Expand All @@ -42,7 +42,7 @@ func PageNext(clientAwk api.Client, chatStor chats.Storage, groupId string) serv
var m *telebot.ReplyMarkup
m, err = listButtons(groupIdCtx, userId, clientAwk, chatStor, tgCtx.Chat().ID, args[0], cursor)
if err == nil {
err = tgCtx.Send("Own queries list page:", m, telebot.ModeHTML)
err = tgCtx.Send("Own subscriptions list page:", m, telebot.ModeHTML)
}
return
}
Expand Down
6 changes: 3 additions & 3 deletions service/subscriptions/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import (
)

const CmdStart = "sub_start"
const msgFmtChatLinked = "Linked the query \"%s\" to this chat. " +
const msgFmtChatLinked = "Linked the subscription \"%s\" to this chat. " +
"New matching messages will appear here with a minimum interval of %s. " +
"Use the <a href=\"https://awakari.com/login.html\" target=\"blank\">app</a> to manage own queries."
"Use the <a href=\"https://awakari.com/login.html\" target=\"blank\">app</a> to manage own subscriptions."

var deliveryIntervalRows = [][]string{
{
Expand Down Expand Up @@ -75,7 +75,7 @@ func requestDeliveryInterval(tgCtx telebot.Context, subId string) (err error) {
rows = append(rows, row)
}
m.Inline(rows...)
err = tgCtx.Send("Choose the minimum interval for the message delivery for this query:", m)
err = tgCtx.Send("Choose the minimum interval for the message delivery for this subscription:", m)
return
}

Expand Down
4 changes: 2 additions & 2 deletions service/subscriptions/stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ func Stop(chatStor chats.Storage) service.ArgHandlerFunc {
err = chatStor.UnlinkSubscription(context.Background(), subId)
if err == nil {
if chats.StopChatReader(subId) {
_ = tgCtx.Send("Unlinked the query from this chat")
_ = tgCtx.Send("Unlinked the subscription from this chat")
} else {
_ = tgCtx.Send(fmt.Sprintf("Unlinked the query from this chat. Note: don't delete this group for the next %s. Some new messages may appear here.", chats.ReaderTtl))
_ = tgCtx.Send(fmt.Sprintf("Unlinked the subscription from this chat. Note: don't delete this group for the next %s. Some new messages may appear here.", chats.ReaderTtl))
}
}
return
Expand Down
6 changes: 3 additions & 3 deletions service/usage/limits.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (lh LimitsHandler) RequestExtension(tgCtx telebot.Context, args ...string)
//case usage.SubjectSubscriptions:
// err = tgCtx.Send(
// fmt.Sprintf(
// "The limit extension price is %s %.2f per day per query starting from 2nd. "+
// "The limit extension price is %s %.2f per day per subscription starting from 2nd. "+
// "Reply with the count of days to add:",
// lh.CfgPayment.Currency.Code,
// lh.CfgPayment.Price.Subscription.CountLimit,
Expand Down Expand Up @@ -220,7 +220,7 @@ func formatUsageSubject(subj usage.Subject) (s string) {
case usage.SubjectPublishEvents:
s = "Message Daily Publications"
case usage.SubjectSubscriptions:
s = "Queries Count"
s = "Subscriptions Count"
default:
s = "undefined"
}
Expand Down Expand Up @@ -249,7 +249,7 @@ func (lh LimitsHandler) RequestIncrease(tgCtx telebot.Context, args ...string) (
err = tgCtx.Send(
fmt.Sprintf(
// TODO: uncomment the code below only when payments are in use
//"The price is %s %.2f per day per additional query. "+
//"The price is %s %.2f per day per additional subscription. "+
"Reply the count to add to the current limit:",
// TODO: uncomment the code below only when payments are in use
//lh.CfgPayment.Currency.Code,
Expand Down

0 comments on commit bd2798e

Please sign in to comment.