Skip to content

Commit 07835e5

Browse files
committed
Add a contact add/remove button in chat.
1 parent 4a2cdbe commit 07835e5

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
@@ -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 = "";
@@ -195,6 +195,7 @@ define(['jquery', 'underscore', 'text!partials/chat.html', 'text!partials/chatro
195195
var options = $.extend({}, opts);
196196
var subscope = controller.rooms[id];
197197
var index = controller.visibleRooms.length;
198+
var buddy = buddyData.lookup(id);
198199
if (!subscope) {
199200
console.log("Create new chatroom", [id]);
200201
if (settings.group) {
@@ -216,6 +217,9 @@ define(['jquery', 'underscore', 'text!partials/chat.html', 'text!partials/chatro
216217
subscope.p2pstate = false;
217218
subscope.active = false;
218219
subscope.pending = 0;
220+
subscope.isuser = !!(buddy && buddy.session && buddy.session.Userid);
221+
subscope.iscontact = !!(buddy && buddy.contact);
222+
subscope.canAddContact = !subscope.isgroupchat && subscope.isuser;
219223
if (!subscope.isgroupchat) {
220224
buddyData.push(id);
221225
}
@@ -332,6 +336,19 @@ define(['jquery', 'underscore', 'text!partials/chat.html', 'text!partials/chatro
332336
subscope.doClear = function() {
333337
subscope.$broadcast("clear");
334338
};
339+
subscope.addContact = function() {
340+
subscope.$emit("requestcontact", subscope.id, {
341+
restore: true
342+
});
343+
};
344+
subscope.removeContact = function() {
345+
contacts.remove(buddy.contact.Userid);
346+
};
347+
subscope.updateContactStatus = function(event, data) {
348+
subscope.iscontact = event.type === "contactadded";
349+
};
350+
contacts.e.on("contactadded", subscope.updateContactStatus);
351+
contacts.e.on("contactremoved", subscope.updateContactStatus);
335352
//console.log("Creating new chat room", controller, subscope, index);
336353
subscope.$on("submit", function(event, input) {
337354
subscope.seen();
@@ -515,6 +532,8 @@ define(['jquery', 'underscore', 'text!partials/chat.html', 'text!partials/chatro
515532
return;
516533
}
517534
delete controller.rooms[id];
535+
contacts.e.off("contactadded", subscope.updateContactStatus);
536+
contacts.e.off("contactremoved", subscope.updateContactStatus);
518537
$timeout(function() {
519538
subscope.$destroy();
520539
}, 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 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)