Skip to content

Commit

Permalink
fix: small touchups
Browse files Browse the repository at this point in the history
  • Loading branch information
mattrltrent committed Aug 13, 2023
1 parent 660717a commit 202efd6
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 20 deletions.
8 changes: 4 additions & 4 deletions config/builders/fcm_msg_notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ func VoteOnPostNoti(vote int, totalVotes int) *messaging.Notification {
func YourSchoolsDailyHottestNoti(occurences int) *messaging.Notification {
if occurences == 1 {
return &messaging.Notification{
Title: "Your School is Trending! 🔥",
Body: "Check out todays hottest confession!",
Title: "Your school hit the Daily Hottest!",
Body: fmt.Sprintf("Check it out in app!"),
}
}

return &messaging.Notification{
Title: fmt.Sprintf("Your School is Trending %d times! 🔥", occurences),
Body: "Check out todays hottest confessions!",
Title: "Your school hit the Daily Hottest!",
Body: fmt.Sprintf("%d times", occurences),
}
}

Expand Down
4 changes: 2 additions & 2 deletions config/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ const (
QueryForSchoolsBySearchPageSize = 10 // how many schools are returned in a page size in the search schools page
QueryForSchoolsBySearchFloorSimilarityMatchValue = 0.05 // how much of a match is required for a school to be returned in the search schools page (value is the min percent of match, IE: 0.05 = 5% match at least, or 1 in 20 of the characters match)
DefaultRange = 50000 // default distance to include schools in, in meters
HottestPostNotificationsLowerBound = "10:00" // the lower bound of the hottest post notifications cron job
HottestPostNotificationsUpperBound = "14:00" // the upper bound of the hottest post notifications cron job
HottestPostNotificationsLowerBound = "10:00" // the lower bound of the hottest post notifications cron job - 24h time
HottestPostNotificationsUpperBound = "18:00" // the upper bound of the hottest post notifications cron job - 24h time
)

// ----- DEPLOYMENT CONSTANTS
Expand Down
4 changes: 2 additions & 2 deletions features/admin/hide.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func (h *handler) handleHideContent(c *gin.Context) {
ToTokens([]string{tokenWithReportID.Token}).
WithMsg(builders.HideReportNoti()).
WithData(builders.HideReportData(tokenWithReportID.ReportID)).
Send(*h.db)
Send()
}
}

Expand All @@ -190,7 +190,7 @@ func (h *handler) handleHideContent(c *gin.Context) {
ToTokens([]string{tokenWithOffenderID.Token}).
WithMsg(builders.HideOffendingUserNoti()).
WithData(builders.HideOffendingUserData(tokenWithOffenderID.HideLogID)).
Send(*h.db)
Send()
}
}
}
4 changes: 2 additions & 2 deletions features/admin/set_user_standing.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,14 @@ func (h *handler) handleSetUserStanding(c *gin.Context) {
ToTokens(tokens).
WithMsg(builders.AccountStandingLimitedNoti(isLimited)).
WithData(builders.AccountStandingLimitedData(isLimited)).
Send(*h.db)
Send()
} else if req.Standing == "banned" || req.Standing == "unbanned" {
isBanned := req.Standing == "banned"
go fcm.New(h.fb.MsgClient).
ToTokens(tokens).
WithMsg(builders.AccountStandingBannedNoti(isBanned)).
WithData(builders.AccountStandingBannedData(isBanned)).
Send(*h.db)
Send()
}
}

Expand Down
4 changes: 2 additions & 2 deletions features/comments/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ func (h *handler) handleCreate(c *gin.Context) {
ToTokens(postTokens).
WithMsg(builders.CommentAddedToPostNoti(req.Content)).
WithData(builders.CommentAddedToPostData(comment.ID.Val, unmaskedPostId)).
Send(*h.db)
Send()
}

// respond "success" BEFORE sending FCM
Expand All @@ -289,7 +289,7 @@ func (h *handler) handleCreate(c *gin.Context) {
ToTokens(threadTokens).
WithMsg(builders.ThreadedCommentReplyNoti(req.Content)).
WithData(builders.ThreadedCommentReplyData(unmaskedCommentId, comment.ID.Val, unmaskedPostId)).
Send(*h.db)
Send()
}
}

Expand Down
2 changes: 1 addition & 1 deletion features/notifications/set_topic_prefs.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (h *handler) handleSetTopicPrefs(c *gin.Context) {
go fcm.New(h.fb.MsgClient).
ToTokens(tokens).
WithData(builders.NotificationSettingsSyncData()).
Send(*h.db)
Send()
} else if err != nil {
// "handle" the error if fetching tokens fails
logger.StdInfo(fmt.Sprintf("failed to send sync request for set topic prefs: %v", err))
Expand Down
4 changes: 2 additions & 2 deletions features/votes/vote.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func (h *handler) doVote(c *gin.Context, vote db.Vote, contentType string, uid s
ToTokens(tokens).
WithMsg(builders.VoteOnCommentNoti(vote.Vote, votes.Upvote-votes.Downvote)).
WithData(builders.VoteOnCommentData(vote.CommentID.Val)).
Send(*h.db)
Send()
}
} else if vote.PostID != nil {
err = h.db.
Expand All @@ -207,7 +207,7 @@ func (h *handler) doVote(c *gin.Context, vote db.Vote, contentType string, uid s
ToTokens(tokens).
WithMsg(builders.VoteOnPostNoti(vote.Vote, votes.Upvote-votes.Downvote)).
WithData(builders.VoteOnCommentData(vote.PostID.Val)).
Send(*h.db)
Send()
}
}

Expand Down
4 changes: 2 additions & 2 deletions lib/cronJobs/cronNotifications/hottest_post_notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (

// Cron job that runs every two hours to send notifications to users about the hottest posts.
func StartDailyHottestPostsCronJob() {

// DoHottestPostNotifications(time.Now().UTC())
upperBound, err := time.Parse("15:04", config.HottestPostNotificationsUpperBound)
if err != nil {
panic(err)
Expand Down Expand Up @@ -153,7 +153,7 @@ func DoHottestPostNotifications(dateTime time.Time) error {
ToTokens(tokens).
WithMsg(builders.YourSchoolsDailyHottestNoti(hottestOccurences)).
WithData(builders.YourSchoolsDailyHottestData()).
Send(*tx)
Send()

}
}
Expand Down
6 changes: 3 additions & 3 deletions lib/firebase_cloud_messaging/fcm.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package fcm

import (
"confesi/db"
"confesi/lib/logger"
"context"
"errors"
"fmt"
"time"

"firebase.google.com/go/messaging"
"gorm.io/gorm"
)

var (
Expand Down Expand Up @@ -54,7 +54,7 @@ func (s *Sender) WithMsg(notification *messaging.Notification) *Sender {
return s
}

func (s *Sender) Send(db gorm.DB) (error, uint) {
func (s *Sender) Send() (error, uint) {
messages := make([]*messaging.Message, 0)

if len(s.Tokens) > 0 && s.Topic == "" {
Expand Down Expand Up @@ -148,7 +148,7 @@ func (s *Sender) Send(db gorm.DB) (error, uint) {
}

if len(deadTokens) > 0 {
result := db.Table("fcm_tokens").Where("token IN ?", deadTokens).Delete(nil)
result := db.New().Table("fcm_tokens").Where("token IN ?", deadTokens).Delete(&db.FcmToken{})
if result.Error != nil {
// Handle the error if the deletion fails
return result.Error, sends
Expand Down

0 comments on commit 202efd6

Please sign in to comment.