mirror of
https://github.com/status-im/status-go.git
synced 2025-01-10 06:36:32 +00:00
9d5bcc3c60
This commit introduces a new `clock` field in the `communities_settings` table so that it can be leveraged for syncing community settings across devices. It alsoe exends existing `syncCommunity` APIs to generate `SyncCommunitySettings` as well, avoiding sending additional sync messages for community settings. When editing communities however, we still sync community settings explicitly are we aren't syncing the community itself in that case.
48 lines
1.1 KiB
Go
48 lines
1.1 KiB
Go
package communities
|
|
|
|
import (
|
|
"github.com/status-im/status-go/eth-node/crypto"
|
|
"github.com/status-im/status-go/protocol/protobuf"
|
|
)
|
|
|
|
func (o *Community) ToSyncCommunityProtobuf(clock uint64, communitySettings *CommunitySettings) (*protobuf.SyncCommunity, error) {
|
|
var pkb []byte
|
|
pk := o.PrivateKey()
|
|
if pk != nil {
|
|
pkb = crypto.FromECDSA(pk)
|
|
}
|
|
|
|
md, err := o.ToBytes()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var rtjs []*protobuf.SyncCommunityRequestsToJoin
|
|
reqs := o.RequestsToJoin()
|
|
for _, req := range reqs {
|
|
rtjs = append(rtjs, req.ToSyncProtobuf())
|
|
}
|
|
|
|
settings := &protobuf.SyncCommunitySettings{
|
|
Clock: clock,
|
|
CommunityId: o.IDString(),
|
|
HistoryArchiveSupportEnabled: true,
|
|
}
|
|
|
|
if communitySettings != nil {
|
|
settings.HistoryArchiveSupportEnabled = communitySettings.HistoryArchiveSupportEnabled
|
|
}
|
|
|
|
return &protobuf.SyncCommunity{
|
|
Clock: clock,
|
|
Id: o.ID(),
|
|
PrivateKey: pkb,
|
|
Description: md,
|
|
Joined: o.Joined(),
|
|
Verified: o.Verified(),
|
|
Muted: o.Muted(),
|
|
RequestsToJoin: rtjs,
|
|
Settings: settings,
|
|
}, nil
|
|
}
|