funcbuild_alert(eventstring,elementTypestring,actor_idint,targetUser_idint,elementIDint,userUser/* The current user */)(string,error){
vartargetUser*User
actor,err:=users.CascadeGet(actor_id)
iferr!=nil{
return"",errors.New("Unable to find the actor")
}
/*ifelementType!="forum"{
targetUser,err=users.CascadeGet(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":"\/user\/`+strconv.Itoa(actor.ID)+`","avatar":"`+strings.Replace(actor.Avatar,"/","\\/",-1)+`"}`,nil
}
varact,post_act,url,areastring
varstart_frag,end_fragstring
switch(elementType){
case"forum":
ifevent=="reply"{
act="created a new topic"
topic,err:=topics.CascadeGet(elementID)
iferr!=nil{
return"",errors.New("Unable to find the linked topic")
}
url=build_topic_url(elementID)
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.CascadeGet(elementID)
iferr!=nil{
return"",errors.New("Unable to find the linked topic")
}
url=build_topic_url(elementID)
area=topic.Title
iftargetUser_id==user.ID{
post_act=" your topic"
}
case"user":
targetUser,err=users.CascadeGet(elementID)
iferr!=nil{
return"",errors.New("Unable to find the target user")
}
area=targetUser.Name
end_frag="'s profile"
url=build_profile_url(elementID)
case"post":
topic,err:=get_topic_by_reply(elementID)
iferr!=nil{
return"",errors.New("Unable to find the linked reply or parent topic")