// These notes are for me, don't worry about it too much ^_^
/*
"You received a friend invite from {user}"
"{x}{mentioned you on}{user}{'s profile}"
"{x}{mentioned you in}{topic}"
"{x}{likes}{you}"
"{x}{liked}{your topic}{topic}"
"{x}{liked}{your post on}{user}{'s profile}"todo
"{x}{liked}{your post in}{topic}"
"{x}{replied to}{your post in}{topic}"todo
"{x}{replied to}{topic}"
"{x}{replied to}{your topic}{topic}"
"{x}{created a new topic}{topic}"
*/
funcBuildAlert(asidint,eventstring,elementTypestring,actorIDint,targetUserIDint,elementIDint,userUser/* The current user */)(string,error){
vartargetUser*User
actor,err:=Users.Get(actorID)
iferr!=nil{
return"",errors.New("Unable to find the actor")
}
/*ifelementType!="forum"{
targetUser,err=users.Get(targetUser_id)
iferr!=nil{
LocalErrorJS("Unable to find the target user",w,r)
return
}
}*/
ifevent=="friend_invite"{
return`{"msg":"You received a friend invite from {0}","sub":["`+actor.Name+`"],"path":"`+actor.Link+`","avatar":"`+strings.Replace(actor.Avatar,"/","\\/",-1)+`","asid":"`+strconv.Itoa(asid)+`"}`,nil
}
varact,postAct,url,areastring
varstartFrag,endFragstring
switchelementType{
case"forum":
ifevent=="reply"{
act="created a new topic"
topic,err:=Topics.Get(elementID)
iferr!=nil{
DebugLogf("Unable to find linked topic %d",elementID)
return"",errors.New("Unable to find the linked topic")
}
url=topic.Link
area=topic.Title
// Store the forum ID in the targetUser column instead of making a new one? o.O
// Add an additional column for extra information later on when we add the ability to link directly to posts. We don't need the forum data for now...
}else{
act="did something in a forum"
}
case"topic":
topic,err:=Topics.Get(elementID)
iferr!=nil{
DebugLogf("Unable to find linked topic %d",elementID)
return"",errors.New("Unable to find the linked topic")
}
url=topic.Link
area=topic.Title
iftargetUserID==user.ID{
postAct=" your topic"
}
case"user":
targetUser,err=Users.Get(elementID)
iferr!=nil{
DebugLogf("Unable to find target user %d",elementID)
return"",errors.New("Unable to find the target user")
}
area=targetUser.Name
endFrag="'s profile"
url=targetUser.Link
case"post":
topic,err:=TopicByReplyID(elementID)
iferr!=nil{
return"",errors.New("Unable to find the linked reply or parent topic")