Documentation ¶
Index ¶
- Constants
- Variables
- func BlockUser(from, to bson.ObjectId, conn interfaces.Saver) error
- func FollowUser(from, to bson.ObjectId, conn interfaces.Saver) error
- func FollowedBy(to, from bson.ObjectId, conn interfaces.Conn) bool
- func Follows(from, to bson.ObjectId, conn interfaces.Conn) bool
- func GetLikesForPosts(posts []bson.ObjectId, user bson.ObjectId, conn interfaces.Conn) map[bson.ObjectId]bool
- func GetUsersData(ids []bson.ObjectId, user *User, conn interfaces.Conn) map[bson.ObjectId]map[string]interface{}
- func IsValidPrivacyType(t PrivacyType) bool
- func SendNotification(notificationType NotificationType, user *User, ...) error
- func UnblockUser(from, to bson.ObjectId, conn interfaces.Conn) error
- func UnfollowUser(from, to bson.ObjectId, conn interfaces.Conn) error
- func UserForDisplay(u User, hasAccess, includeInfo bool) map[string]interface{}
- func UserIsBlocked(from, to bson.ObjectId, conn interfaces.Conn) bool
- type Block
- type Comment
- type Follow
- type FollowRequest
- type Gender
- type Notification
- type NotificationType
- type ObjectType
- type Post
- type PostLike
- type PrivacySettings
- type PrivacyType
- type RecoveryMethod
- type TimelineEntry
- type Token
- type TokenType
- type User
- type UserInfo
- type UserRole
- type UserSettings
- type UserStatus
- type VideoService
Constants ¶
const ( NotificationFollowRequest = 1 NotificationFollowRequestAccepted = 2 NotificationFollowed = 3 NotificationPostLiked = 4 NotificationPostCommented = 5 NotificationPostOnMyWall = 6 )
const ( // Post types PostStatus = 1 PostPhoto = 2 PostVideo = 3 PostLink = 4 Album = 5 )
const ( PrivacyPublic = 1 PrivacyFollowersOnly = 2 PrivacyFollowingOnly = 3 PrivacyNone = 4 PrivacyAllBut = 5 PrivacyFollowersBut = 6 PrivacyFollowingBut = 7 PrivacyNoneBut = 8 )
const ( // Token types AccessToken = 0 UserToken = 1 SessionToken = 2 // Expiration times AccessTokenExpirationHours = 1 UserTokenExpirationDays = 30 )
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 )
const ( // Service code VideoServiceYoutube = 1 VideoServiceVimeo = 2 // Services regexps VideoServiceYoutubeRegexp = "youtube.com/watch?(.*)v=(.*)" VideoServiceVimeoRegexp = "vimeo.com/([0-9]+)" )
Variables ¶
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 ¶
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 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 ¶
GetCommentsForPost returns up to N comments for the given post
func NewComment ¶
NewComment returns a new instance of Comment
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 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 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 (*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
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 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
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 UserExists ¶
func UserExists(conn interfaces.Conn, ID bson.ObjectId) *User
UserExists returns the user if exists or nil
func (*User) CheckEmail ¶
CheckEmail checks if the given email matches the current user email
func (*User) CheckPassword ¶
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) SetPassword ¶
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 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 VideoService ¶
type VideoService int