Browse Source

Merge 130321373f into ff95b5e408

pull/151/merge
theurere 8 years ago committed by GitHub
parent
commit
a236d36633
  1. 49
      static/js/directives/chat.js
  2. 2
      static/partials/chatroom.html

49
static/js/directives/chat.js

@ -22,7 +22,7 @@ @@ -22,7 +22,7 @@
"use strict";
define(['jquery', 'underscore', 'text!partials/chat.html', 'text!partials/chatroom.html'], function($, _, templateChat, templateChatroom) {
return ["$compile", "safeDisplayName", "mediaStream", "safeApply", "desktopNotify", "translation", "playSound", "fileUpload", "randomGen", "buddyData", "appData", "$timeout", "geolocation", function($compile, safeDisplayName, mediaStream, safeApply, desktopNotify, translation, playSound, fileUpload, randomGen, buddyData, appData, $timeout, geolocation) {
return ["$compile", "safeDisplayName", "mediaStream", "safeApply", "desktopNotify", "translation", "playSound", "fileUpload", "randomGen", "buddyData", "appData", "$timeout", "geolocation", "contacts", function($compile, safeDisplayName, mediaStream, safeApply, desktopNotify, translation, playSound, fileUpload, randomGen, buddyData, appData, $timeout, geolocation, contacts) {
var displayName = safeDisplayName;
var groupChatId = "";
@ -198,6 +198,7 @@ define(['jquery', 'underscore', 'text!partials/chat.html', 'text!partials/chatro @@ -198,6 +198,7 @@ define(['jquery', 'underscore', 'text!partials/chat.html', 'text!partials/chatro
var index = controller.visibleRooms.length;
if (!subscope) {
console.log("Create new chatroom", [id]);
var buddy = buddyData.lookup(id);
if (settings.group) {
controller.visibleRooms.unshift(id);
} else {
@ -205,6 +206,7 @@ define(['jquery', 'underscore', 'text!partials/chat.html', 'text!partials/chatro @@ -205,6 +206,7 @@ define(['jquery', 'underscore', 'text!partials/chat.html', 'text!partials/chatro
}
subscope = controller.rooms[id] = scope.$new();
translation.inject(subscope);
subscope.contact = {};
subscope.id = id;
subscope.isgroupchat = !!settings.group;
subscope.index = index;
@ -217,6 +219,31 @@ define(['jquery', 'underscore', 'text!partials/chat.html', 'text!partials/chatro @@ -217,6 +219,31 @@ define(['jquery', 'underscore', 'text!partials/chat.html', 'text!partials/chatro
subscope.p2pstate = false;
subscope.active = false;
subscope.pending = 0;
var handleContactFunctionality = function(buddy) {
var buddyId = buddy && buddy.session && buddy.session.Userid;
var myId = appData.get().userid;
var isAnotherUser = buddyId && myId !== buddyId;
subscope.contact.isContact = !!(buddy && buddy.contact);
subscope.contact.disableContact = !myId || !isAnotherUser;
subscope.contact.showContact = !subscope.isgroupchat && buddyId;
safeApply(subscope);
};
handleContactFunctionality(buddy);
// Update chatter
appData.e.on('authenticationChanged', function() {
handleContactFunctionality(buddy);
});
// Update chattee
mediaStream.api.e.on("received.status", function(event, data) {
if (!id && !data) {
return;
}
// Chattee status changed - logged in
var bd = buddyData.lookup(id);
if ((bd && bd.session.Userid) === data.Userid) {
handleContactFunctionality(buddyData.lookup(data.Id));
}
});
if (!subscope.isgroupchat) {
buddyData.push(id);
}
@ -333,6 +360,24 @@ define(['jquery', 'underscore', 'text!partials/chat.html', 'text!partials/chatro @@ -333,6 +360,24 @@ define(['jquery', 'underscore', 'text!partials/chat.html', 'text!partials/chatro
subscope.doClear = function() {
subscope.$broadcast("clear");
};
subscope.addContact = function() {
subscope.$emit("requestcontact", subscope.id, {
restore: true
});
};
subscope.removeContact = function() {
contacts.remove(buddyData.lookup(id).contact.Userid);
};
subscope.updateContactStatus = function(event, data) {
var userid = buddy && buddy.session && buddy.session.Userid;
if (userid !== data.Userid) {
return;
}
subscope.contact.isContact = event.type === "contactadded";
safeApply(subscope);
};
contacts.e.on("contactadded", subscope.updateContactStatus);
contacts.e.on("contactremoved", subscope.updateContactStatus);
//console.log("Creating new chat room", controller, subscope, index);
subscope.$on("submit", function(event, input) {
subscope.seen();
@ -509,6 +554,8 @@ define(['jquery', 'underscore', 'text!partials/chat.html', 'text!partials/chatro @@ -509,6 +554,8 @@ define(['jquery', 'underscore', 'text!partials/chat.html', 'text!partials/chatro
return;
}
delete controller.rooms[id];
contacts.e.off("contactadded", subscope.updateContactStatus);
contacts.e.off("contactremoved", subscope.updateContactStatus);
$timeout(function() {
subscope.$destroy();
}, 0);

2
static/partials/chatroom.html

@ -5,6 +5,8 @@ @@ -5,6 +5,8 @@
<button ng-if="!isgroupchat && roomType!='Conference'" class="btn btn-sm btn-default" title="{{_('Start video call')}}" ng-click="doCall()"><i class="fa fa-phone fa-fw"></i></button>
<button class="btn btn-sm btn-default btn-fileupload" title="{{_('Upload files')}}"><i class="fa fa-upload fa-fw"></i></button>
<button class="btn btn-sm btn-default btn-locationshare" title="{{_('Share my location')}}" ng-click="shareGeolocation()"><i class="fa fa-location-arrow fa-fw"></i></button>
<button ng-if="contact.showContact && !contact.isContact" class="btn btn-sm btn-default" ng-class="{'disabled': contact.disableContact}" title="{{_('Add to contacts')}}" ng-click="addContact()"><i class="fa fa-star-o"></i></button>
<button ng-if="contact.showContact && contact.isContact" class="btn btn-sm btn-default" title="{{_('Remove from contacts')}}" ng-click="removeContact()"><i class="fa fa-star"></i></button>
</div>
<div class="btn-group pull-right">
<button class="btn btn-sm btn-default" title="{{_('Clear chat')}}" ng-click="doClear()"><i class="fa fa-eraser fa-fw"></i></button>

Loading…
Cancel
Save