feat(groups): add group chat notifications
This commit is contained in:
@@ -249,6 +249,14 @@ api.deleteChatMessage = function(req, res){
|
||||
});
|
||||
}
|
||||
|
||||
api.seenMessage = function(req,res,next){
|
||||
// Skip the auth step, we want this to be fast. If !found with uuid/token, then it just doesn't save
|
||||
var update = {$set:{}};
|
||||
update['$set']['newMessages.'+req.params.gid+'.value'] = false;
|
||||
User.update({_id:req.headers['x-api-user'], apiToken:req.headers['x-api-key']},update).exec();
|
||||
res.send(200);
|
||||
}
|
||||
|
||||
api.likeChatMessage = function(req, res, next) {
|
||||
var user = res.locals.user;
|
||||
var group = res.locals.group;
|
||||
|
||||
@@ -106,6 +106,17 @@ GroupSchema.methods.sendChat = function(message, user){
|
||||
}
|
||||
group.chat.unshift(message);
|
||||
group.chat.splice(200);
|
||||
|
||||
// Kick off chat notifications in the background.
|
||||
var lastSeenUpdate = {$set:{}, $inc:{_v:1}};
|
||||
lastSeenUpdate['$set']['newMessages.'+group._id] = {name:group.name,value:true};
|
||||
if (group._id == 'habitrpg') {
|
||||
// TODO For Tavern, only notify them if their name was mentioned
|
||||
// var profileNames = [] // get usernames from regex of @xyz. how to handle space-delimited profile names?
|
||||
// User.update({'profile.name':{$in:profileNames}},lastSeenUpdate,{multi:true}).exec();
|
||||
} else {
|
||||
mongoose.model('User').update({_id:{$in:group.members, $ne: user ? user._id : ''}},lastSeenUpdate,{multi:true}).exec();
|
||||
}
|
||||
}
|
||||
|
||||
var cleanQuestProgress = function(merge){
|
||||
|
||||
+5
-2
@@ -207,9 +207,11 @@ var UserSchema = new Schema({
|
||||
|
||||
lastCron: {type: Date, 'default': Date.now},
|
||||
|
||||
// {GROUP_ID: Boolean}, represents whether they have unseen chat messages
|
||||
newMessages: {type: Schema.Types.Mixed, 'default': {}},
|
||||
|
||||
party: {
|
||||
// id // FIXME can we use a populated doc instead of fetching party separate from user?
|
||||
lastMessageSeen: String,
|
||||
order: {type:String, 'default':'level'},
|
||||
quest: {
|
||||
key: String,
|
||||
@@ -245,7 +247,8 @@ var UserSchema = new Schema({
|
||||
disableClasses: {type: Boolean, 'default': false},
|
||||
newTaskEdit: {type: Boolean, 'default': false},
|
||||
tagsCollapsed: {type: Boolean, 'default': false},
|
||||
advancedCollapsed: {type: Boolean, 'default': false}
|
||||
advancedCollapsed: {type: Boolean, 'default': false},
|
||||
toolbarCollapsed: {type:Boolean, 'default':false}
|
||||
},
|
||||
profile: {
|
||||
blurb: String,
|
||||
|
||||
@@ -488,6 +488,17 @@ module.exports = (swagger, v2) ->
|
||||
middleware: [auth.auth, groups.attachGroup]
|
||||
action: groups.postChat
|
||||
|
||||
# placing before route below, so that if !=='seen' it goes to next()
|
||||
"/groups/{gid}/chat/seen":
|
||||
spec:
|
||||
method: 'POST'
|
||||
description: "Flag chat messages for a particular group as seen"
|
||||
parameters: [
|
||||
path 'gid','Group id','string'
|
||||
]
|
||||
middleware: []
|
||||
action: groups.seenMessage
|
||||
|
||||
"/groups/{gid}/chat/{messageId}":
|
||||
spec:
|
||||
method: 'DELETE'
|
||||
|
||||
Reference in New Issue
Block a user