model

package
v0.0.0-...-1dc691d Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2020 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BanUser

func BanUser(u *uexky.Uexky, postID string) error

BanUser ...

func BlockPost

func BlockPost(u *uexky.Uexky, postID string) error

BlockPost ...

func BlockThread

func BlockThread(u *uexky.Uexky, threadID string) error

BlockThread ...

func CountThreads

func CountThreads(u *uexky.Uexky, selector bson.M) (int, error)

CountThreads ...

func EditTags

func EditTags(u *uexky.Uexky, threadID, mainTag string, subTags []string) error

EditTags ...

func FindThreads

func FindThreads(u *uexky.Uexky, selector bson.M, sq *SliceQuery) ([]*Thread, *SliceInfo, error)

FindThreads ...

func GetNotification

func GetNotification(
	u *uexky.Uexky, t NotiType, sq *SliceQuery,
) ([]*Notification, *SliceInfo, error)

GetNotification ...

func GetThreadSlice

func GetThreadSlice(u *uexky.Uexky, tags []string, sq *SliceQuery) (
	[]*Thread, *SliceInfo, error,
)

GetThreadSlice ...

func GetUnreadNotificationCount

func GetUnreadNotificationCount(u *uexky.Uexky, t NotiType) (int, error)

GetUnreadNotificationCount ...

func LockThread

func LockThread(u *uexky.Uexky, threadID string) error

LockThread ...

func SendSystemNotification

func SendSystemNotification(u *uexky.Uexky, title, content string) error

SendSystemNotification Send a system notification

func TriggerNotifForPost

func TriggerNotifForPost(
	u *uexky.Uexky, thread *Thread, post *Post, quotes []*Post,
) error

TriggerNotifForPost ...

func UpsertTags

func UpsertTags(u *uexky.Uexky, mainTag string, tagStrings []string) error

UpsertTags after insert thread...

Types

type AuthInfo

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

AuthInfo impl uexky.Auth

func NewUexkyAuth

func NewUexkyAuth(uexky *uexky.Uexky, email string) *AuthInfo

NewUexkyAuth make a new AuthInfo and add to Uexky

func (*AuthInfo) CheckPriority

func (ai *AuthInfo) CheckPriority(action, target string) (bool, error)

CheckPriority ...

func (*AuthInfo) Email

func (ai *AuthInfo) Email() string

Email ...

func (*AuthInfo) GetUser

func (ai *AuthInfo) GetUser() (*User, error)

GetUser who signed in

func (*AuthInfo) IsSignedIn

func (ai *AuthInfo) IsSignedIn() bool

IsSignedIn ...

func (*AuthInfo) RequireSignedIn

func (ai *AuthInfo) RequireSignedIn() error

RequireSignedIn ...

type NotiType

type NotiType string

NotiType ...

const (
	NotiTypeSystem  NotiType = "system"
	NotiTypeReplied NotiType = "replied"
	NotiTypeQuoted  NotiType = "quoted"
)

NotifTypes

type Notification

type Notification struct {
	// base info
	ID          string        `bson:"id"`
	Type        NotiType      `bson:"type"`
	SendTo      bson.ObjectId `bson:"send_to,omitempty"`
	SendToGroup UserGroup     `bson:"send_to_group,omitempty"`
	EventTime   time.Time     `bson:"event_time"`
	HasRead     bool          `bson:"-"`

	System  *SystemNotiContent  `bson:"system,omitempty"`
	Replied *RepliedNotiContent `bson:"replied,omitempty"`
	Quoted  *QuotedNotiContent  `bson:"quoted,omitempty"`
}

Notification for save notification in DB

type Post

type Post struct {
	PostBase
	ThreadID   string    `bson:"thread_id"`
	Anonymous  bool      `bson:"anonymous"`
	Author     string    `bson:"author"`
	CreateTime time.Time `bson:"create_time"`
	Blocked    bool      `bson:"blocked"`
	Index      int       `bson:"-"`
	Quotes     []string  `bson:"quotes,omitempty"`
	Content    string    `bson:"content"`
}

Post ...

func FindPostByID

func FindPostByID(u *uexky.Uexky, ID string) (*Post, error)

FindPostByID ...

func NewPost

func NewPost(u *uexky.Uexky, input *PostInput) (*Post, error)

NewPost ...

func (*Post) QuoteCount

func (p *Post) QuoteCount(u *uexky.Uexky) (int, error)

QuoteCount ...

func (*Post) QuotePosts

func (p *Post) QuotePosts(u *uexky.Uexky) ([]*Post, error)

QuotePosts ...

type PostBase

type PostBase struct {
	ObjectID bson.ObjectId `bson:"_id"`
	ID       string        `bson:"id"`
	UserID   bson.ObjectId `bson:"user_id"`
}

PostBase ...

type PostInput

type PostInput struct {
	ThreadID  string
	Anonymous bool
	Content   string
	Quotes    *[]string
}

PostInput ...

func (*PostInput) ParsePost

func (pi *PostInput) ParsePost(u *uexky.Uexky, user *User) (
	*Post, *Thread, []*Post, error,
)

ParsePost ...

type QuotedNotiContent

type QuotedNotiContent struct {
	ThreadID     string        `bson:"thread_id"`
	PostID       string        `bson:"post_id"`
	QuotedPostID string        `bson:"quoted_post_id"`
	Quoter       string        `bson:"quoter"`
	QuoterID     bson.ObjectId `bson:"quoter_id"`
}

QuotedNotiContent ...

type RepliedNotiContent

type RepliedNotiContent struct {
	ThreadID   string          `bson:"thread_id"`
	Repliers   []string        `bson:"repliers"`
	ReplierIDs []bson.ObjectId `bson:"replier_ids"`
}

RepliedNotiContent ...

type RoleType

type RoleType string

RoleType ...

const (
	Normal     RoleType = ""
	Banned     RoleType = "banned"
	TagAdmin   RoleType = "tag_admin"
	SuperAdmin RoleType = "super_admin"
)

Roles

type SliceInfo

type SliceInfo struct {
	FirstCursor string
	LastCursor  string
	HasPrev     bool
	HasNext     bool
}

SliceInfo ...

type SliceQuery

type SliceQuery struct {
	GT    string
	LT    string
	Limit int
}

SliceQuery ...

func (*SliceQuery) Find

func (sq *SliceQuery) Find(
	u *uexky.Uexky, collection, sort string,
	queryObj bson.M, result interface{},
) error

Find ...

func (*SliceQuery) GenQueryByObjectID

func (sq *SliceQuery) GenQueryByObjectID() (bson.M, error)

GenQueryByObjectID ...

func (*SliceQuery) GenQueryByTime

func (sq *SliceQuery) GenQueryByTime(field string) (bson.M, error)

GenQueryByTime in milliSeconds

type SystemNotiContent

type SystemNotiContent struct {
	Title   string `bson:"title"`
	Content string `bson:"content"`
}

SystemNotiContent ...

type Tag

type Tag struct {
	ObjectID    bson.ObjectId `bson:"_id"`
	Name        string        `bson:"name"`
	MainTags    []string      `bson:"main_tags"`
	UpdatedTime time.Time     `bson:"updated_time"`
}

Tag ...

type TagTree

type TagTree struct {
	Nodes []*TagTreeNode `json:"nodes"`
}

TagTree ...

func GetTagTree

func GetTagTree(u *uexky.Uexky, query string) (*TagTree, error)

GetTagTree ...

type TagTreeNode

type TagTreeNode struct {
	MainTag string   `json:"main_tag"`
	SubTags []string `json:"sub_tags"`
}

TagTreeNode ...

type Thread

type Thread struct {
	ObjectID   bson.ObjectId `bson:"_id"` // not display in front
	ID         string        `bson:"id"`
	Anonymous  bool          `bson:"anonymous"`
	Author     string        `bson:"author"`
	UserID     bson.ObjectId `bson:"user_id"` // not display in front
	MainTag    string        `bson:"main_tag"`
	SubTags    []string      `bson:"sub_tags"`
	Tags       []string      `bson:"tags"`
	Title      string        `bson:"title"`
	Content    string        `bson:"content"`
	Blocked    bool          `bson:"blocked"`
	Banned     bool          `bson:"banned"`
	CreateTime time.Time     `bson:"created_time"`
	UpdateTime time.Time     `bson:"update_time"`
	Posts      []PostBase    `bson:"posts"`
}

Thread ...

func FindThread

func FindThread(u *uexky.Uexky, selector interface{}) (*Thread, error)

FindThread ...

func FindThreadByID

func FindThreadByID(u *uexky.Uexky, id string) (*Thread, error)

FindThreadByID ...

func NewThread

func NewThread(u *uexky.Uexky, input *ThreadInput) (*Thread, error)

NewThread init new thread and insert to db

func (*Thread) GetReplies

func (t *Thread) GetReplies(
	u *uexky.Uexky, sq *SliceQuery,
) ([]*Post, *SliceInfo, error)

GetReplies ...

func (*Thread) ReplyCount

func (t *Thread) ReplyCount() int

ReplyCount ...

type ThreadInput

type ThreadInput struct {
	Anonymous bool
	Content   string
	MainTag   string
	SubTags   *[]string
	Title     *string
}

ThreadInput ...

func (*ThreadInput) ParseThead

func (ti *ThreadInput) ParseThead(u *uexky.Uexky, user *User) (*Thread, error)

ParseThead ...

type User

type User struct {
	ID           bson.ObjectId `bson:"_id"`
	Email        string        `bson:"email"`
	Name         string        `bson:"name"`
	Tags         []string      `bson:"tags"`
	ReadNotiTime struct {
		System  time.Time `bson:"system"`
		Replied time.Time `bson:"replied"`
		Quoted  time.Time `bson:"quoted"`
	} `bson:"read_noti_time"`
	Role struct {
		Type  RoleType `bson:"type"`
		Range []string `bson:"range"`
	} `bson:"role"`
}

User for uexky

func GetSignedInUser

func GetSignedInUser(u *uexky.Uexky) (*User, error)

GetSignedInUser in uexky

func GetUserByEmail

func GetUserByEmail(u *uexky.Uexky, email string) (*User, error)

GetUserByEmail ...

func (*User) AddSubbedTags

func (a *User) AddSubbedTags(u *uexky.Uexky, tags []string) error

AddSubbedTags ...

func (*User) AnonymousID

func (a *User) AnonymousID(u *uexky.Uexky, threadID string, new bool) (string, error)

AnonymousID ...

func (*User) CheckPriority

func (a *User) CheckPriority(
	u *uexky.Uexky, action, target string,
) (bool, error)

CheckPriority ...

func (*User) DelSubbedTags

func (a *User) DelSubbedTags(u *uexky.Uexky, tags []string) error

DelSubbedTags ...

func (*User) SetName

func (a *User) SetName(u *uexky.Uexky, name string) error

SetName ...

func (User) String

func (a User) String() string

String ...

func (*User) SyncTags

func (a *User) SyncTags(u *uexky.Uexky, tags []string) error

SyncTags ...

type UserGroup

type UserGroup string

UserGroup ...

const (
	AllUser UserGroup = "all"
)

UserGroups

Jump to

Keyboard shortcuts

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