models

package
v0.0.0-...-d9c4052 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2014 License: GPL-3.0 Imports: 7 Imported by: 6

Documentation

Index

Constants

View Source
const (
	NotificationFollowRequest         = 1
	NotificationFollowRequestAccepted = 2
	NotificationFollowed              = 3
	NotificationPostLiked             = 4
	NotificationPostCommented         = 5
	NotificationPostOnMyWall          = 6
)
View Source
const (
	// Post types
	PostStatus = 1
	PostPhoto  = 2
	PostVideo  = 3
	PostLink   = 4
	Album      = 5
)
View Source
const (
	PrivacyPublic        = 1
	PrivacyFollowersOnly = 2
	PrivacyFollowingOnly = 3
	PrivacyNone          = 4
	PrivacyAllBut        = 5
	PrivacyFollowersBut  = 6
	PrivacyFollowingBut  = 7
	PrivacyNoneBut       = 8
)
View Source
const (
	// Token types
	AccessToken  = 0
	UserToken    = 1
	SessionToken = 2

	// Expiration times
	AccessTokenExpirationHours = 1
	UserTokenExpirationDays    = 30
)
View Source
const (
	// Roles
	RoleUser  = 0
	RoleAdmin = 1

	// Genders
	Male   = 1
	Female = 2
	Other  = 3

	// User statuses
	Single          = 1
	Married         = 2
	InARelationship = 3
	ItsComplicated  = 4
	OtherStatus     = 5

	// Recovery methods
	RecoveryNone      = 0
	RecoverByEMail    = 1
	RecoverByQuestion = 2
)
View Source
const (
	// Service code
	VideoServiceYoutube = 1
	VideoServiceVimeo   = 2

	// Services regexps
	VideoServiceYoutubeRegexp = "youtube.com/watch?(.*)v=(.*)"
	VideoServiceVimeoRegexp   = "vimeo.com/([0-9]+)"
)

Variables

View Source
var (
	AvailableLanguages = []string{"en", "es"}
)

Functions

func BlockUser

func BlockUser(from, to bson.ObjectId, conn interfaces.Saver) error

BlockUser blocks an user ("from" blocks "to")

func FollowUser

func FollowUser(from, to bson.ObjectId, conn interfaces.Saver) error

FollowUser follows an user ("from" follows "to")

func FollowedBy

func FollowedBy(to, from bson.ObjectId, conn interfaces.Conn) bool

FollowedBy checks if the user is followed by another user

func Follows

func Follows(from, to bson.ObjectId, conn interfaces.Conn) bool

Follows checks if the user follows another user

func GetLikesForPosts

func GetLikesForPosts(posts []bson.ObjectId, user bson.ObjectId, conn interfaces.Conn) map[bson.ObjectId]bool

GetLikesForPosts gets all user likes for a list of posts

func GetUsersData

func GetUsersData(ids []bson.ObjectId, user *User, conn interfaces.Conn) map[bson.ObjectId]map[string]interface{}

GetUserData retrieves basic data from users for responses

func IsValidPrivacyType

func IsValidPrivacyType(t PrivacyType) bool

IsValidPrivacyType determines if the given PrivacyType is valid or not

func SendNotification

func SendNotification(notificationType NotificationType, user *User, postID, userActionID bson.ObjectId, conn interfaces.Saver) error

SendNotification sends a new notification to the user

func UnblockUser

func UnblockUser(from, to bson.ObjectId, conn interfaces.Conn) error

UnblockUser unblocks an user ("from" unblocks "to")

func UnfollowUser

func UnfollowUser(from, to bson.ObjectId, conn interfaces.Conn) error

UnfollowUser unfollows an user ("from" unfollows "to")

func UserForDisplay

func UserForDisplay(u User, hasAccess, includeInfo bool) map[string]interface{}

UserForDisplay returns a displayable version of the user model based on the users permissions

func UserIsBlocked

func UserIsBlocked(from, to bson.ObjectId, conn interfaces.Conn) bool

UserIsBlocked returns if the user is blocked

Types

type Block

type Block Follow

Block model (same as follow)

type Comment

type Comment struct {
	ID      bson.ObjectId          `json:"id" bson:"_id"`
	UserID  bson.ObjectId          `json:"-" bson:"user_id"`
	User    map[string]interface{} `json:"user" bson:"-"`
	PostID  bson.ObjectId          `json:"post_id" bson:"post_id"`
	Created float64                `json:"created" bson:"created"`
	Message string                 `json:"message" bson:"message"`
}

func GetCommentsForPost

func GetCommentsForPost(post bson.ObjectId, user *User, n int, conn interfaces.Conn) []Comment

GetCommentsForPost returns up to N comments for the given post

func NewComment

func NewComment(user, post bson.ObjectId) *Comment

NewComment returns a new instance of Comment

func (*Comment) Save

func (c *Comment) Save(conn interfaces.Saver) error

Save inserts the Comment instance if it hasn't been created yet or updates it if it has

type Follow

type Follow struct {
	ID   bson.ObjectId `json:"id" bson:"_id"`
	From bson.ObjectId `json:"user_from" bson:"user_from"`
	To   bson.ObjectId `json:"user_to" bson:"user_to"`
	Time float64       `json:"time" bson:"time"`
}

Follow model

type FollowRequest

type FollowRequest struct {
	ID   bson.ObjectId `json:"id" bson:"_id"`
	From bson.ObjectId `json:"user_from" bson:"user_from"`
	To   bson.ObjectId `json:"user_to" bson:"user_to"`
	Msg  string        `json:"msg,omitempty" bson:"msg,omitempty"`
	Time float64       `json:"time" bson:"time"`
}

FollowRequest model

func (*FollowRequest) Remove

func (fr *FollowRequest) Remove(conn interfaces.Remover) error

Remove deletes the follow request instance

func (*FollowRequest) Save

func (fr *FollowRequest) Save(conn interfaces.Saver) error

Save inserts the FollowRequest instance if it hasn't been created yet or updates it if it has

type Gender

type Gender int

Gender represents an user gender

type Notification

type Notification struct {
	ID           bson.ObjectId          `json:"id" bson:"_id"`
	Type         NotificationType       `json:"notification_type" bson:"notification_type"`
	PostID       bson.ObjectId          `json:"post_id" bson:"post_id,omitempty"`
	User         bson.ObjectId          `json:"user_id" bson:"user_id"`
	UserActionID bson.ObjectId          `json:"-" bson:"user_action_id,omitempty"`
	UserAction   map[string]interface{} `json:"user_action" bson:"-"`
	Time         float64                `json:"time" bson:"time"`
	Read         bool                   `json:"read" bson:"read"`
}

Notification model

func (*Notification) Save

func (n *Notification) Save(conn interfaces.Saver) error

Save inserts the Notification instance if it hasn't been created yet or updates it if it has

type NotificationType

type NotificationType int

NotificationType is the type of the notification

type ObjectType

type ObjectType int

type Post

type Post struct {
	ID          bson.ObjectId          `json:"id" bson:"_id"`
	User        map[string]interface{} `json:"user" bson:"-"`
	UserID      bson.ObjectId          `json:"-" bson:"user_id"`
	Created     float64                `json:"created" bson:"created"`
	Type        ObjectType             `json:"post_type" bson:"post_type"`
	Likes       float64                `json:"likes" bson:"likes"`
	CommentsNum float64                `json:"comments_num" bson:"comments_num"`
	Comments    []Comment              `json:"comments" bson:"-"`
	Reported    float64                `json:"reported" bson:"reported"`
	Privacy     PrivacySettings        `json:"privacy" bson:"privacy"`
	Text        string                 `json:"text,omitempty" bson:"text,omitempty"`
	Liked       bool                   `json:"liked,omitempty" bson:"-"`

	// Video specific fields
	Service VideoService `json:"video_service,omitempty" bson:"video_service,omitempty"`
	VideoID string       `json:"video_id,omitempty" bson:"video_id,omitempty"`
	// Also used in link
	Title string `json:"title,omitempty" bson:"title,omitempty"`

	// Photo specific fields
	PhotoURL  string        `json:"photo_url,omitempty" bson:"photo_url,omitempty"`
	Caption   string        `json:"caption,omitempty" bson:"caption,omitempty"`
	AlbumID   bson.ObjectId `json:"album_id,omitempty" bson:"album_id,omitempty"`
	Thumbnail string        `json:"thumbnail,omitempty" bson:"thumbnail,omitempty"`

	// Link specific fields
	URL string `json:"link_url,omitempty" bson:"link_url,omitempty"`
}

Post model

func NewPost

func NewPost(t ObjectType, user *User) *Post

NewPost returns a new post instance

func (*Post) CanBeAccessedBy

func (p *Post) CanBeAccessedBy(u *User, conn interfaces.Conn) bool

CanBeAccessedBy determines if the current post can be accessed by the given user

func (*Post) Save

func (p *Post) Save(conn interfaces.Saver) error

Save inserts the Post instance if it hasn't been created yet or updates it if it has

type PostLike

type PostLike struct {
	ID     bson.ObjectId `json:"id" bson:"_id"`
	UserID bson.ObjectId `json:"user_id" bson:"user_id"`
	PostID bson.ObjectId `json:"post_id" bson:"post_id"`
}

PostLike model

type PrivacySettings

type PrivacySettings struct {
	Type  PrivacyType     `json:"privacy_type,omitempty" bson:"privacy_type"`
	Users []bson.ObjectId `json:"users,omitempty" bson:"users,omitempty"`
}

PrivacySettings model

func NewPrivacySettings

func NewPrivacySettings() PrivacySettings

NewPrivacySettings returns a new empty instance of PrivacySettings

type PrivacyType

type PrivacyType int

type RecoveryMethod

type RecoveryMethod int

RecoveryMethod represents the type of recovery for an account

type TimelineEntry

type TimelineEntry struct {
	ID       bson.ObjectId   `bson:"_id"`
	User     bson.ObjectId   `bson:"user_id"`
	Post     bson.ObjectId   `bson:"post_id"`
	PostUser bson.ObjectId   `bson:"post_user_id"`
	Liked    bool            `bson:"liked"`
	Comments []bson.ObjectId `bson:"comments"`
	Time     float64         `bson:"time"`
}

type Token

type Token struct {
	ID      bson.ObjectId `json:"id,omitempty" bson:"_id"`
	Type    TokenType     `json:"type" bson:"type"`
	Hash    string        `json:"hash" bson:"hash"`
	Expires float64       `json:"expires" bson:"expires"`
	UserID  bson.ObjectId `json:"user_id,omitempty" bson:"user_id,omitempty"`
}

Token represents a token which can be an access token, an user token or a session token

func (*Token) Remove

func (t *Token) Remove(conn interfaces.Remover) error

Remove removes the Token instance

func (*Token) Save

func (t *Token) Save(conn interfaces.Saver) error

Save inserts the Token instance if it hasn't been created yet or updates it if it has

type TokenType

type TokenType int

TokenType represents the type of the token

type User

type User struct {
	ID                    bson.ObjectId `json:"id,omitempty" bson:"_id"`
	Username              string        `json:"username" bson:"username"`
	UsernameLower         string        `json:"username_lower,omitempty" bson:"username_lower"`
	Password              string        `json:"-" bson:"password"`
	EMail                 string        `json:"-" bson:"email,omitempty"`
	PublicName            string        `json:"public_name" bson:"public_name,omitempty"`
	PrivateName           string        `json:"private_name" bson:"private_name,omitempty"`
	Role                  UserRole      `json:"role,omitempty" bson:"role"`
	PreferredLanguage     string        `json:"preferred_lang,omitempty" bson:"preferred_lang,omitempty"`
	Timezone              int           `json:"timezone,omitempty" bson:"timezone,omitempty"`
	Avatar                string        `json:"avatar" bson:"avatar,omitempty"`
	AvatarThumbnail       string        `json:"avatar_thumbnail" bson:"avatar_thumbnail,omitempty"`
	PublicAvatar          string        `json:"public_avatar" bson:"public_avatar,omitempty"`
	PublicAvatarThumbnail string        `json:"public_avatar_thumbnail" bson:"public_avatar_thumbnail,omitempty"`
	Active                bool          `json:"active,omitempty" bson:"active"`
	Info                  UserInfo      `json:"info,omitempty" bson:"info"`
	Settings              UserSettings  `json:"settings,omitempty" bson:"settings"`
}

User represents an application user

func NewUser

func NewUser() *User

NewUser returns a new User instance

func UserExists

func UserExists(conn interfaces.Conn, ID bson.ObjectId) *User

UserExists returns the user if exists or nil

func (*User) CheckEmail

func (u *User) CheckEmail(email string) bool

CheckEmail checks if the given email matches the current user email

func (*User) CheckPassword

func (u *User) CheckPassword(password string) bool

CheckPassword checks if the given password matches the current password hash

func (*User) Remove

func (u *User) Remove(conn interfaces.Remover) error

Remove deletes the user instance

func (*User) Save

func (u *User) Save(conn interfaces.Conn) error

Save inserts the User instance if it hasn't been created yet or updates it if it has

func (*User) SetEmail

func (u *User) SetEmail(email string) error

SetEmail sets the email of the user

func (*User) SetPassword

func (u *User) SetPassword(password string) error

SetPassword sets a new encrypted password for the user

type UserInfo

type UserInfo struct {
	Work      string     `json:"work,omitempty" bson:"work,omitempty"`
	Education string     `json:"education,omitempty" bson:"education,omitempty"`
	Hobbies   string     `json:"hobbies,omitempty" bson:"hobbies,omitempty"`
	Books     string     `json:"books,omitempty" bson:"books,omitempty"`
	Movies    string     `json:"movies,omitempty" bson:"movies,omitempty"`
	TV        string     `json:"tv,omitempty" bson:"tv,omitempty"`
	Gender    Gender     `json:"gender,omitempty" bson:"gender,omitempty"`
	Websites  []string   `json:"websites,omitempty" bson:"websites,omitempty"`
	Status    UserStatus `json:"status,omitempty" bson:"status,omitempty"`
	About     string     `json:"about,omitempty" bson:"about,omitempty"`
}

UserInfo stores all personal information about the user

type UserRole

type UserRole int

UserRole represents an user role

type UserSettings

type UserSettings struct {
	Invisible                   bool           `json:"invisible" bson:"invisible"`
	CanReceiveRequests          bool           `json:"can_receive_requests" bson:"can_receive_requests"`
	FollowApprovalRequired      bool           `json:"follow_approval_required" bson:"follow_approval_required"`
	DisplayAvatarBeforeApproval bool           `json:"display_avatar_before_approval" bson:"display_avatar_before_approval"`
	NotifyNewComment            bool           `json:"notify_new_comment" bson:"notify_new_comment"`
	NotifyNewCommentOthers      bool           `json:"notify_new_comment_others" bson:"notify_new_comment_others"`
	NotifyPostsInMyProfile      bool           `json:"notify_posts_in_my_profile" bson:"notify_posts_in_my_profile"`
	NotifyLikes                 bool           `json:"notify_likes" bson:"notify_likes"`
	AllowPostsInMyProfile       bool           `json:"allow_posts_in_my_profile" bson:"allow_posts_in_my_profile"`
	AllowCommentsInPosts        bool           `json:"allow_comments_in_posts" bson:"allow_comments_in_posts"`
	DisplayInfoFollowersOnly    bool           `json:"display_info_followers_only" bson:"display_info_followers_only"`
	PasswordRecoveryMethod      RecoveryMethod `json:"recovery_method" bson:"recovery_method"`
	RecoveryQuestion            string         `json:"recovery_question" bson:"recovery_question"`
	RecoveryAnswer              string         `json:"recovery_answer" bson:"recovery_answer"`
	// If this is true DefaultStatusPrivacy will override all the other settings
	OverrideDefaultPrivacy bool            `json:"override_default_privacy" bson:"override_default_privacy"`
	DefaultStatusPrivacy   PrivacySettings `json:"default_status_privacy" bson:"default_status_privacy"`
	DefaultVideoPrivacy    PrivacySettings `json:"default_video_privacy" bson:"default_video_privacy"`
	DefaultPhotoPrivacy    PrivacySettings `json:"default_photo_privacy" bson:"default_photo_privacy"`
	DefaultLinkPrivacy     PrivacySettings `json:"default_link_privacy" bson:"default_link_privacy"`
	DefaultAlbumPrivacy    PrivacySettings `json:"default_album_privacy" bson:"default_album_privacy"`
}

UserSettings stores the user preferences

func (UserSettings) GetPrivacySettings

func (us UserSettings) GetPrivacySettings(objectType ObjectType) PrivacySettings

GetPrivacySettings returns the privacy settings of the user for the given object type

type UserStatus

type UserStatus int

UserStatus represents the civil status of the user

type VideoService

type VideoService int

Jump to

Keyboard shortcuts

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