Skip to content

Commit 014a82d

Browse files
committed
Add a contact add/remove button in chat.
1 parent 34fdf0b commit 014a82d

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

static/js/directives/chat.js

+20-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"use strict";
2323
define(['jquery', 'underscore', 'text!partials/chat.html', 'text!partials/chatroom.html'], function($, _, templateChat, templateChatroom) {
2424

25-
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) {
25+
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) {
2626

2727
var displayName = safeDisplayName;
2828
var groupChatId = "";
@@ -198,6 +198,7 @@ define(['jquery', 'underscore', 'text!partials/chat.html', 'text!partials/chatro
198198
var options = $.extend({}, opts);
199199
var subscope = controller.rooms[id];
200200
var index = controller.visibleRooms.length;
201+
var buddy = buddyData.lookup(id);
201202
if (!subscope) {
202203
console.log("Create new chatroom", [id]);
203204
if (settings.group) {
@@ -219,6 +220,9 @@ define(['jquery', 'underscore', 'text!partials/chat.html', 'text!partials/chatro
219220
subscope.p2pstate = false;
220221
subscope.active = false;
221222
subscope.pending = 0;
223+
subscope.isuser = !!(buddy && buddy.session && buddy.session.Userid);
224+
subscope.iscontact = !!(buddy && buddy.contact);
225+
subscope.canAddContact = !subscope.isgroupchat && subscope.isuser;
222226
if (!subscope.isgroupchat) {
223227
buddyData.push(id);
224228
}
@@ -336,6 +340,19 @@ define(['jquery', 'underscore', 'text!partials/chat.html', 'text!partials/chatro
336340
subscope.doClear = function() {
337341
subscope.$broadcast("clear");
338342
};
343+
subscope.addContact = function() {
344+
subscope.$emit("requestcontact", subscope.id, {
345+
restore: true
346+
});
347+
};
348+
subscope.removeContact = function() {
349+
contacts.remove(buddy.contact.Userid);
350+
};
351+
subscope.updateContactStatus = function(event, data) {
352+
subscope.iscontact = event.type === "contactadded";
353+
};
354+
contacts.e.on("contactadded", subscope.updateContactStatus);
355+
contacts.e.on("contactremoved", subscope.updateContactStatus);
339356
//console.log("Creating new chat room", controller, subscope, index);
340357
subscope.$on("submit", function(event, input) {
341358
subscope.seen();
@@ -500,6 +517,8 @@ define(['jquery', 'underscore', 'text!partials/chat.html', 'text!partials/chatro
500517
return;
501518
}
502519
delete controller.rooms[id];
520+
contacts.e.off("contactadded", subscope.updateContactStatus);
521+
contacts.e.off("contactremoved", subscope.updateContactStatus);
503522
$timeout(function() {
504523
subscope.$destroy();
505524
}, 0);

static/partials/chatroom.html

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
<button ng-if="!isgroupchat" class="btn btn-sm btn-primary" title="{{_('Start video call')}}" ng-click="doCall()"><i class="fa fa-phone fa-fw"></i></button>
66
<button class="btn btn-sm btn-primary btn-fileupload" title="{{_('Upload files')}}"><i class="fa fa-upload fa-fw"></i></button>
77
<button class="btn btn-sm btn-primary btn-locationshare" title="{{_('Share my location')}}" ng-click="shareGeolocation()"><i class="fa fa-location-arrow fa-fw"></i></button>
8+
<button ng-if="canAddContact && !iscontact" class="btn btn-sm btn-primary" title="{{_('Add to contacts')}}" ng-click="addContact()"><i class="fa fa-star-o"></i></button>
9+
<button ng-if="canAddContact && iscontact" class="btn btn-sm btn-primary" title="{{_('Remove from contacts')}}" ng-click="removeContact()"><i class="fa fa-star"></i></button>
810
</div>
911
<div class="btn-group pull-right">
1012
<button class="btn btn-sm btn-default" title="{{_('Clear chat')}}" ng-click="doClear()"><i class="fa fa-eraser fa-fw"></i></button>

0 commit comments

Comments
 (0)