-
Notifications
You must be signed in to change notification settings - Fork 249
/
Copy pathdelete_community_member_messages.go
54 lines (44 loc) · 2.12 KB
/
delete_community_member_messages.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package requests
import (
"errors"
"github.com/status-im/status-go/eth-node/types"
"github.com/status-im/status-go/protocol/protobuf"
)
var ErrDeleteCommunityMemberMessagesInvalidCommunityID = errors.New("delete-community-member-messages: invalid community id")
var ErrDeleteCommunityMemberMessagesInvalidMemberID = errors.New("delete-community-member-messages: invalid member id")
var ErrDeleteCommunityMemberMessagesInvalidData = errors.New("delete-community-member-messages: invalid data")
var ErrDeleteCommunityMemberMessagesInvalidDeleteAll = errors.New("delete-community-member-messages: invalid delete all setup")
var ErrDeleteCommunityMemberMessagesInvalidDeleteMessagesByID = errors.New("delete-community-member-messages: invalid delete messages by ID setups")
var ErrDeleteCommunityMemberMessagesInvalidMsgID = errors.New("delete-community-member-messages: invalid messages Id")
var ErrDeleteCommunityMemberMessagesInvalidMsgChatID = errors.New("delete-community-member-messages: invalid messages chatId")
type DeleteCommunityMemberMessages struct {
CommunityID types.HexBytes `json:"communityId"`
MemberPubKey string `json:"memberPubKey"`
Messages []*protobuf.DeleteCommunityMemberMessage `json:"messages"`
DeleteAll bool `json:"deleteAll"`
}
func (d *DeleteCommunityMemberMessages) Validate() error {
if len(d.CommunityID) == 0 {
return ErrDeleteCommunityMemberMessagesInvalidCommunityID
}
if len(d.MemberPubKey) == 0 {
return ErrDeleteCommunityMemberMessagesInvalidMemberID
}
if d.Messages != nil && len(d.Messages) > 0 && d.DeleteAll {
return ErrDeleteCommunityMemberMessagesInvalidDeleteAll
}
if (d.Messages == nil || (d.Messages != nil && len(d.Messages) == 0)) && !d.DeleteAll {
return ErrDeleteCommunityMemberMessagesInvalidDeleteMessagesByID
}
if d.Messages != nil {
for _, message := range d.Messages {
if len(message.Id) == 0 {
return ErrDeleteCommunityMemberMessagesInvalidMsgID
}
if len(message.ChatId) == 0 {
return ErrDeleteCommunityMemberMessagesInvalidMsgChatID
}
}
}
return nil
}