Skip to content

Commit 939ce20

Browse files
committed
Add button to disable notifications
1 parent 38decac commit 939ce20

5 files changed

Lines changed: 44 additions & 17 deletions

File tree

api/pkg/emails/hermes_notification_email_factory.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@ func (factory *hermesNotificationEmailFactory) DiscordSendFailed(user *entities.
4747
Button: hermes.Button{
4848
Color: "#329ef4",
4949
TextColor: "#FFFFFF",
50-
Text: "Settings",
51-
Link: "https://httpsms.com/settings",
50+
Text: "DISCORD SETTINGS",
51+
Link: "https://httpsms.com/settings/#discord-settings",
5252
},
5353
},
5454
},
5555
Signature: "Cheers",
5656
Outros: []string{
57-
fmt.Sprintf("Don't hesitate to contact us by replying to this email."),
57+
fmt.Sprintf("Don't hesitate to contact us by replying to this email. You can disable this email notification on https://httpsms.com/settings/#email-notifications"),
5858
},
5959
},
6060
}
@@ -98,14 +98,14 @@ func (factory *hermesNotificationEmailFactory) WebhookSendFailed(user *entities.
9898
Button: hermes.Button{
9999
Color: "#329ef4",
100100
TextColor: "#FFFFFF",
101-
Text: "Settings",
102-
Link: "https://httpsms.com/settings",
101+
Text: "WEBHOOK SETTINGS",
102+
Link: "https://httpsms.com/settings/#webhook-settings",
103103
},
104104
},
105105
},
106106
Signature: "Cheers",
107107
Outros: []string{
108-
fmt.Sprintf("Don't hesitate to contact us by replying to this email."),
108+
fmt.Sprintf("Don't hesitate to contact us by replying to this email. You can disable this email notification on https://httpsms.com/settings/#email-notifications"),
109109
},
110110
},
111111
}
@@ -147,14 +147,14 @@ func (factory *hermesNotificationEmailFactory) MessageExpired(user *entities.Use
147147
Button: hermes.Button{
148148
Color: "#329ef4",
149149
TextColor: "#FFFFFF",
150-
Text: "View Messages",
150+
Text: "VIEW MESSAGES",
151151
Link: "https://httpsms.com/threads",
152152
},
153153
},
154154
},
155155
Signature: "Cheers",
156156
Outros: []string{
157-
fmt.Sprintf("Don't hesitate to contact us by replying to this email."),
157+
fmt.Sprintf("Don't hesitate to contact us by replying to this email. You can disable this email notification on https://httpsms.com/settings/#email-notifications"),
158158
},
159159
},
160160
}
@@ -197,14 +197,14 @@ func (factory *hermesNotificationEmailFactory) MessageFailed(user *entities.User
197197
Button: hermes.Button{
198198
Color: "#329ef4",
199199
TextColor: "#FFFFFF",
200-
Text: "View Messages",
200+
Text: "VIEW MESSAGES",
201201
Link: "https://httpsms.com/threads",
202202
},
203203
},
204204
},
205205
Signature: "Cheers",
206206
Outros: []string{
207-
fmt.Sprintf("Don't hesitate to contact us by replying to this email."),
207+
fmt.Sprintf("Don't hesitate to contact us by replying to this email. You can disable this email notification on https://httpsms.com/settings/#email-notifications"),
208208
},
209209
},
210210
}

api/pkg/emails/hermes_user_email_factory.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func (factory *hermesUserEmailFactory) UsageLimitExceeded(user *entities.User) (
2828
Button: hermes.Button{
2929
Color: "#329ef4",
3030
TextColor: "#FFFFFF",
31-
Text: "Upgrade your httpSMS plan",
31+
Text: "UPGRADE YOUR PLAN",
3232
Link: "https://httpsms.com/billing",
3333
},
3434
},
@@ -74,7 +74,7 @@ func (factory *hermesUserEmailFactory) UsageLimitAlert(user *entities.User, usag
7474
Button: hermes.Button{
7575
Color: "#329ef4",
7676
TextColor: "#FFFFFF",
77-
Text: "UPGRADE PLAN",
77+
Text: "UPGRADE YOUR PLAN",
7878
Link: "https://httpsms.com/billing",
7979
},
8080
},
@@ -140,7 +140,7 @@ func (factory *hermesUserEmailFactory) PhoneDead(user *entities.User, lastHeartb
140140
Title: "Hey,",
141141
Signature: "Cheers",
142142
Outros: []string{
143-
fmt.Sprintf("Don't hesitate to contact us by replying to this email."),
143+
fmt.Sprintf("Don't hesitate to contact us by replying to this email. You can disable this email notification on https://httpsms.com/settings/#email-notifications"),
144144
},
145145
},
146146
}

api/pkg/services/email_notification_service.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ func (service *EmailNotificationService) NotifyMessageExpired(ctx context.Contex
7070
return service.tracer.WrapErrorSpan(span, stacktrace.PropagateWithCode(err, stacktrace.GetCode(err), msg))
7171
}
7272

73+
if !user.NotificationMessageStatusEnabled {
74+
ctxLogger.Info(fmt.Sprintf("[%s] email notifications disabled for user [%s] with owner [%s]", events.EventTypeMessageSendExpired, payload.UserID, payload.Owner))
75+
return nil
76+
}
77+
7378
email, err := service.factory.MessageExpired(user, payload.MessageID, payload.Owner, payload.Contact, payload.Content)
7479
if err != nil {
7580
msg := fmt.Sprintf("cannot create email for user with ID [%s] and for expired message with ID [%s]", payload.UserID, payload.MessageID)
@@ -103,6 +108,11 @@ func (service *EmailNotificationService) NotifyMessageFailed(ctx context.Context
103108
return service.tracer.WrapErrorSpan(span, stacktrace.PropagateWithCode(err, stacktrace.GetCode(err), msg))
104109
}
105110

111+
if !user.NotificationMessageStatusEnabled {
112+
ctxLogger.Info(fmt.Sprintf("[%s] email notifications disabled for user [%s] with owner [%s]", events.EventTypeMessageSendFailed, payload.UserID, payload.Owner))
113+
return nil
114+
}
115+
106116
email, err := service.factory.MessageFailed(user, payload.ID, payload.Owner, payload.Contact, payload.Content, payload.ErrorMessage)
107117
if err != nil {
108118
msg := fmt.Sprintf("cannot create email for user with ID [%s] for [%s] message with ID [%s]", payload.UserID, payload.ID)
@@ -136,6 +146,11 @@ func (service *EmailNotificationService) NotifyWebhookSendFailed(ctx context.Con
136146
return service.tracer.WrapErrorSpan(span, stacktrace.PropagateWithCode(err, stacktrace.GetCode(err), msg))
137147
}
138148

149+
if !user.NotificationWebhookEnabled {
150+
ctxLogger.Info(fmt.Sprintf("[%s] email notifications disabled for user [%s] with owner [%s]", events.EventTypeWebhookSendFailed, payload.UserID, payload.Owner))
151+
return nil
152+
}
153+
139154
email, err := service.factory.WebhookSendFailed(user, payload)
140155
if err != nil {
141156
msg := fmt.Sprintf("cannot create [%s] email for user with ID [%s] for [%s] event with ID [%s]", events.EventTypeWebhookSendFailed, payload.UserID, payload.EventType, payload.EventID)
@@ -169,6 +184,11 @@ func (service *EmailNotificationService) NotifyDiscordSendFailed(ctx context.Con
169184
return service.tracer.WrapErrorSpan(span, stacktrace.PropagateWithCode(err, stacktrace.GetCode(err), msg))
170185
}
171186

187+
if !user.NotificationWebhookEnabled {
188+
ctxLogger.Info(fmt.Sprintf("[%s] email notifications disabled for user [%s] with owner [%s]", events.EventTypeDiscordSendFailed, payload.UserID, payload.Owner))
189+
return nil
190+
}
191+
172192
email, err := service.factory.DiscordSendFailed(user, payload)
173193
if err != nil {
174194
msg := fmt.Sprintf("cannot create email for user with ID [%s] for [%s] event and message with ID [%s]", payload.UserID, payload.EventType, payload.MessageID)

api/pkg/services/user_service.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,11 @@ func (service *UserService) SendPhoneDeadEmail(ctx context.Context, params *User
156156
return service.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg))
157157
}
158158

159+
if !user.NotificationHeartbeatEnabled {
160+
ctxLogger.Info(fmt.Sprintf("[%s] email notifications disabled for user [%s] with owner [%s]", events.EventTypePhoneHeartbeatDead, params.UserID, params.Owner))
161+
return nil
162+
}
163+
159164
email, err := service.emailFactory.PhoneDead(user, params.LastHeartbeatTimestamp, params.Owner)
160165
if err != nil {
161166
msg := fmt.Sprintf("cannot create phone dead email for user [%s]", params.UserID)

web/pages/settings/index.vue

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
>Documentation</v-btn
9292
>
9393
</div>
94-
<h5 id="webhooks" class="text-h4 mb-3 mt-12">Webhooks</h5>
94+
<h5 id="webhook-settings" class="text-h4 mb-3 mt-12">Webhooks</h5>
9595
<p class="text--secondary">
9696
Webhooks allow us to send events to your server for example when
9797
the android phone receives an SMS message we can forward the
@@ -164,10 +164,12 @@
164164
>Documentation</v-btn
165165
>
166166
</div>
167-
<h5 class="text-h4 mb-3 mt-12">Discord Integration</h5>
167+
<h5 id="discord-settings" class="text-h4 mb-3 mt-12">
168+
Discord Integration
169+
</h5>
168170
<p class="text--secondary">
169171
Send and receive SMS messages without leaving your discord server
170-
with the httpsms discord app using the
172+
with the httpSMS discord app using the
171173
<code>/httpsms</code> command.
172174
</p>
173175
<div v-if="loadingDiscordIntegrations">
@@ -854,7 +856,7 @@ export default Vue.extend({
854856
},
855857
856858
async updatePhone() {
857-
thisPhone = true
859+
this.updatingPhone = true
858860
await this.$store.dispatch('clearAxiosError')
859861
this.$store.dispatch('updatePhone', this.activePhone).finally(() => {
860862
if (!this.$store.getters.getAxiosError) {

0 commit comments

Comments
 (0)