communities

package
v0.70.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 5, 2021 License: MPL-2.0, MPL-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrCantRequestAccess = errors.New("can't request access")
View Source
var ErrChatAlreadyExists = errors.New("chat already exists")
View Source
var ErrChatNotFound = errors.New("chat not found")
View Source
var ErrInvalidCommunityDescription = errors.New("invalid community description")
View Source
var ErrInvalidCommunityDescriptionMemberInChatButNotInOrg = errors.New("invalid community description member in chat but not in org")
View Source
var ErrInvalidCommunityDescriptionNoChatPermissions = errors.New("invalid community description no chat permissions")
View Source
var ErrInvalidCommunityDescriptionNoOrgPermissions = errors.New("invalid community description no org permissions")
View Source
var ErrInvalidCommunityDescriptionUnknownChatAccess = errors.New("invalid community description unknown chat access")
View Source
var ErrInvalidCommunityDescriptionUnknownOrgAccess = errors.New("invalid community description unknown org access")
View Source
var ErrInvalidGrant = errors.New("invalid grant")
View Source
var ErrInvalidMessage = errors.New("invalid community description message")
View Source
var ErrNotAdmin = errors.New("no admin privileges for this community")
View Source
var ErrNotAuthorized = errors.New("not authorized")
View Source
var ErrOrgNotFound = errors.New("community not found")

Functions

func ValidateCommunityDescription

func ValidateCommunityDescription(desc *protobuf.CommunityDescription) error

Types

type Community

type Community struct {
	// contains filtered or unexported fields
}

func New

func New(config Config) (*Community, error)

func (*Community) AcceptRequestToJoin

func (o *Community) AcceptRequestToJoin(pk *ecdsa.PublicKey) (*protobuf.CommunityRequestJoinResponse, error)

TODO: this should accept a request from a user to join and perform any validation

func (*Community) CanPost

func (o *Community) CanPost(pk *ecdsa.PublicKey, chatID string, grantBytes []byte) (bool, error)

func (*Community) Chats

func (o *Community) Chats() map[string]*protobuf.CommunityChat

func (*Community) CreateChat

func (o *Community) CreateChat(chatID string, chat *protobuf.CommunityChat) (*CommunityChanges, error)

func (*Community) DeclineRequestToJoin

func (o *Community) DeclineRequestToJoin(pk *ecdsa.PublicKey) (*protobuf.CommunityRequestJoinResponse, error)

TODO: this should decline a request from a user to join

func (*Community) DeleteChat

func (o *Community) DeleteChat(chatID string) (*protobuf.CommunityDescription, error)

func (*Community) HandleCommunityDescription

func (o *Community) HandleCommunityDescription(signer *ecdsa.PublicKey, description *protobuf.CommunityDescription, rawMessage []byte) (*CommunityChanges, error)

func (*Community) HandleRequestJoin

func (o *Community) HandleRequestJoin(signer *ecdsa.PublicKey, request *protobuf.CommunityRequestJoin) error

HandleRequestJoin handles a request, checks that the right permissions are applied and returns an CommunityRequestJoinResponse

func (*Community) HasMember

func (o *Community) HasMember(pk *ecdsa.PublicKey) bool

func (*Community) ID

func (o *Community) ID() []byte

func (*Community) IDString

func (o *Community) IDString() string

func (*Community) InviteUserToChat

func (o *Community) InviteUserToChat(pk *ecdsa.PublicKey, chatID string) (*protobuf.CommunityInvitation, error)

func (*Community) InviteUserToOrg

func (o *Community) InviteUserToOrg(pk *ecdsa.PublicKey) (*protobuf.CommunityInvitation, error)

func (*Community) IsAdmin

func (o *Community) IsAdmin() bool

func (*Community) IsMemberInChat

func (o *Community) IsMemberInChat(pk *ecdsa.PublicKey, chatID string) bool

func (*Community) Join

func (o *Community) Join()

func (*Community) Joined

func (o *Community) Joined() bool

func (*Community) Leave

func (o *Community) Leave()

func (*Community) MarshalJSON

func (o *Community) MarshalJSON() ([]byte, error)

func (*Community) MarshaledDescription

func (o *Community) MarshaledDescription() ([]byte, error)

func (*Community) PrivateKey

func (o *Community) PrivateKey() *ecdsa.PrivateKey

func (*Community) RemoveUserFromChat

func (o *Community) RemoveUserFromChat(pk *ecdsa.PublicKey, chatID string) (*protobuf.CommunityDescription, error)

func (*Community) RemoveUserFromOrg

func (o *Community) RemoveUserFromOrg(pk *ecdsa.PublicKey) (*protobuf.CommunityDescription, error)

func (*Community) ToBytes

func (o *Community) ToBytes() ([]byte, error)

ToBytes returns the community in a wrapped & signed protocol message

func (*Community) VerifyGrantSignature

func (o *Community) VerifyGrantSignature(data []byte) (*protobuf.Grant, error)

type CommunityChanges

type CommunityChanges struct {
	MembersAdded   map[string]*protobuf.CommunityMember
	MembersRemoved map[string]*protobuf.CommunityMember

	ChatsRemoved  map[string]*protobuf.CommunityChat
	ChatsAdded    map[string]*protobuf.CommunityChat
	ChatsModified map[string]*CommunityChatChanges
}

type CommunityChatChanges

type CommunityChatChanges struct {
	MembersAdded   map[string]*protobuf.CommunityMember
	MembersRemoved map[string]*protobuf.CommunityMember
}

type Config

type Config struct {
	PrivateKey                    *ecdsa.PrivateKey
	CommunityDescription          *protobuf.CommunityDescription
	MarshaledCommunityDescription []byte
	ID                            *ecdsa.PublicKey
	Joined                        bool
	Verified                      bool
	Logger                        *zap.Logger
}

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

func NewManager

func NewManager(db *sql.DB, logger *zap.Logger) (*Manager, error)

func (*Manager) All

func (m *Manager) All() ([]*Community, error)

func (*Manager) CanPost

func (m *Manager) CanPost(pk *ecdsa.PublicKey, orgIDString, chatID string, grant []byte) (bool, error)

func (*Manager) CreateChat

func (m *Manager) CreateChat(idString string, chat *protobuf.CommunityChat) (*Community, *CommunityChanges, error)

func (*Manager) CreateCommunity

func (m *Manager) CreateCommunity(description *protobuf.CommunityDescription) (*Community, error)

CreateCommunity takes a description, generates an ID for it, saves it and return it

func (*Manager) Created

func (m *Manager) Created() ([]*Community, error)

func (*Manager) ExportCommunity

func (m *Manager) ExportCommunity(idString string) (*ecdsa.PrivateKey, error)

func (*Manager) GetByIDString

func (m *Manager) GetByIDString(idString string) (*Community, error)

func (*Manager) HandleCommunityDescriptionMessage

func (m *Manager) HandleCommunityDescriptionMessage(signer *ecdsa.PublicKey, description *protobuf.CommunityDescription, payload []byte) (*Community, error)

func (*Manager) HandleCommunityInvitation

func (m *Manager) HandleCommunityInvitation(signer *ecdsa.PublicKey, invitation *protobuf.CommunityInvitation, payload []byte) (*Community, error)

TODO: Finish implementing this

func (*Manager) HandleWrappedCommunityDescriptionMessage

func (m *Manager) HandleWrappedCommunityDescriptionMessage(payload []byte) (*Community, error)

func (*Manager) ImportCommunity

func (m *Manager) ImportCommunity(key *ecdsa.PrivateKey) (*Community, error)

func (*Manager) InviteUserToCommunity

func (m *Manager) InviteUserToCommunity(idString string, pk *ecdsa.PublicKey) (*Community, error)

func (*Manager) JoinCommunity

func (m *Manager) JoinCommunity(idString string) (*Community, error)

func (*Manager) Joined

func (m *Manager) Joined() ([]*Community, error)

func (*Manager) LeaveCommunity

func (m *Manager) LeaveCommunity(idString string) (*Community, error)

func (*Manager) RemoveUserFromCommunity

func (m *Manager) RemoveUserFromCommunity(idString string, pk *ecdsa.PublicKey) (*Community, error)

func (*Manager) Stop

func (m *Manager) Stop() error

func (*Manager) Subscribe

func (m *Manager) Subscribe() chan *Subscription

type Persistence

type Persistence struct {
	// contains filtered or unexported fields
}

func (*Persistence) AllCommunities

func (p *Persistence) AllCommunities() ([]*Community, error)

func (*Persistence) CreatedCommunities

func (p *Persistence) CreatedCommunities() ([]*Community, error)

func (*Persistence) GetByID

func (p *Persistence) GetByID(id []byte) (*Community, error)

func (*Persistence) JoinedCommunities

func (p *Persistence) JoinedCommunities() ([]*Community, error)

func (*Persistence) SaveCommunity

func (p *Persistence) SaveCommunity(community *Community) error

type Subscription

type Subscription struct {
	Community  *Community
	Invitation *protobuf.CommunityInvitation
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL