Skip to content

Commit 8b03418

Browse files
committed
Add a contact add/remove button in chat.
1 parent 6f174f8 commit 8b03418

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

static/js/directives/chat.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
*/
2121
define(['jquery', 'underscore', 'text!partials/chat.html', 'text!partials/chatroom.html'], function($, _, templateChat, templateChatroom) {
2222

23-
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) {
23+
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) {
2424

2525
var displayName = safeDisplayName;
2626
var group_chat_id = "";
@@ -193,6 +193,7 @@ define(['jquery', 'underscore', 'text!partials/chat.html', 'text!partials/chatro
193193
var options = $.extend({}, opts);
194194
var subscope = controller.rooms[id];
195195
var index = controller.visibleRooms.length;
196+
var buddy = buddyData.lookup(id);
196197
if (!subscope) {
197198
console.log("Create new chatroom", [id]);
198199
if (settings.group) {
@@ -214,6 +215,9 @@ define(['jquery', 'underscore', 'text!partials/chat.html', 'text!partials/chatro
214215
subscope.p2pstate = false;
215216
subscope.active = false;
216217
subscope.pending = 0;
218+
subscope.isuser = !!(buddy && buddy.session && buddy.session.Userid);
219+
subscope.iscontact = !!(buddy && buddy.contact);
220+
subscope.canAddContact = !subscope.isgroupchat && subscope.isuser;
217221
if (!subscope.isgroupchat) {
218222
buddyData.push(id);
219223
}
@@ -328,6 +332,19 @@ define(['jquery', 'underscore', 'text!partials/chat.html', 'text!partials/chatro
328332
subscope.doClear = function() {
329333
subscope.$broadcast("clear");
330334
};
335+
subscope.addContact = function() {
336+
subscope.$emit("requestcontact", subscope.id, {
337+
restore: true
338+
});
339+
};
340+
subscope.removeContact = function() {
341+
contacts.remove(buddy.contact.Userid);
342+
};
343+
subscope.updateContactStatus = function(event, data) {
344+
subscope.iscontact = event.type === "contactadded";
345+
};
346+
contacts.e.on("contactadded", subscope.updateContactStatus);
347+
contacts.e.on("contactremoved", subscope.updateContactStatus);
331348
//console.log("Creating new chat room", controller, subscope, index);
332349
subscope.$on("submit", function(event, input) {
333350
subscope.seen();
@@ -492,6 +509,8 @@ define(['jquery', 'underscore', 'text!partials/chat.html', 'text!partials/chatro
492509
return;
493510
}
494511
delete controller.rooms[id];
512+
contacts.e.off("contactadded", subscope.updateContactStatus);
513+
contacts.e.off("contactremoved", subscope.updateContactStatus);
495514
$timeout(function() {
496515
subscope.$destroy();
497516
}, 0);

static/partials/chatroom.html

Lines changed: 2 additions & 0 deletions
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" 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)