mongo

package
v0.0.0-...-a3dc01b Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2024 License: AGPL-3.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TypeCommunityCensusChannel is the type for a community census that uses
	// a channel as source.
	TypeCommunityCensusChannel = "channel"
	// TypeCommunityCensusERC20 is the type for a community census that uses
	// ERC20 holders as source.
	TypeCommunityCensusERC20 = "erc20"
	// TypeCommunityCensusNFT is the type for a community census that uses
	// NFT holders as source.
	TypeCommunityCensusNFT = "nft"
	// TypeCommunityCensusFollowers is the type for a community census that uses
	// followers as source.
	TypeCommunityCensusFollowers = "followers"
)

Variables

View Source
var (
	ErrUserUnknown     = fmt.Errorf("user unknown")
	ErrAvatarUnknown   = fmt.Errorf("avatar unknown")
	ErrElectionUnknown = fmt.Errorf("electionID unknown")
	ErrNoResults       = fmt.Errorf("no results found")
)

Functions

func IsDBClosed

func IsDBClosed(err error) bool

Types

type Authentication

type Authentication struct {
	UserID     uint64    `json:"userId" bson:"_id"`
	AuthTokens []string  `json:"authTokens" bson:"authTokens"`
	UpdatedAt  time.Time `json:"updatedAt" bson:"updatedAt"`
}

Authentication represents the authentication data for a user.

type Avatar

type Avatar struct {
	ID          string    `json:"id" bson:"_id"`
	Data        []byte    `json:"data" bson:"data"`
	CreatedAt   time.Time `json:"createdAt" bson:"createdAt"`
	UserID      uint64    `json:"userId" bson:"userId"`
	CommunityID string    `json:"communityId" bson:"communityId"`
	ContentType string    `json:"contentType" bson:"contentType"`
}

Avatar represents an avatar image. Includes the avatar ID and the image data as a byte array.

type AvatarsCollection

type AvatarsCollection struct {
	Avatars []Avatar `json:"avatars" bson:"avatars"`
}

AvatarsCollection is a dataset containing several avatars from users and communities (used for dump and import).

type Census

type Census struct {
	CensusID              string            `json:"censusId" bson:"_id"`
	Root                  string            `json:"root" bson:"root"`
	ElectionID            string            `json:"electionId" bson:"electionId"`
	Participants          map[string]string `json:"participants" bson:"participants"`
	FromTotalParticipants uint32            `json:"fromTotalParticipants" bson:"fromTotalParticipants"`
	FromTotalAddresses    uint32            `json:"fromTotalAddresses" bson:"fromTotalAddresses"`
	CreatedBy             uint64            `json:"createdBy" bson:"createdBy"`
	TotalWeight           string            `json:"totalWeight" bson:"totalWeight"`
	URL                   string            `json:"url" bson:"url"`
}

Census stores the census of an election ready to be used for voting on farcaster.

type CensusCollection

type CensusCollection struct {
	Censuses []Census `json:"censuses" bson:"censuses"`
}

CensusCollection is a dataset containing several censuses (used for dump and import).

type Collection

Collection is a dataset containing several users, elections and results (used for dump and import).

type CommunitiesCollection

type CommunitiesCollection struct {
	Communities []Community `json:"communities" bson:"communities"`
}

CommunitiesCollection is a dataset containing several communities (used for dump and import).

type Community

type Community struct {
	ID               string          `json:"id" bson:"_id"`
	Name             string          `json:"name" bson:"name"`
	Channels         []string        `json:"channels" bson:"channels"`
	Census           CommunityCensus `json:"census" bson:"census"`
	ImageURL         string          `json:"imageURL" bson:"imageURL"`
	GroupChatURL     string          `json:"groupChatURL" bson:"groupChatURL"`
	Creator          uint64          `json:"creator" bson:"creator"`
	Admins           []uint64        `json:"owners" bson:"owners"`
	Notifications    bool            `json:"notifications" bson:"notifications"`
	Disabled         bool            `json:"disabled" bson:"disabled"`
	Featured         bool            `json:"featured" bson:"featured"`
	LastAnnouncement time.Time       `json:"lastAnnouncement" bson:"lastAnnouncement"`
}

Community represents a community entry.

type CommunityCensus

type CommunityCensus struct {
	Type      string                     `json:"type" bson:"type"`
	Addresses []CommunityCensusAddresses `json:"addresses" bson:"addresses"`
	Channel   string                     `json:"channel" bson:"channel"`
	Strategy  uint64                     `json:"strategy" bson:"strategy"`
}

CommunityCensus represents the census of a community in the database. It includes the name, type, and the census addresses (CommunityCensusAddresses) or the census channel (depending on the type).

type CommunityCensusAddresses

type CommunityCensusAddresses struct {
	Address    string `json:"address" bson:"address"`
	Blockchain string `json:"blockchain" bson:"blockchain"`
}

CommunityCensusAddresses represents the addresses of a contract to be used to create the census of a community.

type Delegation

type Delegation struct {
	ID         primitive.ObjectID `json:"id" bson:"_id"`
	From       uint64             `json:"from" bson:"from"`
	To         uint64             `json:"to" bson:"to"`
	CommuniyID string             `json:"communityId" bson:"communityId"`
	FromUser   *User              `json:"fromUser" bson:"fromUser"`
	ToUser     *User              `json:"toUser" bson:"toUser"`
}

Delegation represents a delegation of votes from one user to another for a specific community.

type DelegationsCollection

type DelegationsCollection struct {
	Delegations []Delegation `json:"delegations" bson:"delegations"`
}

DelegationsCollection is a dataset containing several delegations (used for dump and import).

type Election

type Election struct {
	ElectionID            string             `json:"electionId" bson:"_id"`
	UserID                uint64             `json:"userId" bson:"userId"`
	CastedVotes           uint64             `json:"castedVotes" bson:"castedVotes"`
	LastVoteTime          time.Time          `json:"lastVoteTime" bson:"lastVoteTime"`
	CreatedTime           time.Time          `json:"createdTime" bson:"createdTime"`
	EndTime               time.Time          `json:"endTime" bson:"endTime"`
	Source                string             `json:"source" bson:"source"`
	FarcasterUserCount    uint32             `json:"farcasterUserCount" bson:"farcasterUserCount"`
	InitialAddressesCount uint32             `json:"initialAddressesCount" bson:"initialAddressesCount"`
	Question              string             `json:"question" bson:"question"`
	Community             *ElectionCommunity `json:"community" bson:"community"`
	CastedWeight          string             `json:"castedWeight" bson:"castedWeight"`
}

Election represents an election and its details owned by a user.

type ElectionCollection

type ElectionCollection struct {
	Elections []Election `json:"elections" bson:"elections"`
}

ElectionCollection is a dataset containing several elections (used for dump and import).

type ElectionCommunity

type ElectionCommunity struct {
	ID   string `json:"id" bson:"id"`
	Name string `json:"name" bson:"name"`
}

ElectionCommunity represents the community used to create an election.

type ElectionMeta

type ElectionMeta struct {
	// CensusERC20TokenDecimals is the number of decimals that a certain ERC20 token, that was used
	// for creating the census of the election, has.
	CensusERC20TokenDecimals uint32 `json:"censusERC20TokenDecimals" bson:"censusERC20TokenDecimals"`
}

ElectionMeta stores non related election information that is useful for certain types of frame interactions

type ElectionRanking

type ElectionRanking struct {
	ElectionID           string `json:"electionId" bson:"_id"`
	VoteCount            uint64 `json:"voteCount" bson:"voteCount"`
	CreatedByFID         uint64 `json:"createdByFID" bson:"createdByFID"`
	CreatedByUsername    string `json:"createdByUsername" bson:"createdByUsername"`
	CreatedByDisplayname string `json:"createdByDisplayname" bson:"createdByDisplayname"`
	Title                string `json:"title" bson:"title"`
}

ElectionRanking is an election ranking entry.

type MongoStorage

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

MongoStorage uses an external MongoDB service for stoting the user data and election details.

func New

func New(url, database string) (*MongoStorage, error)

func (*MongoStorage) AddAuthentication

func (ms *MongoStorage) AddAuthentication(userFID uint64, authToken string) error

AddAuthentication adds an authentication token for a user and updates the CreatedAt field to the current time.

func (*MongoStorage) AddCensus

func (ms *MongoStorage) AddCensus(censusID types.HexBytes, userFID uint64) error

AddCensus creates a new census document in the database.

func (*MongoStorage) AddCommunity

func (ms *MongoStorage) AddCommunity(community *Community) error

func (*MongoStorage) AddElection

func (ms *MongoStorage) AddElection(
	electionID types.HexBytes,
	userFID uint64,
	source string,
	question string,
	usersCount, usersCountInitial uint32,
	endTime time.Time,
	community *ElectionCommunity,
) error

func (*MongoStorage) AddElectionCallback

func (ms *MongoStorage) AddElectionCallback(f funcGetElection)

AddElectionCallback adds a callback function to get the election details by its ID.

func (*MongoStorage) AddFinalResults

func (ms *MongoStorage) AddFinalResults(electionID types.HexBytes, finalPNG []byte, choices, votes []string) error

AddFinalResults adds the final results of an election in PNG format. It performs and upsert operation, so it will update the results if they already exist.

func (*MongoStorage) AddNotificationMutedUser

func (ms *MongoStorage) AddNotificationMutedUser(ownerUserID, mutedUserID uint64) error

AddNotificationMutedUser adds a user ID to the owner user's list of muted notifications users.

func (*MongoStorage) AddNotifications

func (ms *MongoStorage) AddNotifications(nType NotificationType, electionID string,
	userID, authorID uint64, communityID, username, authorUsername, communityName,
	frameURL, customText string, deadline time.Time,
) (int64, error)

func (*MongoStorage) AddParticipantsToCensus

func (ms *MongoStorage) AddParticipantsToCensus(censusID types.HexBytes, participants map[string]struct {
	Weight        *big.Int
	Participation uint32
},
	fromTotalAddresses uint32, censusURI string,
) error

AddParticipantsToCensus updates a census document with participants and their associated values.

func (*MongoStorage) AddUser

func (ms *MongoStorage) AddUser(
	userFID uint64,
	usernanme string,
	displayname string,
	addresses []string,
	signers []string,
	custodyAddr string,
	elections uint64,
) error

AddUser adds a new user to the database. If the user already exists, it returns an error.

func (*MongoStorage) AllCommunities

func (ms *MongoStorage) AllCommunities(limit, offset int64) ([]Community, int64, error)

AllCommunities returns the list of all communities.

func (*MongoStorage) Authentications

func (ms *MongoStorage) Authentications() ([]string, error)

Authentications returns the full list of authTokens.

func (*MongoStorage) Avatar

func (ms *MongoStorage) Avatar(avatarID string) (*Avatar, error)

Avatar returns an avatar image with the given avatarID.

func (*MongoStorage) Census

func (ms *MongoStorage) Census(censusID types.HexBytes) (Census, error)

Census retrieves a census document based on its ID.

func (*MongoStorage) CensusFromElection

func (ms *MongoStorage) CensusFromElection(electionID types.HexBytes) (*Census, error)

CensusFromRoot retrieves a Census document by its root.

func (*MongoStorage) CensusFromRoot

func (ms *MongoStorage) CensusFromRoot(root types.HexBytes) (*Census, error)

CensusFromRoot retrieves a Census document by its root.

func (*MongoStorage) CommunitiesByVoter

func (ms *MongoStorage) CommunitiesByVoter(userID uint64) ([]Community, error)

CommunitiesByVoter returns the list of communities with elections where the user is voter. It returns an error if something goes wrong with the database.

func (*MongoStorage) CommunitiesCountForUser

func (ms *MongoStorage) CommunitiesCountForUser(userID uint64) (uint64, error)

CommunitiesCountForUser calculates the number of communities where the user is an admin.

func (*MongoStorage) Community

func (ms *MongoStorage) Community(id string) (*Community, error)

func (*MongoStorage) CommunityAllowNotifications

func (ms *MongoStorage) CommunityAllowNotifications(communityID string) bool

CommunityAllowNotifications checks if the community with the given ID has notifications enabled.

func (*MongoStorage) CommunityParticipationMean

func (ms *MongoStorage) CommunityParticipationMean(communityID string) (float64, error)

CommunityParticipationMean returns the mean of the participation of the every community poll with the given ID. It returns an error if something goes wrong with the database.

func (*MongoStorage) CountUsers

func (ms *MongoStorage) CountUsers() uint64

CountUsers returns the total number of users in the database.

func (*MongoStorage) DelCommunity

func (ms *MongoStorage) DelCommunity(communityID string) error

DelCommunity removes the community with the specified ID from the database. If an error occurs, it returns the error.

func (*MongoStorage) DelNotificationMutedUser

func (ms *MongoStorage) DelNotificationMutedUser(ownerUserID, unmutedUserID uint64) error

DelNotificationMutedUser removes a user ID from the owner user's list of muted notifications users.

func (*MongoStorage) DelUser

func (ms *MongoStorage) DelUser(userFID uint64) error

func (*MongoStorage) Delegation

func (ms *MongoStorage) Delegation(id string) (Delegation, error)

Delegation retrieves a delegation from the database by its ID

func (*MongoStorage) DelegationsByCommunity

func (ms *MongoStorage) DelegationsByCommunity(communityID string, solveNested, fullUserInfo bool) ([]*Delegation, error)

DelegationsByCommunity retrieves all delegations to a community by the community ID provided

func (*MongoStorage) DelegationsByCommunityFrom

func (ms *MongoStorage) DelegationsByCommunityFrom(communityID string, userID uint64, fullUserInfo bool) ([]*Delegation, error)

DelegationsByCommunityFrom retrieves all delegations from a user to a community by the community ID and user ID provided

func (*MongoStorage) DelegationsFrom

func (ms *MongoStorage) DelegationsFrom(userID uint64, fullUserInfo bool) ([]*Delegation, error)

DelegationsFrom retrieves all delegations from a user by their user ID provided

func (*MongoStorage) DelegationsTo

func (ms *MongoStorage) DelegationsTo(userID uint64, fullUserInfo bool) ([]*Delegation, error)

DelegationsTo retrieves all delegations to a user by their user ID provided

func (*MongoStorage) DeleteDelegation

func (ms *MongoStorage) DeleteDelegation(id string) error

DeleteDelegation deletes a delegation from the database by its ID

func (*MongoStorage) DetailedCommunityReputation

func (ms *MongoStorage) DetailedCommunityReputation(communityID string) (*Reputation, error)

DetailedCommunityReputation method return the reputation of a community based on the community ID. It returns the detailed reputation information and values from the database.

func (*MongoStorage) DetailedUserReputation

func (ms *MongoStorage) DetailedUserReputation(userID uint64) (*Reputation, error)

DetailedUserReputation method return the reputation of a user based on the user ID. It returns the detailed reputation information and values from the database.

func (*MongoStorage) Election

func (ms *MongoStorage) Election(electionID types.HexBytes) (*Election, error)

func (*MongoStorage) ElectionsByCommunity

func (ms *MongoStorage) ElectionsByCommunity(communityID string) ([]*Election, error)

ElectionsByCommunity returns all the elections created by the community with the ID.

func (*MongoStorage) ElectionsByUser

func (ms *MongoStorage) ElectionsByUser(userFID uint64, count int64) ([]ElectionRanking, error)

ElectionsByUser returns all the elections created by the user with the FID provided, sorted by CreatedTime in descending order.

func (*MongoStorage) ElectionsByVoteNumber

func (ms *MongoStorage) ElectionsByVoteNumber() ([]*Election, error)

ElectionsByVoteNumber returns the list of elections ordered by the number of votes casted within the last 60 days.

func (*MongoStorage) ElectionsWithoutResults

func (ms *MongoStorage) ElectionsWithoutResults() ([]string, error)

ElectionsWithoutResults returns a list of election IDs where results are not finalized or where the finalized field is not set.

func (*MongoStorage) FinalResultsPNG

func (ms *MongoStorage) FinalResultsPNG(electionID types.HexBytes) []byte

FinalResultsPNG returns the final results of an election in PNG format. It returns nil if the results image is not found.

func (*MongoStorage) Import

func (ms *MongoStorage) Import(jsonData []byte) error

Import imports a JSON dataset produced by String() into the database.

func (*MongoStorage) IncreaseVoteCount

func (ms *MongoStorage) IncreaseVoteCount(userFID uint64, electionID types.HexBytes, weight *big.Int, participation uint32) error

func (*MongoStorage) IsCommunityAdmin

func (ms *MongoStorage) IsCommunityAdmin(userID uint64, communityID string) bool

IsCommunityAdmin checks if the user is an admin of the given community by ID.

func (*MongoStorage) IsCommunityDisabled

func (ms *MongoStorage) IsCommunityDisabled(communityID string) bool

IsCommunityDisabled checks if the community with the given ID is disabled.

func (*MongoStorage) IsUserNotificationMuted

func (ms *MongoStorage) IsUserNotificationMuted(ownerUserID, mutedUserID uint64) (bool, error)

IsUserNotificationMuted checks if a user's notifications are muted by the owner user.

func (*MongoStorage) LastCommunityID

func (ms *MongoStorage) LastCommunityID(prefix string) (string, error)

func (*MongoStorage) LastCreatedElections

func (ms *MongoStorage) LastCreatedElections(count int) ([]*Election, error)

LastCreatedElections returns the last created elections.

func (*MongoStorage) LastNotifications

func (ms *MongoStorage) LastNotifications(maxResults int) ([]Notification, error)

LastNotifications returns the registered notifications in the database ordered by the _id field in descending order and limited to the specified number of results. If an error occurs, it returns the error.

func (*MongoStorage) LatestElections

func (ms *MongoStorage) LatestElections(limit, offset int64) ([]*Election, int64, error)

LatestElections returns the latest elections, sorted by CreatedTime in descending order.

func (*MongoStorage) ListCommunities

func (ms *MongoStorage) ListCommunities(limit, offset int64) ([]Community, int64, error)

ListCommunities returns the list of enabled communities.

func (*MongoStorage) ListCommunitiesByAdminFID

func (ms *MongoStorage) ListCommunitiesByAdminFID(fid uint64, limit, offset int64) ([]Community, int64, error)

ListCommunitiesByAdminFID returns the list of communities where the user is an admin by FID provided.

func (*MongoStorage) ListCommunitiesByAdminUsername

func (ms *MongoStorage) ListCommunitiesByAdminUsername(username string, limit, offset int64) ([]Community, int64, error)

ListCommunitiesByAdminUsername returns the list of communities where the user is an admin by username provided. It queries about the user FID first.

func (*MongoStorage) ListCommunitiesByCreatorFID

func (ms *MongoStorage) ListCommunitiesByCreatorFID(fid uint64, limit, offset int64) ([]Community, int64, error)

ListCommunitiesByAdminFID returns the list of communities where the user is the creator by FID provided.

func (*MongoStorage) ListFeaturedCommunities

func (ms *MongoStorage) ListFeaturedCommunities(limit, offset int64) ([]Community, int64, error)

ListFeaturedCommunities returns the list of featured communities.

func (*MongoStorage) ListNotificationMutedUsers

func (ms *MongoStorage) ListNotificationMutedUsers(ownerUserID uint64) ([]*User, error)

ListNotificationMutedUsers returns a list of user IDs muted by the owner user.

func (*MongoStorage) NormalizeUserAddresses

func (ms *MongoStorage) NormalizeUserAddresses() error

func (*MongoStorage) ParticipantParticipation

func (ms *MongoStorage) ParticipantParticipation(censusRoot types.HexBytes, fid uint64) (uint32, error)

ParticipantParticipation retrieves the participation value for a given participant in a census.

func (*MongoStorage) ParticipantsByWeight

func (ms *MongoStorage) ParticipantsByWeight(electionID types.HexBytes, n int) (map[string]*big.Int, error)

ParticipantsByWeight retrieves the top N participants by weight in a census.

func (*MongoStorage) PopulateRemindableVoters

func (ms *MongoStorage) PopulateRemindableVoters(electionID types.HexBytes) error

PopulateRemindableVoters creates the list of remindable voters for an election.

func (*MongoStorage) RemindersOfElection

func (ms *MongoStorage) RemindersOfElection(electionID types.HexBytes) (map[uint64]string, uint64, error)

RemindersOfElection returns the list of remindable voters of an election and the number of already reminded voters.

func (*MongoStorage) RemindersSent

func (ms *MongoStorage) RemindersSent(electionID types.HexBytes, reminders map[uint64]string) error

RemindersSent updates the list of remindable voters and the list of already reminded voters of an election. It receives a map of user fids and usernames of the last reminders sent, and updates the lists accordingly, by removing the users from the remindable list and adding them to the already reminded list.

func (*MongoStorage) RemoveAvatar

func (ms *MongoStorage) RemoveAvatar(avatarID string) error

RemoveAvatar removes the avatar image data for the given avatarID.

func (*MongoStorage) RemoveNotification

func (ms *MongoStorage) RemoveNotification(notificationID int64) error

RemoveNotification removes the notification with the specified ID from the database. If an error occurs, it returns the error.

func (*MongoStorage) ReputableUsers

func (ms *MongoStorage) ReputableUsers() ([]*User, error)

UsersIterator iterates over available users and sends them to the provided channel.

func (*MongoStorage) ReputationRanking

func (ms *MongoStorage) ReputationRanking(users, communities bool) ([]ReputationRanking, error)

func (*MongoStorage) Reputations

func (ms *MongoStorage) Reputations() ([]*Reputation, error)

ReputationsIterator iterates over available reputations and sends them to the provided channel.

func (*MongoStorage) Reset

func (ms *MongoStorage) Reset() error

func (*MongoStorage) Results

func (ms *MongoStorage) Results(electionID types.HexBytes) (*Results, error)

Results retrieves the final results of an election.

func (*MongoStorage) SetAccessLevelForUser

func (ms *MongoStorage) SetAccessLevelForUser(userID uint64, accessLevel uint32) error

SetAccessLevelForUser updates the access level for a given user ID.

func (*MongoStorage) SetAvatar

func (ms *MongoStorage) SetAvatar(avatarID string, data []byte, userID uint64, communityID, contentType string) error

SetAvatar sets the avatar image data for the given avatarID. If the avatar does not exist, it will be created with the given data, otherwise it will be updated.

func (*MongoStorage) SetCommunityCensusStrategy

func (ms *MongoStorage) SetCommunityCensusStrategy(communityID string, strategyID uint64) error

SetCommunityCensusStrategy sets the census strategy of the community with the given ID.

func (*MongoStorage) SetCommunityLastAnnouncement

func (ms *MongoStorage) SetCommunityLastAnnouncement(communityID string, t time.Time) error

SetCommunityLastAnnouncement sets the last announcement time of the community with the given ID.

func (*MongoStorage) SetCommunityNotifications

func (ms *MongoStorage) SetCommunityNotifications(communityID string, enabled bool) error

SetCommunityNotifications sets the disabled status of the community with the given ID.

func (*MongoStorage) SetCommunityStatus

func (ms *MongoStorage) SetCommunityStatus(communityID string, disabled bool) error

SetCommunityStatus sets the disabled status of the community with the given ID.

func (*MongoStorage) SetDelegation

func (ms *MongoStorage) SetDelegation(delegation Delegation) (string, error)

SetDelegation inserts a delegation into the database and returns the ID of the inserted delegation

func (*MongoStorage) SetDetailedReputationForCommunity

func (ms *MongoStorage) SetDetailedReputationForCommunity(communityID string, reputation *Reputation) error

SetDetailedReputationForCommunity method updates the detailed reputation for a given community ID. It overwrites the previous reputation values with the provided values, if some values are not provided, they will keep the previous values if they exist.

func (*MongoStorage) SetDetailedReputationForUser

func (ms *MongoStorage) SetDetailedReputationForUser(userID uint64, reputation *Reputation) error

SetDetailedReputationForUser method updates the detailed reputation for a given user ID. It overwrites the previous reputation values with the provided values, if some values are not provided, they will keep the previous values if they exist.

func (*MongoStorage) SetElectionIdForCensusRoot

func (ms *MongoStorage) SetElectionIdForCensusRoot(root, electionID types.HexBytes) error

SetElectionIdForCensusRoot updates the electionId for a given census document. It will only be set if the electionId field is empty. If the census does not exist, it returns nil without error.

func (*MongoStorage) SetElectionQuestion

func (ms *MongoStorage) SetElectionQuestion(electionID types.HexBytes, question string) error

func (*MongoStorage) SetNotificationDeadline

func (ms *MongoStorage) SetNotificationDeadline(notificationID int64, deadline time.Time) error

SetNotificationDeadline sets the deadline for the notification with the specified ID. If an error occurs, it returns the error.

func (*MongoStorage) SetNotificationsAcceptedForUser

func (ms *MongoStorage) SetNotificationsAcceptedForUser(userID uint64, accepted bool) error

SetNotificationsAcceptedForUser updates the notifications accepted status for a given user ID.

func (*MongoStorage) SetNotificationsRequestedForUser

func (ms *MongoStorage) SetNotificationsRequestedForUser(userID uint64, requested bool) error

SetNotificationsRequestedForUser updates the notifications requested status for a given user ID.

func (*MongoStorage) SetPartialResults

func (ms *MongoStorage) SetPartialResults(electionID types.HexBytes, choices, votes []string) error

SetPartialResults sets or updates the choices and votes for an election result only if it is not finalized. It performs an upsert operation, so it will create the result entry if it does not exist and is not finalized.

func (*MongoStorage) SetRootForCensus

func (ms *MongoStorage) SetRootForCensus(censusID, root types.HexBytes) error

SetRootForCensus updates the root for a given census document. If the census does not exist, it returns nil without error.

func (*MongoStorage) SetWarpcastAPIKey

func (ms *MongoStorage) SetWarpcastAPIKey(userID uint64, apiKey string) error

SetWarpcastAPIKey updates the user api key for warpcast.

func (*MongoStorage) SetWhiteListedForUser

func (ms *MongoStorage) SetWhiteListedForUser(userID uint64, whiteListed bool) error

SetWhiteListedForUser updates the white listed status for a given user ID.

func (*MongoStorage) String

func (ms *MongoStorage) String() string

func (*MongoStorage) TotalVotesForUserElections

func (ms *MongoStorage) TotalVotesForUserElections(userID uint64) (uint64, error)

TotalVotesForUserElections calculates the total number of votes casted on elections created by the user.

func (*MongoStorage) UpdateActivityAndGetData

func (ms *MongoStorage) UpdateActivityAndGetData(authToken string) (*Authentication, error)

UpdateActivityAndGetData updates the activity timer and retrieves the Authentication data for a given authToken.

func (*MongoStorage) UpdateCommunity

func (ms *MongoStorage) UpdateCommunity(community *Community) error

func (*MongoStorage) UpdateUser

func (ms *MongoStorage) UpdateUser(udata *User) error

func (*MongoStorage) User

func (ms *MongoStorage) User(userFID uint64) (*User, error)

func (*MongoStorage) UserAccessProfile

func (ms *MongoStorage) UserAccessProfile(userID uint64) (*UserAccessProfile, error)

UserAccessProfile retrieves the access profile for a given user ID. Returns ErrUserUnknown if the user is not found.

func (*MongoStorage) UserAuthorizations

func (ms *MongoStorage) UserAuthorizations(userID uint64) ([]string, error)

UserAuthorizations method returns the tokens of a user for the fid provider. If the user is not found, it returns ErrUserUnknown.

func (*MongoStorage) UserByAddress

func (ms *MongoStorage) UserByAddress(address string) (*User, error)

UserByAddress returns the user that has the given address. If the user is not found, it returns an error.

func (*MongoStorage) UserByAddressBulk

func (ms *MongoStorage) UserByAddressBulk(addresses []string) (map[string]*User, error)

UserByAddressBulk returns a map of users that have the given addresses. If the user is not found, it returns an error.

func (*MongoStorage) UserByAddressCaseInsensitive

func (ms *MongoStorage) UserByAddressCaseInsensitive(address string) (*User, error)

UserByAddress returns the user that has the given address (case insensitive). If the user is not found, it returns an error. Warning, this is expensive and should be used with caution.

func (*MongoStorage) UserByReputation

func (ms *MongoStorage) UserByReputation() ([]UserRanking, error)

UserByReputation returns the list of users ordered by their reputation score.

func (*MongoStorage) UserBySigner

func (ms *MongoStorage) UserBySigner(signer string) (*User, error)

UserBySigner returns the user that has the given signer. If the user is not found, it returns an error.

func (*MongoStorage) UserByUsername

func (ms *MongoStorage) UserByUsername(username string) (*User, error)

UserByUsername returns the user that has the given username. If the user is not found, it returns an error.

func (*MongoStorage) UserExists

func (ms *MongoStorage) UserExists(userFID uint64) bool

func (*MongoStorage) UserFromAuthToken

func (ms *MongoStorage) UserFromAuthToken(authToken string) (uint64, error)

CheckAuthentication checks if the authToken is valid and returns the corresponding userID. If the token is not found, it returns ErrUserUnknown.

func (*MongoStorage) UserIDs

func (ms *MongoStorage) UserIDs(startId uint64, maxResults int) ([]uint64, error)

UserIDs returns a list of user IDs starting from the given ID and limited to the specified amount.

func (*MongoStorage) UsersByElectionNumber

func (ms *MongoStorage) UsersByElectionNumber() ([]UserRanking, error)

UsersByElectionNumber returns the list of users ordered by the number of elections they have created.

func (*MongoStorage) UsersByVoteNumber

func (ms *MongoStorage) UsersByVoteNumber() ([]UserRanking, error)

UsersByVoteNumber returns the list of users ordered by the number of votes they have casted.

func (*MongoStorage) UsersWithPendingProfile

func (ms *MongoStorage) UsersWithPendingProfile() ([]uint64, error)

UsersWithPendingProfile returns the list of users that have not set their username yet. This call is limited to 32 users.

func (*MongoStorage) VotersOfElection

func (ms *MongoStorage) VotersOfElection(electionID types.HexBytes) ([]*User, error)

VotersOfElection returns the list of voters of an election (usernames).

type Notification

type Notification struct {
	ID             int64            `json:"id" bson:"_id"`
	Type           NotificationType `json:"type" bson:"type"`
	UserID         uint64           `json:"userId" bson:"userId"`
	Username       string           `json:"username" bson:"username"`
	AuthorID       uint64           `json:"authorId" bson:"authorId"`
	AuthorUsername string           `json:"authorUsername" bson:"authorUsername"`
	CommunityID    string           `json:"communityId" bson:"communityId"`
	CommunityName  string           `json:"communityName" bson:"communityName"`
	ElectionID     string           `json:"electionId" bson:"electionId"`
	FrameUrl       string           `json:"frameUrl" bson:"frameUrl"`
	CustomText     string           `json:"customText" bson:"customText"`
	Deadline       time.Time        `json:"deadline" bson:"deadline"`
}

Notification represents a notification to be sent to a user.

type NotificationType

type NotificationType int

NotificationType represents the type of notification to be sent to a user.

const (
	NotificationTypeNewElection NotificationType = iota
)

type Options

type Options struct {
	MongoURL string
	Database string
}

type Reputation

type Reputation struct {
	// ids
	CommunityID     string `json:"communityID" bson:"communityID"`
	UserID          uint64 `json:"userID" bson:"userID"`
	TotalReputation uint64 `json:"totalReputation" bson:"totalReputation"`
	TotalPoints     uint64 `json:"totalPoints" bson:"totalPoints"`
	// community
	Participation float64 `json:"participation" bson:"participation"`
	CensusSize    uint64  `json:"censusSize" bson:"censusSize"`
	// activity
	FollowersCount        uint64 `json:"followersCount" bson:"followersCount"`
	ElectionsCreatedCount uint64 `json:"electionsCreatedCount" bson:"electionsCreatedCount"`
	CastVotesCount        uint64 `json:"castVotesCount" bson:"castVotesCount"`
	ParticipationsCount   uint64 `json:"participationsCount" bson:"participationsCount"`
	CommunitiesCount      uint64 `json:"communitiesCount" bson:"communitiesCount"`
	// boosters
	HasVotecasterNFTPass           bool `json:"hasVotecasterNFTPass" bson:"hasVotecasterNFTPass"`
	HasVotecasterLaunchNFT         bool `json:"hasVotecasterLaunchNFT" bson:"hasVotecasterLaunchNFT"`
	IsVotecasterAlphafrensFollower bool `json:"isVotecasterAlphafrensFollower" bson:"isVotecasterAlphafrensFollower"`
	IsVotecasterFarcasterFollower  bool `json:"isVotecasterFarcasterFollower" bson:"isVotecasterFarcasterFollower"`
	IsVocdoniFarcasterFollower     bool `json:"isVocdoniFarcasterFollower" bson:"isVocdoniFarcasterFollower"`
	VotecasterAnnouncementRecasted bool `json:"votecasterAnnouncementRecasted" bson:"votecasterAnnouncementRecasted"`
	HasKIWI                        bool `json:"hasKIWI" bson:"hasKIWI"`
	HasDegenDAONFT                 bool `json:"hasDegenDAONFT" bson:"hasDegenDAONFT"`
	HasHaberdasheryNFT             bool `json:"hasHaberdasheryNFT" bson:"hasHaberdasheryNFT"`
	Has10kDegenAtLeast             bool `json:"has10kDegenAtLeast" bson:"has10kDegenAtLeast"`
	HasTokyoDAONFT                 bool `json:"hasTokyoDAONFT" bson:"hasTokyoDAONFT"`
	HasProxy                       bool `json:"hasProxy" bson:"hasProxy"`
	Has5ProxyAtLeast               bool `json:"has5ProxyAtLeast" bson:"has5ProxyAtLeast"`
	HasProxyStudioNFT              bool `json:"hasProxyStudioNFT" bson:"hasProxyStudioNFT"`
	HasNameDegen                   bool `json:"hasNameDegen" bson:"hasNameDegen"`
	HasFarcasterOGNFT              bool `json:"hasFarcasterOGNFT" bson:"hasFarcasterOGNFT"`
	HasMoxiePass                   bool `json:"hasMoxiePass" bson:"hasMoxiePass"`
}

type ReputationCollection

type ReputationCollection struct {
	Reputations []Reputation `json:"reputations" bson:"reputations"`
}

ReputationCollection is a dataset containing several reputations (used for dump and import).

type ReputationRanking

type ReputationRanking struct {
	UserID           uint64 `json:"userID" bson:"userID"`
	Username         string `json:"username" bson:"username"`
	UserDisplayname  string `json:"userDisplayname" bson:"userDisplayname"`
	CommunityID      string `json:"communityID" bson:"communityID"`
	CommunityName    string `json:"communityName" bson:"communityName"`
	CommunityCreator uint64 `json:"communityCreator" bson:"communityCreator"`
	TotalPoints      uint64 `json:"totalPoints" bson:"totalPoints"`
	ImageURL         string `json:"imageURL" bson:"imageURL"`
}

type Results

type Results struct {
	ElectionID string   `json:"electionId" bson:"_id"`
	FinalPNG   []byte   `json:"finalPNG" bson:"finalPNG"`
	Choices    []string `json:"title" bson:"title"`
	Votes      []string `json:"votes" bson:"votes"`
	Finalized  bool     `json:"finalized" bson:"finalized"`
}

Results represents the final results of an election.

type ResultsCollection

type ResultsCollection struct {
	Results []Results `json:"results" bson:"results"`
}

ResultsCollection is a dataset containing several election results (used for dump and import).

type User

type User struct {
	UserID         uint64    `json:"userID,omitempty" bson:"_id"`
	ElectionCount  uint64    `json:"electionCount" bson:"electionCount"`
	CastedVotes    uint64    `json:"castedVotes" bson:"castedVotes"`
	Username       string    `json:"username" bson:"username"`
	Displayname    string    `json:"displayName" bson:"displayname"`
	CustodyAddress string    `json:"custodyAddress" bson:"custodyAddress"`
	Addresses      []string  `json:"addresses" bson:"addresses"`
	Signers        []string  `json:"signers" bson:"signers"`
	Followers      uint64    `json:"followers" bson:"followers"`
	LastUpdated    time.Time `json:"lastUpdated" bson:"lastUpdated"`
	Avatar         string    `json:"avatar" bson:"avatar"`
}

User represents a farcaster user.

type UserAccessProfile

type UserAccessProfile struct {
	UserID                  uint64   `json:"userID,omitempty" bson:"_id"`
	NotificationsAccepted   bool     `json:"notificationsAccepted" bson:"notificationsAccepted"`
	NotificationsRequested  bool     `json:"notificationsRequested" bson:"notificationsRequested"`
	Reputation              uint32   `json:"reputation" bson:"reputation"`
	AccessLevel             uint32   `json:"accessLevel" bson:"accessLevel"`
	WhiteListed             bool     `json:"whiteListed" bson:"whiteListed"`
	NotificationsMutedUsers []uint64 `json:"notificationsMutedUsers" bson:"notificationsMutedUsers"`
	WarpcastAPIKey          string   `json:"warpcastAPIKey" bson:"warpcastAPIKey"`
}

UserAccessProfile holds the user's access profile data, used by our backend to determine the user's access level. It also holds the notification status.

type UserAccessProfileCollection

type UserAccessProfileCollection struct {
	UserAccessProfiles []UserAccessProfile `json:"userAccessProfiles" bson:"userAccessProfiles"`
}

UserAccessProfileCollection is a dataset containing several user access profiles (used for dump and import).

type UserCollection

type UserCollection struct {
	Users []User `json:"users" bson:"users"`
}

UserCollection is a dataset containing several users (used for dump and import).

type UserRanking

type UserRanking struct {
	FID         uint64 `json:"fid" bson:"fid"`
	Username    string `json:"username" bson:"username"`
	Displayname string `json:"displayName" bson:"displayname"`
	Count       uint64 `json:"count" bson:"count"`
}

UserRanking is a user ranking entry.

type Users

type Users struct {
	Users []uint64 `json:"users"`
}

Users is the list of users.

type VotersOfElection

type VotersOfElection struct {
	ElectionID       string            `json:"electionId" bson:"_id"`
	Voters           []uint64          `json:"voters" bson:"voters"`
	AlreadyReminded  map[uint64]string `json:"already_reminded" bson:"already_reminded"`
	RemindableVoters map[uint64]string `json:"remindable_voters" bson:"remindable_voters"`
}

VotersOfElection represents the list of voters of an election. It includes the list of voters, the list of users that have already been reminded and the list of users that can be reminded about the election.

type VotersOfElectionCollection

type VotersOfElectionCollection struct {
	VotersOfElection []VotersOfElection `json:"votersOfElection" bson:"votersOfElection"`
}

VotersOfElectionCollection is a dataset containing several voters of elections (used for dump and import).

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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