Skip to content

Commit

Permalink
Do not store empty dictionary when updating PollDTO.custom and PollOp…
Browse files Browse the repository at this point in the history
…tionDTO.custom because it leads to errors in decoding later (#3551)
  • Loading branch information
laevandus authored Jan 4, 2025
1 parent e03357e commit 9017687
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
7 changes: 6 additions & 1 deletion Sources/StreamChat/Database/DTOs/PollDTO.swift
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,19 @@ extension NSManagedObjectContext {
pollDto.name = payload.name
pollDto.updatedAt = payload.updatedAt.bridgeDate
pollDto.voteCount = payload.voteCount
pollDto.custom = try JSONEncoder.default.encode(payload.custom)
pollDto.voteCountsByOption = payload.voteCountsByOption
pollDto.isClosed = payload.isClosed ?? false
if let maxVotesAllowed = payload.maxVotesAllowed {
pollDto.maxVotesAllowed = NSNumber(value: maxVotesAllowed)
}
pollDto.votingVisibility = payload.votingVisibility

if let custom = payload.custom, !custom.isEmpty {
pollDto.custom = try JSONEncoder.default.encode(custom)
} else {
pollDto.custom = nil
}

if let userPayload = payload.createdBy {
pollDto.createdBy = try saveUser(payload: userPayload, query: nil, cache: cache)
} else {
Expand Down
6 changes: 5 additions & 1 deletion Sources/StreamChat/Database/DTOs/PollOptionDTO.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ extension NSManagedObjectContext {
cache: cache
)
dto.text = payload.text
dto.custom = try JSONEncoder.default.encode(payload.custom)
if let custom = payload.custom, !custom.isEmpty {
dto.custom = try JSONEncoder.default.encode(custom)
} else {
dto.custom = nil
}
return dto
}

Expand Down

0 comments on commit 9017687

Please sign in to comment.