Browse Source

Add a contact add/remove button in chat.

pull/151/head
Evan Theurer 12 years ago
parent
commit
849aed6c87
  1. 21
      static/js/directives/chat.js
  2. 2
      static/partials/chatroom.html

21
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 = "";
@ -195,6 +195,7 @@ define(['jquery', 'underscore', 'text!partials/chat.html', 'text!partials/chatro @@ -195,6 +195,7 @@ define(['jquery', 'underscore', 'text!partials/chat.html', 'text!partials/chatro
var options = $.extend({}, opts);
var subscope = controller.rooms[id];
var index = controller.visibleRooms.length;
var buddy = buddyData.lookup(id);
if (!subscope) {
console.log("Create new chatroom", [id]);
if (settings.group) {
@ -216,6 +217,9 @@ define(['jquery', 'underscore', 'text!partials/chat.html', 'text!partials/chatro @@ -216,6 +217,9 @@ define(['jquery', 'underscore', 'text!partials/chat.html', 'text!partials/chatro
subscope.p2pstate = false;
subscope.active = false;
subscope.pending = 0;
subscope.isuser = !!(buddy && buddy.session && buddy.session.Userid);
subscope.iscontact = !!(buddy && buddy.contact);
subscope.canAddContact = !subscope.isgroupchat && subscope.isuser;
if (!subscope.isgroupchat) {
buddyData.push(id);
}
@ -332,6 +336,19 @@ define(['jquery', 'underscore', 'text!partials/chat.html', 'text!partials/chatro @@ -332,6 +336,19 @@ 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(buddy.contact.Userid);
};
subscope.updateContactStatus = function(event, data) {
subscope.iscontact = event.type === "contactadded";
};
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();
@ -515,6 +532,8 @@ define(['jquery', 'underscore', 'text!partials/chat.html', 'text!partials/chatro @@ -515,6 +532,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" 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="canAddContact && !iscontact" class="btn btn-sm btn-primary" title="{{_('Add to contacts')}}" ng-click="addContact()"><i class="fa fa-star-o"></i></button>
<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>
</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