Skip to content

Commit 2492a1c

Browse files
authored
Merge pull request #31 from bdach/discussion-watch-status
Set 'notify on discussion replies' state according to user request
2 parents 316a408 + d6464a9 commit 2492a1c

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

osu.Server.BeatmapSubmission/BeatmapSubmissionController.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ public async Task<IActionResult> PutBeatmapSetAsync([FromBody] PutBeatmapSetRequ
165165
beatmapIds.AddRange(request.BeatmapsToKeep);
166166

167167
await db.SetBeatmapSetOnlineStatusAsync(beatmapSetId.Value, (BeatmapOnlineStatus)request.Target, transaction);
168+
await db.SetBeatmapsetDiscussionNotificationState(beatmapSetId.Value, userId, request.NotifyOnDiscussionReplies, transaction);
168169
await db.UpdateBeatmapCountForSet(beatmapSetId.Value, totalBeatmapCount, transaction);
169170

170171
await transaction.CommitAsync();

osu.Server.BeatmapSubmission/DatabaseOperationExtensions.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,41 @@ public static Task SoftDeleteBeatmapAsync(this MySqlConnection db, uint beatmapI
225225
transaction);
226226
}
227227

228+
public static async Task SetBeatmapsetDiscussionNotificationState(this MySqlConnection db, uint beatmapSetId, uint userId, bool shouldNotify, MySqlTransaction? transaction = null)
229+
{
230+
if (shouldNotify)
231+
{
232+
await db.ExecuteAsync(
233+
"""
234+
INSERT IGNORE INTO `beatmapset_watches` (`beatmapset_id`, `user_id`, `created_at`, `updated_at`)
235+
VALUES (@beatmapset_id, @user_id, NOW(), NOW());
236+
237+
INSERT IGNORE INTO `follows` (`user_id`, `notifiable_type`, `notifiable_id`, `subtype`, `created_at`, `updated_at`)
238+
VALUES (@user_id, 'beatmapset', @beatmapset_id, 'comment', NOW(), NOW());
239+
""",
240+
new
241+
{
242+
beatmapset_id = beatmapSetId,
243+
user_id = userId,
244+
},
245+
transaction);
246+
}
247+
else
248+
{
249+
await db.ExecuteAsync(
250+
"""
251+
DELETE FROM `beatmapset_watches` WHERE `beatmapset_id` = @beatmapset_id AND `user_id` = @user_id;
252+
DELETE FROM `follows` WHERE `user_id` = @user_id AND `notifiable_id` = @beatmapset_id AND `notifiable_type` = 'beatmapset' AND `subtype` = 'comment';
253+
""",
254+
new
255+
{
256+
beatmapset_id = beatmapSetId,
257+
user_id = userId,
258+
},
259+
transaction);
260+
}
261+
}
262+
228263
public static Task UpdateBeatmapAsync(this MySqlConnection db, osu_beatmap beatmap, MySqlTransaction? transaction = null)
229264
{
230265
return db.ExecuteAsync(

osu.Server.BeatmapSubmission/Models/API/Requests/PutBeatmapSetRequest.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ public class PutBeatmapSetRequest
3535

3636
[JsonPropertyName("target")]
3737
public BeatmapSubmissionTarget Target { get; set; } = BeatmapSubmissionTarget.WIP;
38+
39+
[JsonPropertyName("notify_on_discussion_replies")]
40+
public bool NotifyOnDiscussionReplies { get; set; }
3841
}
3942

4043
/// <summary>

0 commit comments

Comments
 (0)