2023-07-18 15:06:12 +00:00
|
|
|
package communities
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/golang/protobuf/proto"
|
|
|
|
|
|
|
|
"github.com/status-im/status-go/protocol/protobuf"
|
|
|
|
)
|
|
|
|
|
|
|
|
type CommunityEventsMessage struct {
|
|
|
|
CommunityID []byte `json:"communityId"`
|
|
|
|
EventsBaseCommunityDescription []byte `json:"eventsBaseCommunityDescription"`
|
|
|
|
Events []CommunityEvent `json:"events,omitempty"`
|
|
|
|
}
|
|
|
|
|
2023-08-18 11:39:59 +00:00
|
|
|
func (m *CommunityEventsMessage) ToProtobuf() *protobuf.CommunityEventsMessage {
|
2023-08-08 18:33:29 +00:00
|
|
|
result := protobuf.CommunityEventsMessage{
|
2023-07-18 15:06:12 +00:00
|
|
|
CommunityId: m.CommunityID,
|
|
|
|
EventsBaseCommunityDescription: m.EventsBaseCommunityDescription,
|
2023-08-08 18:33:29 +00:00
|
|
|
SignedEvents: []*protobuf.SignedCommunityEvent{},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, event := range m.Events {
|
|
|
|
signedEvent := &protobuf.SignedCommunityEvent{
|
|
|
|
Signature: event.Signature,
|
|
|
|
Payload: event.Payload,
|
|
|
|
}
|
|
|
|
result.SignedEvents = append(result.SignedEvents, signedEvent)
|
2023-07-18 15:06:12 +00:00
|
|
|
}
|
2023-08-08 18:33:29 +00:00
|
|
|
|
2023-08-18 11:39:59 +00:00
|
|
|
return &result
|
2023-07-18 15:06:12 +00:00
|
|
|
}
|
|
|
|
|
2023-08-08 18:33:29 +00:00
|
|
|
func CommunityEventsMessageFromProtobuf(msg *protobuf.CommunityEventsMessage) (*CommunityEventsMessage, error) {
|
|
|
|
result := &CommunityEventsMessage{
|
|
|
|
CommunityID: msg.CommunityId,
|
|
|
|
EventsBaseCommunityDescription: msg.EventsBaseCommunityDescription,
|
|
|
|
Events: []CommunityEvent{},
|
2023-07-18 15:06:12 +00:00
|
|
|
}
|
|
|
|
|
2023-08-08 18:33:29 +00:00
|
|
|
for _, signedEvent := range msg.SignedEvents {
|
|
|
|
event, err := communityEventFromProtobuf(signedEvent)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
result.Events = append(result.Events, *event)
|
|
|
|
}
|
|
|
|
|
|
|
|
return result, nil
|
2023-07-18 15:06:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (m *CommunityEventsMessage) Marshal() ([]byte, error) {
|
|
|
|
pb := m.ToProtobuf()
|
2023-08-18 11:39:59 +00:00
|
|
|
return proto.Marshal(pb)
|
2023-07-18 15:06:12 +00:00
|
|
|
}
|