mirror of
https://github.com/sudoxnym/habitica.git
synced 2026-07-26 13:22:38 +00:00
feat(groups): add group chat notifications
This commit is contained in:
parent
bb852ce9e5
commit
ce82be637d
7 changed files with 52 additions and 6 deletions
|
|
@ -114,8 +114,12 @@ window.habitrpg = angular.module('habitrpg',
|
||||||
.state('options.social.guilds.detail', {
|
.state('options.social.guilds.detail', {
|
||||||
url: '/:gid',
|
url: '/:gid',
|
||||||
templateUrl: 'partials/options.social.guilds.detail.html',
|
templateUrl: 'partials/options.social.guilds.detail.html',
|
||||||
controller: ['$scope', 'Groups', '$stateParams', function($scope, Groups, $stateParams){
|
controller: ['$scope', 'Groups', '$stateParams',
|
||||||
$scope.group = Groups.Group.get({gid:$stateParams.gid});
|
function($scope, Groups, $stateParams){
|
||||||
|
Groups.Group.get({gid:$stateParams.gid}, function(group){
|
||||||
|
$scope.group = group;
|
||||||
|
Groups.seenMessage(group._id);
|
||||||
|
});
|
||||||
}]
|
}]
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -319,6 +319,9 @@ habitrpg.controller("GroupsCtrl", ['$scope', '$rootScope', 'Shared', 'Groups', '
|
||||||
$scope.text = 'Party';
|
$scope.text = 'Party';
|
||||||
$scope.group = $rootScope.party = Groups.party();
|
$scope.group = $rootScope.party = Groups.party();
|
||||||
$scope.newGroup = new Groups.Group({type:'party'});
|
$scope.newGroup = new Groups.Group({type:'party'});
|
||||||
|
|
||||||
|
Groups.seenMessage($scope.group._id);
|
||||||
|
|
||||||
$scope.create = function(group){
|
$scope.create = function(group){
|
||||||
group.$save(function(newGroup){
|
group.$save(function(newGroup){
|
||||||
$scope.group = newGroup;
|
$scope.group = newGroup;
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,8 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
angular.module('groupServices', ['ngResource']).
|
angular.module('groupServices', ['ngResource']).
|
||||||
factory('Groups', ['API_URL', '$resource', '$q',
|
factory('Groups', ['API_URL', '$resource', '$q', '$http', 'User',
|
||||||
function(API_URL, $resource, $q) {
|
function(API_URL, $resource, $q, $http, User) {
|
||||||
var Group = $resource(API_URL + '/api/v2/groups/:gid',
|
var Group = $resource(API_URL + '/api/v2/groups/:gid',
|
||||||
{gid:'@_id', messageId: '@_messageId'},
|
{gid:'@_id', messageId: '@_messageId'},
|
||||||
{
|
{
|
||||||
|
|
@ -44,6 +44,12 @@ angular.module('groupServices', ['ngResource']).
|
||||||
return tavern;
|
return tavern;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// On enter, set chat message to "seen"
|
||||||
|
seenMessage: function(gid){
|
||||||
|
$http.post('/api/v2/groups/'+gid+'/chat/seen');
|
||||||
|
User.user.newMessages[gid] = false;
|
||||||
|
},
|
||||||
|
|
||||||
Group: Group
|
Group: Group
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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) {
|
api.likeChatMessage = function(req, res, next) {
|
||||||
var user = res.locals.user;
|
var user = res.locals.user;
|
||||||
var group = res.locals.group;
|
var group = res.locals.group;
|
||||||
|
|
|
||||||
|
|
@ -106,6 +106,17 @@ GroupSchema.methods.sendChat = function(message, user){
|
||||||
}
|
}
|
||||||
group.chat.unshift(message);
|
group.chat.unshift(message);
|
||||||
group.chat.splice(200);
|
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){
|
var cleanQuestProgress = function(merge){
|
||||||
|
|
|
||||||
|
|
@ -207,9 +207,11 @@ var UserSchema = new Schema({
|
||||||
|
|
||||||
lastCron: {type: Date, 'default': Date.now},
|
lastCron: {type: Date, 'default': Date.now},
|
||||||
|
|
||||||
|
// {GROUP_ID: Boolean}, represents whether they have unseen chat messages
|
||||||
|
newMessages: {type: Schema.Types.Mixed, 'default': {}},
|
||||||
|
|
||||||
party: {
|
party: {
|
||||||
// id // FIXME can we use a populated doc instead of fetching party separate from user?
|
// id // FIXME can we use a populated doc instead of fetching party separate from user?
|
||||||
lastMessageSeen: String,
|
|
||||||
order: {type:String, 'default':'level'},
|
order: {type:String, 'default':'level'},
|
||||||
quest: {
|
quest: {
|
||||||
key: String,
|
key: String,
|
||||||
|
|
@ -245,7 +247,8 @@ var UserSchema = new Schema({
|
||||||
disableClasses: {type: Boolean, 'default': false},
|
disableClasses: {type: Boolean, 'default': false},
|
||||||
newTaskEdit: {type: Boolean, 'default': false},
|
newTaskEdit: {type: Boolean, 'default': false},
|
||||||
tagsCollapsed: {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: {
|
profile: {
|
||||||
blurb: String,
|
blurb: String,
|
||||||
|
|
|
||||||
|
|
@ -488,6 +488,17 @@ module.exports = (swagger, v2) ->
|
||||||
middleware: [auth.auth, groups.attachGroup]
|
middleware: [auth.auth, groups.attachGroup]
|
||||||
action: groups.postChat
|
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}":
|
"/groups/{gid}/chat/{messageId}":
|
||||||
spec:
|
spec:
|
||||||
method: 'DELETE'
|
method: 'DELETE'
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue