From 202efd6c3c8954352183a30231d342039cdde455 Mon Sep 17 00:00:00 2001 From: Matthew Date: Sat, 12 Aug 2023 19:05:35 -0700 Subject: [PATCH] fix: small touchups --- config/builders/fcm_msg_notifications.go | 8 ++++---- config/constants.go | 4 ++-- features/admin/hide.go | 4 ++-- features/admin/set_user_standing.go | 4 ++-- features/comments/create.go | 4 ++-- features/notifications/set_topic_prefs.go | 2 +- features/votes/vote.go | 4 ++-- .../cronNotifications/hottest_post_notifications.go | 4 ++-- lib/firebase_cloud_messaging/fcm.go | 6 +++--- 9 files changed, 20 insertions(+), 20 deletions(-) diff --git a/config/builders/fcm_msg_notifications.go b/config/builders/fcm_msg_notifications.go index c722d367..596a1a73 100644 --- a/config/builders/fcm_msg_notifications.go +++ b/config/builders/fcm_msg_notifications.go @@ -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), } } diff --git a/config/constants.go b/config/constants.go index 7103f721..e384b91e 100644 --- a/config/constants.go +++ b/config/constants.go @@ -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 diff --git a/features/admin/hide.go b/features/admin/hide.go index c24bea1c..077b8705 100644 --- a/features/admin/hide.go +++ b/features/admin/hide.go @@ -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() } } @@ -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() } } } diff --git a/features/admin/set_user_standing.go b/features/admin/set_user_standing.go index 1cff8b89..af43a4c9 100644 --- a/features/admin/set_user_standing.go +++ b/features/admin/set_user_standing.go @@ -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() } } diff --git a/features/comments/create.go b/features/comments/create.go index 557e669c..63e31d05 100644 --- a/features/comments/create.go +++ b/features/comments/create.go @@ -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 @@ -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() } } diff --git a/features/notifications/set_topic_prefs.go b/features/notifications/set_topic_prefs.go index 4afb7125..d769584b 100644 --- a/features/notifications/set_topic_prefs.go +++ b/features/notifications/set_topic_prefs.go @@ -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)) diff --git a/features/votes/vote.go b/features/votes/vote.go index 5cbff278..c4f583ae 100644 --- a/features/votes/vote.go +++ b/features/votes/vote.go @@ -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. @@ -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() } } diff --git a/lib/cronJobs/cronNotifications/hottest_post_notifications.go b/lib/cronJobs/cronNotifications/hottest_post_notifications.go index 1ede5464..5d5a4529 100644 --- a/lib/cronJobs/cronNotifications/hottest_post_notifications.go +++ b/lib/cronJobs/cronNotifications/hottest_post_notifications.go @@ -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) @@ -153,7 +153,7 @@ func DoHottestPostNotifications(dateTime time.Time) error { ToTokens(tokens). WithMsg(builders.YourSchoolsDailyHottestNoti(hottestOccurences)). WithData(builders.YourSchoolsDailyHottestData()). - Send(*tx) + Send() } } diff --git a/lib/firebase_cloud_messaging/fcm.go b/lib/firebase_cloud_messaging/fcm.go index 5ea39722..f13932f9 100644 --- a/lib/firebase_cloud_messaging/fcm.go +++ b/lib/firebase_cloud_messaging/fcm.go @@ -1,6 +1,7 @@ package fcm import ( + "confesi/db" "confesi/lib/logger" "context" "errors" @@ -8,7 +9,6 @@ import ( "time" "firebase.google.com/go/messaging" - "gorm.io/gorm" ) var ( @@ -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 == "" { @@ -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