Skip to content

Commit

Permalink
Rollback telegram changes. Fixed removing disabled domain notificatio…
Browse files Browse the repository at this point in the history
…ns. (#50)
  • Loading branch information
ice-myles authored Jun 27, 2024
1 parent 0edaff2 commit 8dc7c53
Show file tree
Hide file tree
Showing 39 changed files with 508 additions and 1,128 deletions.
7 changes: 0 additions & 7 deletions application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,6 @@ notifications: &notifications
replicaURLs:
- postgresql://root:pass@localhost:5434/husky
tenantName: BogusName
tokenName: BN
wintr/notifications/telegram:
botToken: bogus
telegramBots:
bogusBot:
botToken: bogus
webAppLink: https://bogus.com/startapp
messageBroker: &notificationsMessageBroker
consumerGroup: husky-local-notifications-testing
createTopics: true
Expand Down
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ require (
github.com/goccy/go-json v0.10.3
github.com/google/uuid v1.6.0
github.com/hashicorp/go-multierror v1.1.1
github.com/ice-blockchain/eskimo v1.339.0
github.com/ice-blockchain/freezer v1.470.0
github.com/ice-blockchain/eskimo v1.343.0
github.com/ice-blockchain/freezer v1.472.0
github.com/ice-blockchain/go-tarantool-client v0.0.0-20230327200757-4fc71fa3f7bb
github.com/ice-blockchain/wintr v1.142.0
github.com/imroc/req/v3 v3.43.7
Expand All @@ -25,8 +25,8 @@ require (
cloud.google.com/go/auth/oauth2adapt v0.2.2 // indirect
cloud.google.com/go/compute/metadata v0.3.0 // indirect
cloud.google.com/go/firestore v1.15.0 // indirect
cloud.google.com/go/iam v1.1.8 // indirect
cloud.google.com/go/longrunning v0.5.7 // indirect
cloud.google.com/go/iam v1.1.9 // indirect
cloud.google.com/go/longrunning v0.5.8 // indirect
cloud.google.com/go/storage v1.42.0 // indirect
dario.cat/mergo v1.0.0 // indirect
firebase.google.com/go/v4 v4.14.1 // indirect
Expand Down Expand Up @@ -64,7 +64,7 @@ require (
github.com/distribution/reference v0.6.0 // indirect
github.com/dmarkham/enumer v1.5.10 // indirect
github.com/docker/distribution v2.8.3+incompatible // indirect
github.com/docker/docker v27.0.1+incompatible // indirect
github.com/docker/docker v27.0.2+incompatible // indirect
github.com/docker/go-connections v0.5.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/ethereum/c-kzg-4844 v1.0.2 // indirect
Expand Down
22 changes: 12 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ cloud.google.com/go/compute/metadata v0.3.0 h1:Tz+eQXMEqDIKRsmY3cHTL6FVaynIjX2Qx
cloud.google.com/go/compute/metadata v0.3.0/go.mod h1:zFmK7XCadkQkj6TtorcaGlCW1hT1fIilQDwofLpJ20k=
cloud.google.com/go/firestore v1.15.0 h1:/k8ppuWOtNuDHt2tsRV42yI21uaGnKDEQnRFeBpbFF8=
cloud.google.com/go/firestore v1.15.0/go.mod h1:GWOxFXcv8GZUtYpWHw/w6IuYNux/BtmeVTMmjrm4yhk=
cloud.google.com/go/iam v1.1.8 h1:r7umDwhj+BQyz0ScZMp4QrGXjSTI3ZINnpgU2nlB/K0=
cloud.google.com/go/iam v1.1.8/go.mod h1:GvE6lyMmfxXauzNq8NbgJbeVQNspG+tcdL/W8QO1+zE=
cloud.google.com/go/longrunning v0.5.7 h1:WLbHekDbjK1fVFD3ibpFFVoyizlLRl73I7YKuAKilhU=
cloud.google.com/go/longrunning v0.5.7/go.mod h1:8GClkudohy1Fxm3owmBGid8W0pSgodEMwEAztp38Xng=
cloud.google.com/go/iam v1.1.9 h1:oSkYLVtVme29uGYrOcKcvJRht7cHJpYD09GM9JaR0TE=
cloud.google.com/go/iam v1.1.9/go.mod h1:Nt1eDWNYH9nGQg3d/mY7U1hvfGmsaG9o/kLGoLoLXjQ=
cloud.google.com/go/longrunning v0.5.8 h1:QThI5BFSlYlS7K0wnABCdmKsXbG/htLc3nTPzrfOgeU=
cloud.google.com/go/longrunning v0.5.8/go.mod h1:oJDErR/mm5h44gzsfjQlxd6jyjFvuBPOxR1TLy2+cQk=
cloud.google.com/go/storage v1.42.0 h1:4QtGpplCVt1wz6g5o1ifXd656P5z+yNgzdw1tVfp0cU=
cloud.google.com/go/storage v1.42.0/go.mod h1:HjMXRFq65pGKFn6hxj6x3HCyR41uSB72Z0SO/Vn6JFQ=
dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk=
Expand Down Expand Up @@ -282,10 +282,10 @@ github.com/holiman/uint256 v1.2.4 h1:jUc4Nk8fm9jZabQuqr2JzednajVmBpC+oiTiXZJEApU
github.com/holiman/uint256 v1.2.4/go.mod h1:EOMSn4q6Nyt9P6efbI3bueV4e1b3dGlUCXeiRV4ng7E=
github.com/huin/goupnp v1.3.0 h1:UvLUlWDNpoUdYzb2TCn+MuTWtcjXKSza2n6CBdQ0xXc=
github.com/huin/goupnp v1.3.0/go.mod h1:gnGPsThkYa7bFi/KWmEysQRf48l2dvR5bxr2OFckNX8=
github.com/ice-blockchain/eskimo v1.339.0 h1:X5BA4yf1sJD+gMCG95wMcW0aiRIM7fImuqhn+AmTV6A=
github.com/ice-blockchain/eskimo v1.339.0/go.mod h1:312jKeVpNmEdjaYb6OEANmUEAsCZkf4Ynm004S0UChM=
github.com/ice-blockchain/freezer v1.470.0 h1:c0VF1SQrh/JyddgmxkcMUsg7ar/OGDVys610hhyzt50=
github.com/ice-blockchain/freezer v1.470.0/go.mod h1:fAqBnHQTyKNa7mytPb149yOewLqM2iSqlM9XaKNeueo=
github.com/ice-blockchain/eskimo v1.343.0 h1:GMIPNwVO283vLT2BW5w/27MlR6nnVndx4bV/EtWQjik=
github.com/ice-blockchain/eskimo v1.343.0/go.mod h1:GgnXx4x78wpFt315Aj917+36aLU5g/94Ohpl+ft++6c=
github.com/ice-blockchain/freezer v1.472.0 h1:YCI7btQuYb5R+1VBQf70OIJYkpshm8mujiSvbnjt9pw=
github.com/ice-blockchain/freezer v1.472.0/go.mod h1:Ep+or4+G74x/r8XBG340v07ov1S+9BWnc2eHqOC+VIY=
github.com/ice-blockchain/go-tarantool-client v0.0.0-20230327200757-4fc71fa3f7bb h1:8TnFP3mc7O+tc44kv2e0/TpZKnEVUaKH+UstwfBwRkk=
github.com/ice-blockchain/go-tarantool-client v0.0.0-20230327200757-4fc71fa3f7bb/go.mod h1:ZsQU7i3mxhgBBu43Oev7WPFbIjP4TniN/b1UPNGbrq8=
github.com/ice-blockchain/wintr v1.142.0 h1:pojlgGyNsbcMh3Hv8v0tD7ahsekneYyeU4UZs5tINnw=
Expand Down Expand Up @@ -363,6 +363,8 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A=
github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
github.com/onsi/ginkgo/v2 v2.19.0 h1:9Cnnf7UHo57Hy3k6/m5k3dRfGTMXGvxhHFvkDTCTpvA=
Expand Down Expand Up @@ -391,8 +393,8 @@ github.com/prometheus/client_golang v1.19.1/go.mod h1:mP78NwGzrVks5S2H6ab8+ZZGJL
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E=
github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY=
github.com/prometheus/common v0.54.0 h1:ZlZy0BgJhTwVZUn7dLOkwCZHUkrAqd3WYtcFCWnM1D8=
github.com/prometheus/common v0.54.0/go.mod h1:/TQgMJP5CuVYveyT7n/0Ix8yLNNXy9yRSkhnLTHPDIQ=
github.com/prometheus/common v0.55.0 h1:KEi6DK7lXW/m7Ig5i47x0vRzuBsHuvJdi5ee6Y3G1dc=
github.com/prometheus/common v0.55.0/go.mod h1:2SECS4xJG1kd8XF9IcM1gMX6510RAEL65zxzNImwdc8=
github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc=
github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk=
github.com/quic-go/qpack v0.4.0 h1:Cr9BXA1sQS2SmDUWjSofMPNKmvF6IiIfDRmgU0w1ZCo=
Expand Down
6 changes: 1 addition & 5 deletions notifications/DDL.sql
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,8 @@ CREATE TABLE IF NOT EXISTS users (
profile_picture_name TEXT,
referred_by TEXT,
phone_number_hash TEXT,
telegram_user_id TEXT NOT NULL,
telegram_bot_id TEXT NOT NULL,
language TEXT NOT NULL default 'en'
);
ALTER TABLE users ADD COLUMN IF NOT EXISTS telegram_user_id text NOT NULL;
ALTER TABLE users ADD COLUMN IF NOT EXISTS telegram_bot_id text NOT NULL;
--************************************************************************************************************************************
-- sent_notifications
CREATE TABLE IF NOT EXISTS sent_notifications (
Expand Down Expand Up @@ -49,7 +45,7 @@ CREATE TABLE IF NOT EXISTS scheduled_notifications (
notification_channel_value TEXT NOT NULL,
primary key(user_id,uniqueness,notification_type,notification_channel,notification_channel_value));
CREATE UNIQUE INDEX IF NOT EXISTS scheduled_notifications_i_ix ON scheduled_notifications (i);
CREATE INDEX IF NOT EXISTS scheduled_notifications_mod_i_ix ON scheduled_notifications (MOD(i, %[1]v), scheduled_for, notification_channel ASC);
CREATE INDEX IF NOT EXISTS scheduled_notifications_mod_i_ix ON scheduled_notifications (MOD(i, %[1]v), scheduled_for ASC);
CREATE INDEX IF NOT EXISTS scheduled_notifications_user_id_notification_type_ix ON scheduled_notifications (user_id,notification_type);
--************************************************************************************************************************************
-- sent_announcements
Expand Down
99 changes: 28 additions & 71 deletions notifications/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"github.com/ice-blockchain/wintr/multimedia/picture"
"github.com/ice-blockchain/wintr/notifications/inapp"
"github.com/ice-blockchain/wintr/notifications/push"
"github.com/ice-blockchain/wintr/notifications/telegram"
"github.com/ice-blockchain/wintr/time"
)

Expand All @@ -29,7 +28,6 @@ const (
SMSNotificationChannel NotificationChannel = "sms"
EmailNotificationChannel NotificationChannel = "email"
PushNotificationChannel NotificationChannel = "push"
TelegramNotificationChannel NotificationChannel = "telegram"
PushOrFallbackToEmailNotificationChannel NotificationChannel = "push||email"
)

Expand Down Expand Up @@ -84,7 +82,6 @@ var (
SMSNotificationChannel,
EmailNotificationChannel,
PushNotificationChannel,
TelegramNotificationChannel,
}
//nolint:gochecknoglobals // It's just for more descriptive validation messages.
AllNotificationTypes = users.Enum[NotificationType]{
Expand Down Expand Up @@ -112,24 +109,6 @@ var (
WeeklyStatsNotificationType,
}
//nolint:gochecknoglobals // It's just for more descriptive validation messages.
AllTelegramNotificationTypes = users.Enum[NotificationType]{
LevelBadgeUnlockedNotificationType,
CoinBadgeUnlockedNotificationType,
SocialBadgeUnlockedNotificationType,
RoleChangedNotificationType,
LevelChangedNotificationType,
MiningExtendNotificationType,
MiningEndingSoonNotificationType,
MiningExpiredNotificationType,
MiningNotActiveNotificationType,
InviteFriendNotificationType,
SocialsFollowIceOnXNotificationType,
SocialsFollowUsOnXNotificationType,
SocialsFollowZeusOnXNotificationType,
SocialsFollowIONOnTelegramNotificationType,
SocialsFollowOurTelegramNotificationType,
}
//nolint:gochecknoglobals // It's just for more descriptive validation messages.
AllNotificationDomains = map[NotificationChannel][]NotificationDomain{
EmailNotificationChannel: {
DisableAllNotificationDomain,
Expand Down Expand Up @@ -192,19 +171,16 @@ type (
CheckHealth(ctx context.Context) error
}
Scheduler struct {
pictureClient picture.Client
pushNotificationsClient push.Client
telegramNotificationsClient telegram.Client
cfg *config
schedulerPushAnnouncementsMX *sync.Mutex
schedulerPushNotificationsMX *sync.Mutex
schedulerTelegramNotificationsMX *sync.Mutex
telemetryPushNotifications *telemetry
telemetryTelegramNotifications *telemetry
telemetryAnnouncements *telemetry
db *storage.DB
wg *sync.WaitGroup
cancel context.CancelFunc
pictureClient picture.Client
pushNotificationsClient push.Client
cfg *config
schedulerAnnouncementsMX *sync.Mutex
schedulerNotificationsMX *sync.Mutex
telemetryNotifications *telemetry
telemetryAnnouncements *telemetry
db *storage.DB
wg *sync.WaitGroup
cancel context.CancelFunc
}
)

Expand All @@ -215,8 +191,8 @@ const (
requestingUserIDCtxValueKey = "requestingUserIDCtxValueKey"
requestDeadline = 30 * stdlibtime.Second

schedulerWorkersCount int64 = 10
schedulerPushBatchSize int64 = 250
schedulerWorkersCount int64 = 10
schedulerBatchSize int64 = 250
)

var (
Expand All @@ -227,18 +203,14 @@ var (
//nolint:gochecknoglobals // Its loaded once at startup.
allPushNotificationTemplates map[NotificationType]map[languageCode]*pushNotificationTemplate
//nolint:gochecknoglobals // Its loaded once at startup.
allTelegramNotificationTemplates map[NotificationType]map[languageCode]*telegramNotificationTemplate
//nolint:gochecknoglobals // Its loaded once at startup.
internationalizedEmailDisplayNames = map[string]string{
"en": "ice: Decentralized Future",
}
)

type (
languageCode = string
telegramBotID = string
telegramBotToken = string
user struct {
languageCode = string
user struct {
LastPingCooldownEndedAt *time.Time `json:"lastPingCooldownEndedAt,omitempty"`
DisabledPushNotificationDomains *users.Enum[NotificationDomain] `json:"disabledPushNotificationDomains,omitempty"`
DisabledEmailNotificationDomains *users.Enum[NotificationDomain] `json:"disabledEmailNotificationDomains,omitempty"`
Expand All @@ -253,8 +225,6 @@ type (
ReferredBy string `json:"referredBy,omitempty"`
PhoneNumberHash string `json:"phoneNumberHash,omitempty"`
Language string `json:"language,omitempty"`
TelegramUserID string `json:"telegramUserId,omitempty"`
TelegramBotID string `json:"telegramBotId,omitempty"`
AgendaContactUserIDs []string `json:"agendaContactUserIDs,omitempty" db:"agenda_contact_user_ids"`
}
userTableSource struct {
Expand Down Expand Up @@ -291,16 +261,15 @@ type (
*processor
}
repository struct {
cfg *config
shutdown func() error
db *storage.DB
mb messagebroker.Client
pushNotificationsClient push.Client
telegramNotificationsClient telegram.Client
emailClient email.Client
pictureClient picture.Client
personalInAppFeed inapp.Client
globalInAppFeed inapp.Client
cfg *config
shutdown func() error
db *storage.DB
mb messagebroker.Client
pushNotificationsClient push.Client
emailClient email.Client
pictureClient picture.Client
personalInAppFeed inapp.Client
globalInAppFeed inapp.Client
}
processor struct {
*repository
Expand All @@ -310,8 +279,6 @@ type (
MaxNotificationDelaySec uint `yaml:"maxNotificationDelaySec"`
}
scheduledNotificationInfo struct {
TelegramUserID string
TelegramBotID string
PushNotificationTokens *users.Enum[push.DeviceToken]
DisabledPushNotificationDomains *users.Enum[NotificationDomain]
scheduledNotification
Expand Down Expand Up @@ -343,14 +310,8 @@ type (
UserID string
Token push.DeviceToken
}
telegramNotification struct {
tn *telegram.Notification
sn *sentNotification
scheduled scheduledNotification
}
config struct {
TenantName string `yaml:"tenantName"`
TokenName string `yaml:"tokenName"`
Socials []struct {
NotificationType string `yaml:"notificationType"`
Link string `yaml:"link"`
Expand All @@ -361,15 +322,11 @@ type (
Roles []string `yaml:"roles"`
} `yaml:"disabledAchievementsNotifications" `
NotificationDelaysByTopic map[push.SubscriptionTopic]notificationDelayConfig `yaml:"notificationDelaysByTopic" mapstructure:"notificationDelaysByTopic"` //nolint:lll // .
TelegramBots map[telegramBotID]struct {
BotToken telegramBotToken `yaml:"botToken"`
} `yaml:"telegramBots" mapstructure:"telegramBots"`
DeeplinkScheme string `yaml:"deeplinkScheme"`
WebAppLink string `yaml:"webAppLink"`
messagebroker.Config `mapstructure:",squash"` //nolint:tagliatelle // Nope.
notificationDelayConfig `mapstructure:",squash"`
PingCooldown stdlibtime.Duration `yaml:"pingCooldown"`
WeeklyStats struct {
DeeplinkScheme string `yaml:"deeplinkScheme"`
messagebroker.Config `mapstructure:",squash"` //nolint:tagliatelle // Nope.
notificationDelayConfig `mapstructure:",squash"`
PingCooldown stdlibtime.Duration `yaml:"pingCooldown"`
WeeklyStats struct {
Weekday stdlibtime.Weekday `yaml:"weekday"`
Hour int `yaml:"hour"`
Minutes int `yaml:"minutes"`
Expand Down
14 changes: 6 additions & 8 deletions notifications/notification_invite_friend.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,34 +27,32 @@ func (r *repository) addScheduledInviteFriendNotifications(ctx context.Context,
dayDuration = 24 * stdlibtime.Hour
firstNotificationDuration = 1 * stdlibtime.Hour
}
availableChannels := []NotificationChannel{PushNotificationChannel, TelegramNotificationChannel}
scheduled := make([]*scheduledNotification, 0, 2*len(availableChannels)) //nolint:gomnd,mnd // .
for _, channel := range availableChannels {
scheduled = append(scheduled, &scheduledNotification{
scheduled := []*scheduledNotification{
{
ScheduledAt: now,
ScheduledFor: time.New(us.CreatedAt.Add(firstNotificationDuration)),
Language: us.Language,
UserID: us.ID,
NotificationType: string(InviteFriendNotificationType),
Uniqueness: fmt.Sprintf("%v_%v_1h", us.ID, InviteFriendNotificationType),
NotificationChannel: string(channel),
NotificationChannel: string(PushNotificationChannel),
NotificationChannelValue: us.ID,
Data: &users.JSON{
"TenantName": r.cfg.TenantName,
},
}, &scheduledNotification{
}, {
ScheduledAt: now,
ScheduledFor: time.New(us.CreatedAt.Add(7 * dayDuration)), //nolint:gomnd,mnd // .
Language: us.Language,
UserID: us.ID,
NotificationType: string(InviteFriendNotificationType),
Uniqueness: fmt.Sprintf("%v_%v_7d", us.ID, InviteFriendNotificationType),
NotificationChannel: string(channel),
NotificationChannel: string(PushNotificationChannel),
NotificationChannelValue: us.ID,
Data: &users.JSON{
"TenantName": r.cfg.TenantName,
},
})
},
}

return errors.Wrapf(r.insertScheduledNotifications(ctx, scheduled), "can't execute insertScheduledNotifications:%#v", scheduled)
Expand Down
Loading

0 comments on commit 8dc7c53

Please sign in to comment.