Skip to content

Commit bd94e4b

Browse files
committed
Add recipient.Key#CopyNonNil() method
1 parent e89bbdc commit bd94e4b

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

internal/recipient/recipient.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,24 @@ func (r Key) MarshalText() (text []byte, err error) {
3333
}
3434
}
3535

36+
// CopyNonNil copies non-nil fields from the provided recipient.Key to the current one and
37+
// returns the modified recipient key.
38+
func (r Key) CopyNonNil(recipientKey Key) Key {
39+
if !r.ContactID.Valid && recipientKey.ContactID.Valid {
40+
r.ContactID = recipientKey.ContactID
41+
}
42+
43+
if !r.GroupID.Valid && recipientKey.GroupID.Valid {
44+
r.GroupID = recipientKey.GroupID
45+
}
46+
47+
if !r.ScheduleID.Valid && recipientKey.ScheduleID.Valid {
48+
r.ScheduleID = recipientKey.ScheduleID
49+
}
50+
51+
return r
52+
}
53+
3654
func ToKey(r Recipient) Key {
3755
switch v := r.(type) {
3856
case *Contact:

0 commit comments

Comments
 (0)