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

Skip to content

Commit 39eecd2

Browse files
committed
评论@和表情(未完成)
1 parent 1f04a6f commit 39eecd2

File tree

16 files changed

+265
-4
lines changed

16 files changed

+265
-4
lines changed

websites/code/studygolang/src/controller/ajax.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,21 @@ func NewestUserHandler(rw http.ResponseWriter, req *http.Request) {
255255
fmt.Fprint(rw, `{"ok": 1, "data":`+string(buf)+`}`)
256256
}
257257

258+
// 评论或回复 @ 某人 suggest
259+
// uri: /at/users.json
260+
func AtUsersHandler(rw http.ResponseWriter, req *http.Request) {
261+
term := req.FormValue("term")
262+
usernames := service.GetUserMentions(term, 10)
263+
buf, err := json.Marshal(usernames)
264+
if err != nil {
265+
logger.Errorln("[AtUsersHandler] json.marshal error:", err)
266+
fmt.Fprint(rw, `[]`)
267+
return
268+
}
269+
270+
fmt.Fprint(rw, string(buf))
271+
}
272+
258273
const maxImageSize = 5 << 20 // 5M
259274

260275
func UploadImageHandler(rw http.ResponseWriter, req *http.Request) {

websites/code/studygolang/src/model/user.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ func (this *UserLogin) Set(clause string, args ...interface{}) *UserLogin {
8181
return this
8282
}
8383

84+
// 为了支持连写
85+
func (this *UserLogin) Limit(limit string) *UserLogin {
86+
this.Dao.Limit(limit)
87+
return this
88+
}
89+
8490
func (this *UserLogin) prepareInsertData() {
8591
this.columns = []string{"uid", "username", "passwd", "email", "login_time", "passcode"}
8692
this.GenMd5Passwd("")

websites/code/studygolang/src/server/studygolang/router.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ func initRouter() *mux.Router {
127127
router.HandleFunc("/users/newest.json", NewestUserHandler)
128128
// 最新晨读
129129
router.HandleFunc("/readings/recent.json", RecentReadingHandler)
130+
// @ 某人 suggest(登录用户才能@)
131+
router.HandleFunc("/at/users.json", AtUsersHandler).AppendFilterChain(loginFilterChain)
130132

131133
// 文件上传(图片)
132134
router.HandleFunc("/upload/image.json", UploadImageHandler).AppendFilterChain(loginFilterChain)

websites/code/studygolang/src/service/message.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ func SendSystemMsgTo(to, msgtype int, ext map[string]interface{}) bool {
4646
to = getResourceOwner(objid)
4747
case model.TYPE_WIKI:
4848
to = getWikiOwner(objid)
49+
case model.TYPE_PROJECT:
50+
to = getProjectOwner(objid)
4951
}
5052
}
5153

websites/code/studygolang/src/service/project.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,19 @@ func ProjectsTotal() (total int) {
133133
return
134134
}
135135

136+
// 通过objid获得 project 的所有者
137+
func getProjectOwner(id int) int {
138+
project := model.NewOpenProject()
139+
err := project.Where("id=" + strconv.Itoa(id)).Find()
140+
if err != nil {
141+
logger.Errorln("project service getProjectOwner Error:", err)
142+
return 0
143+
}
144+
145+
user := FindUserByUsername(project.Username)
146+
return user.Uid
147+
}
148+
136149
// 项目评论
137150
type ProjectComment struct{}
138151

websites/code/studygolang/src/service/user.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,23 @@ func FindUsersByPage(conds map[string]string, curPage, limit int) ([]*model.User
265265
return userList, total
266266
}
267267

268+
// 获取 @ 的 suggest 列表
269+
func GetUserMentions(term string, limit int) []string {
270+
term = "%" + term + "%"
271+
userLogins, err := model.NewUserLogin().Where("username like ?", term).Limit(strconv.Itoa(limit)).FindAll("username")
272+
if err != nil {
273+
logger.Errorln("user service GetUserMentions Error:", err)
274+
return []string{}
275+
}
276+
277+
usernames := make([]string, len(userLogins))
278+
for i, userLogin := range userLogins {
279+
usernames[i] = userLogin.Username
280+
}
281+
282+
return usernames
283+
}
284+
268285
var (
269286
ErrUsername = errors.New("用户名不存在")
270287
ErrPasswd = errors.New("密码错误")

websites/code/studygolang/static/css/jquery.atwho.min.css

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

websites/code/studygolang/static/css/main.css

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,4 +205,7 @@ html, body { background: #F2F2F2; font-family: "Helvetica Neue", Helvetica, Aria
205205
.line {border-bottom: 1px dotted #d8d8d8;line-height:1px;margin:0 30px;}
206206

207207
/* validate css */
208-
label.error {color:red;}
208+
label.error {color:red;}
209+
210+
/*emoji*/
211+
.emoji {width:20px;height:20px;vertical-align: middle;}

websites/code/studygolang/static/js/comment.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,20 @@
4949
$('.page-comment .words ul').html(content);
5050
$('.page-comment .words').removeClass('hide');
5151
}
52+
53+
emojify.setConfig({
54+
// emojify_tag_type : 'span',
55+
only_crawl_id : null,
56+
img_dir : 'http://www.emoji-cheat-sheet.com/graphics/emojis',
57+
ignored_tags : { //忽略以下几种标签内的emoji识别
58+
'SCRIPT' : 1,
59+
'TEXTAREA': 1,
60+
'A' : 1,
61+
'PRE' : 1,
62+
'CODE' : 1
63+
}
64+
});
65+
emojify.run($('.page-comment .words ul').get(0));
5266
} else {
5367
comTip("评论加载失败");
5468
}
@@ -232,5 +246,16 @@
232246
}
233247
});
234248
}
249+
250+
// @ 本站其他人
251+
$('.page-comment #commentForm textarea').atwho({
252+
at: "@",
253+
data: "/at/users.json"
254+
}).atwho({
255+
at: ":",
256+
data: window.emojis,
257+
tpl:"<li data-value='${key}'><img src='http://www.emoji-cheat-sheet.com/graphics/emojis/${name}.png' height='20' width='20' /> ${name}</li>"
258+
});
259+
235260
});
236261
}).call(this)
Lines changed: 83 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,85 @@
11
// emoji表情 http://www.emoji-cheat-sheet.com/
2-
window.emojis = ["plus1","ok_hand","sleepy","smile","clap","heart","octopus","six_pointed_star","oden","office","ok","ok_woman","older_man","skull","smiley","smirk","smoking","snake","snowman","sob","soccer","point_down","point_left","point_right","point_up","point_up_2","a","ab","airplane","alien","ambulance","angel","anger","angry","apple","aquarius","aries","arrow_backward","arrow_down","ski","person_with_blond_hair","phone","pig","pill","pisces","arrow_forward","arrow_left","arrow_lower_left","arrow_lower_right","arrow_right","arrow_up","arrow_upper_left","arrow_upper_right","art","astonished","atm","b","baby","baby_chick","baby_symbol","balloon","bamboo","bank","barber","baseball","basketball","bath","bear","beer","beers","beginner","bell","bento","bike","bikini","bird","birthday","black_square","blue_car","blue_heart","blush","boar","boat","bomb","book","boot","bouquet","bow","bowtie","boy","bread","briefcase","broken_heart","bug","bulb","slot_machine","bullettrain_front","bullettrain_side","bus","busstop","cactus","cake","calling","camel","camera","cancer","capricorn","car","cat","cd","chart","checkered_flag","cherry_blossom","chicken","christmas_tree","church","cinema","city_sunrise","city_sunset","clapper","clock1","clock10","clock11","clock12","clock2","clock3","clock4","clock5","clock6","clock7","clock8","clock9","closed_umbrella","cloud","clubs","cn","cocktail","coffee","cold_sweat","computer","confounded","congratulations","construction","construction_worker","convenience_store","cool","cop","copyright","couple","couple_with_heart","couplekiss","cow","crossed_flags","crown","cry","cupid","currency_exchange","curry","cyclone","dancer","dancers","dango","dart","dash","de","department_store","diamonds","disappointed","dog","dolls","dolphin","dress","dvd","ear","ear_of_rice","egg","eggplant","egplant","eight_pointed_black_star","eight_spoked_asterisk","elephant","email","es","european_castle","exclamation","eyes","factory","fallen_leaf","fast_forward","fax","fearful","feelsgood","feet","ferris_wheel","finnadie","fire","fire_engine","fireworks","fish","fist","flags","flushed","football","fork_and_knife","fountain","four_leaf_clover","fr","fries","frog","fuelpump","gb","gem","gemini","ghost","gift","gift_heart","girl","goberserk","godmode","golf","green_heart","grey_exclamation","grey_question","-1","0","1","109","2","3","4","5","6","7","8","8ball","9","grin","guardsman","guitar","gun","haircut","hamburger","hammer","hamster","hand","handbag","hankey","hash","headphones","heart_decoration","heart_eyes","heartbeat","heartpulse","hearts","hibiscus","high_heel","horse","hospital","hotel","hotsprings","house","hurtrealbad","icecream","id","ideograph_advantage","imp","information_desk_person","iphone","it","jack_o_lantern","japanese_castle","joy","jp","key","kimono","kiss","kissing_face","kissing_heart","koala","koko","kr","leaves","leo","libra","lips","lipstick","lock","loop","loudspeaker","love_hotel","mag","mahjong","mailbox","man","man_with_gua_pi_mao","man_with_turban","maple_leaf","mask","massage","mega","memo","mens","metal","metro","microphone","minidisc","mobile_phone_off","moneybag","monkey","monkey_face","moon","mortar_board","mount_fuji","mouse","movie_camera","muscle","musical_note","nail_care","necktie","new","no_good","no_smoking","nose","notes","o","o2","ocean","octocat","older_woman","open_hands","ophiuchus","palm_tree","parking","part_alternation_mark","pencil","penguin","pensive","persevere","police_car","poop","post_office","postbox","pray","princess","punch","purple_heart","question","rabbit","racehorse","radio","rage","rage1","rage2","rage3","rage4","rainbow","raised_hands","ramen","red_car","red_circle","registered","relaxed","relieved","restroom","rewind","ribbon","rice","rice_ball","rice_cracker","rice_scene","ring","rocket","roller_coaster","rose","ru","runner","sa","sagittarius","sailboat","sake","sandal","santa","satellite","satisfied","saxophone","school","school_satchel","scissors","scorpius","scream","seat","secret","shaved_ice","sheep","shell","ship","shipit","shirt","shit","shoe","signal_strength","space_invader","spades","spaghetti","sparkler","sparkles","speaker","speedboat","squirrel","star","star2","stars","station","statue_of_liberty","stew","strawberry","sunflower","sunny","sunrise","sunrise_over_mountains","surfer","sushi","suspect","sweat","sweat_drops","swimmer","syringe","tada","tangerine","taurus","taxi","tea","telephone","tennis","tent","thumbsdown","thumbsup","ticket","tiger","tm","toilet","tokyo_tower","tomato","tongue","top","tophat","traffic_light","train","trident","trollface","trophy","tropical_fish","truck","trumpet","tshirt","tulip","tv","u5272","u55b6","u6307","u6708","u6709","u6e80","u7121","u7533","u7a7a","umbrella","unamused","underage","unlock","up","us","v","vhs","vibration_mode","virgo","vs","walking","warning","watermelon","wave","wc","wedding","whale","wheelchair","white_square","wind_chime","wink","wink2","wolf","woman","womans_hat","womens","x","yellow_heart","zap","zzz","+1"];
2+
emojis = [
3+
"plus1","ok_hand", "sleepy", "smile", "clap", "heart",
4+
"octopus", "six_pointed_star", "oden", "office", "ok", "ok_woman", "older_man","skull",
5+
"smiley", "smirk", "smoking", "snake", "snowman", "sob", "soccer",
6+
"point_down", "point_left", "point_right", "point_up", "point_up_2",
7+
"a", "ab", "airplane", "alien", "ambulance", "angel", "anger", "angry",
8+
"apple", "aquarius", "aries", "arrow_backward", "arrow_down","ski",
9+
"person_with_blond_hair", "phone", "pig", "pill", "pisces",
10+
"arrow_forward", "arrow_left", "arrow_lower_left", "arrow_lower_right",
11+
"arrow_right", "arrow_up", "arrow_upper_left", "arrow_upper_right",
12+
"art", "astonished", "atm", "b", "baby", "baby_chick", "baby_symbol",
13+
"balloon", "bamboo", "bank", "barber", "baseball", "basketball", "bath",
14+
"bear", "beer", "beers", "beginner", "bell", "bento", "bike", "bikini",
15+
"bird", "birthday", "black_square", "blue_car", "blue_heart", "blush",
16+
"boar", "boat", "bomb", "book", "boot", "bouquet", "bow", "bowtie",
17+
"boy", "bread", "briefcase", "broken_heart", "bug", "bulb","slot_machine",
18+
"bullettrain_front", "bullettrain_side", "bus", "busstop", "cactus",
19+
"cake", "calling", "camel", "camera", "cancer", "capricorn", "car",
20+
"cat", "cd", "chart", "checkered_flag", "cherry_blossom", "chicken",
21+
"christmas_tree", "church", "cinema", "city_sunrise", "city_sunset",
22+
"clapper", "clock1", "clock10", "clock11", "clock12", "clock2",
23+
"clock3", "clock4", "clock5", "clock6", "clock7", "clock8", "clock9",
24+
"closed_umbrella", "cloud", "clubs", "cn", "cocktail", "coffee",
25+
"cold_sweat", "computer", "confounded", "congratulations",
26+
"construction", "construction_worker", "convenience_store", "cool",
27+
"cop", "copyright", "couple", "couple_with_heart", "couplekiss", "cow",
28+
"crossed_flags", "crown", "cry", "cupid", "currency_exchange", "curry",
29+
"cyclone", "dancer", "dancers", "dango", "dart", "dash", "de",
30+
"department_store", "diamonds", "disappointed", "dog", "dolls",
31+
"dolphin", "dress", "dvd", "ear", "ear_of_rice", "egg", "eggplant",
32+
"egplant", "eight_pointed_black_star", "eight_spoked_asterisk",
33+
"elephant", "email", "es", "european_castle", "exclamation", "eyes",
34+
"factory", "fallen_leaf", "fast_forward", "fax", "fearful", "feelsgood",
35+
"feet", "ferris_wheel", "finnadie", "fire", "fire_engine", "fireworks",
36+
"fish", "fist", "flags", "flushed", "football", "fork_and_knife",
37+
"fountain", "four_leaf_clover", "fr", "fries", "frog", "fuelpump", "gb",
38+
"gem", "gemini", "ghost", "gift", "gift_heart", "girl", "goberserk",
39+
"godmode", "golf", "green_heart", "grey_exclamation", "grey_question",
40+
"-1", "0", "1", "109", "2", "3", "4", "5", "6", "7", "8", "8ball", "9",
41+
"grin", "guardsman", "guitar", "gun", "haircut", "hamburger", "hammer",
42+
"hamster", "hand", "handbag", "hankey", "hash", "headphones",
43+
"heart_decoration", "heart_eyes", "heartbeat", "heartpulse", "hearts",
44+
"hibiscus", "high_heel", "horse", "hospital", "hotel", "hotsprings",
45+
"house", "hurtrealbad", "icecream", "id", "ideograph_advantage", "imp",
46+
"information_desk_person", "iphone", "it", "jack_o_lantern",
47+
"japanese_castle", "joy", "jp", "key", "kimono", "kiss", "kissing_face",
48+
"kissing_heart", "koala", "koko", "kr", "leaves", "leo", "libra", "lips",
49+
"lipstick", "lock", "loop", "loudspeaker", "love_hotel", "mag",
50+
"mahjong", "mailbox", "man", "man_with_gua_pi_mao", "man_with_turban",
51+
"maple_leaf", "mask", "massage", "mega", "memo", "mens", "metal",
52+
"metro", "microphone", "minidisc", "mobile_phone_off", "moneybag",
53+
"monkey", "monkey_face", "moon", "mortar_board", "mount_fuji", "mouse",
54+
"movie_camera", "muscle", "musical_note", "nail_care", "necktie", "new",
55+
"no_good", "no_smoking", "nose", "notes", "o", "o2", "ocean", "octocat",
56+
"older_woman", "open_hands", "ophiuchus", "palm_tree", "parking",
57+
"part_alternation_mark", "pencil", "penguin", "pensive", "persevere",
58+
"police_car", "poop", "post_office", "postbox", "pray", "princess",
59+
"punch", "purple_heart", "question", "rabbit", "racehorse", "radio",
60+
"rage", "rage1", "rage2", "rage3", "rage4", "rainbow", "raised_hands",
61+
"ramen", "red_car", "red_circle", "registered", "relaxed", "relieved",
62+
"restroom", "rewind", "ribbon", "rice", "rice_ball", "rice_cracker",
63+
"rice_scene", "ring", "rocket", "roller_coaster", "rose", "ru", "runner",
64+
"sa", "sagittarius", "sailboat", "sake", "sandal", "santa", "satellite",
65+
"satisfied", "saxophone", "school", "school_satchel", "scissors",
66+
"scorpius", "scream", "seat", "secret", "shaved_ice", "sheep", "shell",
67+
"ship", "shipit", "shirt", "shit", "shoe", "signal_strength",
68+
"space_invader", "spades", "spaghetti", "sparkler", "sparkles",
69+
"speaker", "speedboat", "squirrel", "star", "star2", "stars", "station",
70+
"statue_of_liberty", "stew", "strawberry", "sunflower", "sunny",
71+
"sunrise", "sunrise_over_mountains", "surfer", "sushi", "suspect",
72+
"sweat", "sweat_drops", "swimmer", "syringe", "tada", "tangerine",
73+
"taurus", "taxi", "tea", "telephone", "tennis", "tent", "thumbsdown",
74+
"thumbsup", "ticket", "tiger", "tm", "toilet", "tokyo_tower", "tomato",
75+
"tongue", "top", "tophat", "traffic_light", "train", "trident",
76+
"trollface", "trophy", "tropical_fish", "truck", "trumpet", "tshirt",
77+
"tulip", "tv", "u5272", "u55b6", "u6307", "u6708", "u6709", "u6e80",
78+
"u7121", "u7533", "u7a7a", "umbrella", "unamused", "underage", "unlock",
79+
"up", "us", "v", "vhs", "vibration_mode", "virgo", "vs", "walking",
80+
"warning", "watermelon", "wave", "wc", "wedding", "whale", "wheelchair",
81+
"white_square", "wind_chime", "wink", "wink2", "wolf", "woman",
82+
"womans_hat", "womens", "x", "yellow_heart", "zap", "zzz", "+1"
83+
];
384

4-
emojis = $.map(emojis, function(value, i) {return {key: value + ':', name:value}});
85+
emojis = $.map(emojis, function(value, i) {return {key:':'+value+':', name:value}});

0 commit comments

Comments
 (0)