Thanks to visit codestin.com
Credit goes to github.com

Skip to content

add sys_msg_for_subject #77

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/logic/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ func (self MessageLogic) FindSysMsgsByUid(ctx context.Context, uid int, paginato
// 评论ID
cidSet := set.New(set.NonThreadSafe)
uidSet := set.New(set.NonThreadSafe)
// subject id
sidSet := set.New(set.NonThreadSafe)

ids := make([]int, 0, len(messages))
for _, message := range messages {
Expand Down Expand Up @@ -234,6 +236,9 @@ func (self MessageLogic) FindSysMsgsByUid(ctx context.Context, uid int, paginato
case model.TypeBook:
bookIdSet.Add(objid)
}
case model.MsgtypeSubjectContribute:
articleIdSet.Add(objid)
sidSet.Add(int(ext["sid"].(float64)))
}
if val, ok := ext["cid"]; ok {
cidSet.Add(int(val.(float64)))
Expand All @@ -253,6 +258,7 @@ func (self MessageLogic) FindSysMsgsByUid(ctx context.Context, uid int, paginato
wikiMap := DefaultWiki.findByIds(set.IntSlice(wikiIdSet))
projectMap := DefaultProject.findByIds(set.IntSlice(pidSet))
bookMap := DefaultGoBook.findByIds(set.IntSlice(bookIdSet))
subjectMap := DefaultSubject.findByIds(set.IntSlice(sidSet))

result := make([]map[string]interface{}, len(messages))
for i, message := range messages {
Expand Down Expand Up @@ -368,6 +374,16 @@ func (self MessageLogic) FindSysMsgsByUid(ctx context.Context, uid int, paginato
}

title += "时提到了你:"

case model.MsgtypeSubjectContribute:
subject := subjectMap[int(ext["sid"].(float64))]
article := articleMap[objid]
objTitle = article.Title
objUrl = "/articles/" + strconv.Itoa(article.Id)
title += "收录了新文章"
tmpMap["sprefix"] = "的专栏"
tmpMap["surl"] = "/subject/" + strconv.Itoa(subject.Id)
tmpMap["stitle"] = subject.Name
}
tmpMap["objtitle"] = objTitle
tmpMap["objurl"] = objUrl
Expand Down
37 changes: 36 additions & 1 deletion src/logic/subject.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,20 @@ func (self SubjectLogic) FindOne(ctx context.Context, sid int) *model.Subject {
return subject
}

func (self SubjectLogic) findByIds(ids []int) map[int]*model.Subject {
if len(ids) == 0 {
return nil
}

subjects := make(map[int]*model.Subject)
err := MasterDB.In("id", ids).Find(&subjects)
if err != nil {
return nil
}

return subjects
}

func (self SubjectLogic) FindArticles(ctx context.Context, sid int, paginator *Paginator, orderBy string) []*model.Article {
objLog := GetLogger(ctx)

Expand Down Expand Up @@ -138,6 +152,12 @@ func (self SubjectLogic) FindFollowers(ctx context.Context, sid int) []*model.Su
return followers
}

func (self SubjectLogic) findFollowersBySid(sid int) []*model.SubjectFollower {
followers := make([]*model.SubjectFollower, 0)
MasterDB.Where("sid=?", sid).Find(&followers)
return followers
}

// FindFollowerTotal 专栏关注的用户数
func (self SubjectLogic) FindFollowerTotal(ctx context.Context, sid int) int64 {
objLog := GetLogger(ctx)
Expand Down Expand Up @@ -241,11 +261,26 @@ func (self SubjectLogic) Contribute(ctx context.Context, me *model.Me, sid, arti
return errors.New("投稿失败:" + err.Error())
}

session.Commit()
if err := session.Commit(); err == nil {
// 成功,发送站内系统消息给关注者
go self.sendMsgForFollower(ctx, subject, sid, articleId)
}

return nil
}

// sendMsgForFollower 专栏投稿发送消息给关注者
func (self SubjectLogic) sendMsgForFollower(ctx context.Context, subject *model.Subject, sid, articleId int) {
followers := self.findFollowersBySid(sid)
for _, f := range followers {
DefaultMessage.SendSystemMsgTo(ctx, f.Uid, model.MsgtypeSubjectContribute, map[string]interface{}{
"uid": subject.Uid,
"objid": articleId,
"sid": sid,
})
}
}

// RemoveContribute 删除投稿
func (self SubjectLogic) RemoveContribute(ctx context.Context, sid, articleId int) error {
objLog := GetLogger(ctx)
Expand Down
16 changes: 8 additions & 8 deletions src/logic/uploader.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ func (this *UploaderLogic) uploadLocalFile(localFile, key string) (err error) {

var ret io.PutRet
var extra = &io.PutExtra{
// Params: params,
// MimeType: mieType,
// Crc32: crc32,
// CheckCrc: CheckCrc,
// Params: params,
// MimeType: mieType,
// Crc32: crc32,
// CheckCrc: CheckCrc,
}

// ret 变量用于存取返回的信息,详情见 io.PutRet
Expand All @@ -119,10 +119,10 @@ func (this *UploaderLogic) uploadMemoryFile(r gio.Reader, key string, size int)

var ret io.PutRet
var extra = &io.PutExtra{
// Params: params,
// MimeType: mieType,
// Crc32: crc32,
// CheckCrc: CheckCrc,
// Params: params,
// MimeType: mieType,
// Crc32: crc32,
// CheckCrc: CheckCrc,
}

// ret 变量用于存取返回的信息,详情见 io.PutRet
Expand Down
2 changes: 2 additions & 0 deletions src/model/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ const (

MsgtypeAtMe = 10 // 评论 @提到我
MsgtypePublishAtMe = 11 // 发布时提到我

MsgtypeSubjectContribute = 12 //专栏投稿
)

// 系统消息
Expand Down
2 changes: 1 addition & 1 deletion template/messages/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<li>
<h3>
<a href="/user/{{.user.Username}}" title="{{.user.Username}}"><img src="{{gravatar .user.Avatar .user.Email 48 $.is_https}}" width="48" height="48" alt="{{.user.Username}}"></a>
<span class="user">{{if eq $.msgtype "outbox"}}你对 {{end}}<a href="/user/{{.user.Username}}" title="{{.user.Username}}">{{.user.Username}}</a> {{if eq $.msgtype "outbox"}}说:{{else}}{{.title}}{{end}}</span>
<span class="user">{{if eq $.msgtype "outbox"}}你对 {{end}}<a href="/user/{{.user.Username}}" title="{{.user.Username}}">{{.user.Username}}</a> {{if eq $.msgtype "outbox"}}说:{{else}}{{if .stitle}}{{.sprefix}}<a href="{{.surl}}" title="{{.stitle}}">{{.stitle}}</a>{{end}}{{.title}}{{end}}</span>
{{if .objtitle}}<a href="{{.objurl}}" title="{{.objtitle}}">{{.objtitle}}</a>{{end}}
{{if eq .hasread "未读"}}
{{if eq $.msgtype "outbox"}}
Expand Down