Skip to content

Commit

Permalink
Add recipient.Key#CopyNonNil() method
Browse files Browse the repository at this point in the history
  • Loading branch information
yhabteab committed May 10, 2023
1 parent ee282a2 commit cab6d2a
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions internal/recipient/recipient.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,24 @@ func (r Key) MarshalText() (text []byte, err error) {
}
}

// CopyNonNil copies non-nil fields from the provided recipient.Key to the current one and
// returns the modified recipient key.
func (r Key) CopyNonNil(recipientKey Key) Key {
if !r.ContactID.Valid && recipientKey.ContactID.Valid {
r.ContactID = recipientKey.ContactID
}

if !r.GroupID.Valid && recipientKey.GroupID.Valid {
r.GroupID = recipientKey.GroupID
}

if !r.ScheduleID.Valid && recipientKey.ScheduleID.Valid {
r.ScheduleID = recipientKey.ScheduleID
}

return r
}

func ToKey(r Recipient) Key {
switch v := r.(type) {
case *Contact:
Expand Down

0 comments on commit cab6d2a

Please sign in to comment.