mirror of
https://github.com/Walter-Sparrow/lunar-tear.git
synced 2026-07-02 05:43:41 +03:00
Fix repeated weapon story unlock notifications by sending only changed stories in diffs
This commit is contained in:
@@ -258,6 +258,27 @@ func sortedWeaponStoryRecords(user store.UserState) []map[string]any {
|
||||
return records
|
||||
}
|
||||
|
||||
func WeaponStoryRecordsForIds(user store.UserState, weaponIds []int32) string {
|
||||
if len(weaponIds) == 0 {
|
||||
return "[]"
|
||||
}
|
||||
records := make([]map[string]any, 0, len(weaponIds))
|
||||
for _, weaponId := range weaponIds {
|
||||
row, ok := user.WeaponStories[weaponId]
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
records = append(records, map[string]any{
|
||||
"userId": user.UserId,
|
||||
"weaponId": row.WeaponId,
|
||||
"releasedMaxStoryIndex": row.ReleasedMaxStoryIndex,
|
||||
"latestVersion": row.LatestVersion,
|
||||
})
|
||||
}
|
||||
s, _ := encodeJSONMaps(records...)
|
||||
return s
|
||||
}
|
||||
|
||||
func sortedWeaponNoteRecords(user store.UserState) []map[string]any {
|
||||
weaponIds := make([]int32, 0, len(user.WeaponNotes))
|
||||
for id := range user.WeaponNotes {
|
||||
|
||||
@@ -170,3 +170,13 @@ func BuildDiffFromTablesOrdered(tables map[string]string, order []string) map[st
|
||||
}
|
||||
return diff
|
||||
}
|
||||
|
||||
func AddWeaponStoryDiff(diff map[string]*pb.DiffData, user store.UserState, weaponIds []int32) {
|
||||
if len(weaponIds) == 0 {
|
||||
return
|
||||
}
|
||||
diff["IUserWeaponStory"] = &pb.DiffData{
|
||||
UpdateRecordsJson: WeaponStoryRecordsForIds(user, weaponIds),
|
||||
DeleteKeysJson: "[]",
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user