mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 22:57:21 +01:00
add online indicator for party members
This commit is contained in:
@@ -182,5 +182,9 @@
|
||||
"raisePetShare": "I raised a pet into a mount by completing my real-life tasks!",
|
||||
"wonChallengeShare": "I won a challenge in Habitica!",
|
||||
"achievementShare": "I earned a new achievement in Habitica!",
|
||||
"orderBy": "Order By <%= item %>"
|
||||
"orderBy": "Order By <%= item %>",
|
||||
|
||||
"you": "you",
|
||||
"online": "online",
|
||||
"onlineCount": "<%= count %> online"
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
habitrpg.controller("PartyCtrl", ['$rootScope','$scope','Groups','Chat','User','Challenges','$state','$compile','Analytics','Quests','Social', 'Pusher',
|
||||
function($rootScope, $scope, Groups, Chat, User, Challenges, $state, $compile, Analytics, Quests, Social, Pusher) {
|
||||
habitrpg.controller("PartyCtrl", ['$rootScope','$scope','Groups','Chat','User','Challenges','$state','$compile','Analytics','Quests','Social',
|
||||
function($rootScope, $scope, Groups, Chat, User, Challenges, $state, $compile, Analytics, Quests, Social) {
|
||||
|
||||
var PARTY_LOADING_MESSAGES = 4;
|
||||
|
||||
@@ -19,7 +19,10 @@ habitrpg.controller("PartyCtrl", ['$rootScope','$scope','Groups','Chat','User','
|
||||
$scope.partyLoadingMessage = window.env.t('partyLoading' + partyMessageNumber);
|
||||
|
||||
function handlePartyResponse (group) {
|
||||
$rootScope.party = $scope.group = group;
|
||||
// Assign and not replace so that all the references get the modifications
|
||||
_.assign($rootScope.party, group);
|
||||
$scope.group = $rootScope.party;
|
||||
$scope.group.loadingParty = false;
|
||||
checkForNotifications();
|
||||
}
|
||||
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
/* Make user and settings available for everyone through root scope.
|
||||
*/
|
||||
|
||||
habitrpg.controller("RootCtrl", ['$scope', '$rootScope', '$location', 'User', '$http', '$state', '$stateParams', 'Notification', 'Groups', 'Shared', 'Content', '$modal', '$timeout', 'ApiUrl', 'Payments','$sce','$window','Analytics','TAVERN_ID',
|
||||
function($scope, $rootScope, $location, User, $http, $state, $stateParams, Notification, Groups, Shared, Content, $modal, $timeout, ApiUrl, Payments, $sce, $window, Analytics, TAVERN_ID) {
|
||||
habitrpg.controller("RootCtrl", ['$scope', '$rootScope', '$location', 'User', '$http', '$state', '$stateParams', 'Notification', 'Groups', 'Shared', 'Content', '$modal', '$timeout', 'ApiUrl', 'Payments','$sce','$window','Analytics','TAVERN_ID', 'Pusher',
|
||||
function($scope, $rootScope, $location, User, $http, $state, $stateParams, Notification, Groups, Shared, Content, $modal, $timeout, ApiUrl, Payments, $sce, $window, Analytics, TAVERN_ID, Pusher) {
|
||||
var user = User.user;
|
||||
|
||||
// Setup page once user is synced
|
||||
@@ -49,6 +49,7 @@ habitrpg.controller("RootCtrl", ['$scope', '$rootScope', '$location', 'User', '$
|
||||
$rootScope.toJson = angular.toJson;
|
||||
$rootScope.Payments = Payments;
|
||||
$rootScope.userNotifications = [];
|
||||
$rootScope.party = {}; // to be extended later with real data
|
||||
|
||||
// Angular UI Router
|
||||
$rootScope.$state = $state;
|
||||
|
||||
@@ -59,29 +59,49 @@ angular.module('habitrpg')
|
||||
});
|
||||
|
||||
// When the user correctly enters the party channel
|
||||
partyChannel.bind('pusher:subscription_succeeded', function(members) {
|
||||
// TODO members = [{id, info}]
|
||||
|
||||
partyChannel.bind('pusher:subscription_succeeded', function(pusherMembers) {
|
||||
// Wait for the party to be loaded
|
||||
Groups.party(reconnecting ? true : false).then(function (party) {
|
||||
// If we just reconnected after some inactivity, sync the party
|
||||
if (reconnecting === true) {
|
||||
Groups.party(true).then(function (syncedParty) {
|
||||
// Assign and not replace so that all the references get the modifications
|
||||
if ($rootScope.party) {
|
||||
_.assign($rootScope.party, syncedParty);
|
||||
_.assign($rootScope.party, party);
|
||||
$rootScope.loadingParty = false; // make sure the party is set as loaded
|
||||
}
|
||||
});
|
||||
|
||||
$rootScope.party.onlineUsers = pusherMembers.count;
|
||||
|
||||
$rootScope.party.members.forEach(function (member) {
|
||||
if (pusherMembers.members[member._id]) {
|
||||
member.online = true;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// When a member enters the party channel
|
||||
partyChannel.bind('pusher:member_added', function(member) {
|
||||
// TODO member = {id, info}
|
||||
partyChannel.bind('pusher:member_added', function(pusherMember) {
|
||||
$rootScope.$apply(function() {
|
||||
$rootScope.party.members.find(function (partyMember) {
|
||||
if (partyMember._id === pusherMember.id) {
|
||||
partyMember.online = true;
|
||||
return true;
|
||||
}
|
||||
});
|
||||
$rootScope.party.onlineUsers++;
|
||||
});
|
||||
});
|
||||
|
||||
// When a member leaves the party channel
|
||||
partyChannel.bind('pusher:member_removed', function(member) {
|
||||
// TODO member = {id, info}
|
||||
partyChannel.bind('pusher:member_removed', function(pusherMember) {
|
||||
$rootScope.$apply(function() {
|
||||
$rootScope.party.onlineUsers--;
|
||||
$rootScope.party.members.find(function (partyMember) {
|
||||
if (partyMember._id === pusherMember.id) {
|
||||
partyMember.online = false;
|
||||
return true;
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// When the user is booted from the party, they get disconnected from Pusher
|
||||
|
||||
@@ -69,6 +69,7 @@ a.pull-right.gem-wallet(ng-if='group.type!="party"', popover-trigger='mouseenter
|
||||
.panel-heading
|
||||
h3.panel-title
|
||||
=env.t('members')
|
||||
span(ng-if='group.type=="party"')= ' (' + env.t('onlineCount', {count: "{{group.onlineUsers}}"}) + ')'
|
||||
button.pull-right.btn.btn-primary(ng-click="openInviteModal(group)")=env.t("inviteFriends")
|
||||
|
||||
.panel-body.modal-fixed-height
|
||||
@@ -84,7 +85,9 @@ a.pull-right.gem-wallet(ng-if='group.type!="party"', popover-trigger='mouseenter
|
||||
span(ng-click='clickMember(member._id, true)')
|
||||
| {{member.profile.name}}
|
||||
span(ng-if='group.type === "party"')
|
||||
| (#[strong {{member.stats.hp.toFixed(1)}}] #{env.t('hp')})
|
||||
| (#[strong {{member.stats.hp.toFixed(1)}}] #{env.t('hp')}) {{member.id === user.id ? ' (' + env.t('you') + ') ' : ''}}
|
||||
.pull-right(ng-if='group.type === "party"')
|
||||
span.text-success {{member.online ? '● ' + env.t('online') : ''}}
|
||||
tr(ng-if='::group.memberCount > group.members.length')
|
||||
td
|
||||
span.badge {{group.memberCount - group.members.length}}
|
||||
|
||||
Reference in New Issue
Block a user