22
22
"use strict" ;
23
23
define ( [ 'jquery' , 'underscore' , 'text!partials/chat.html' , 'text!partials/chatroom.html' ] , function ( $ , _ , templateChat , templateChatroom ) {
24
24
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 ) {
26
26
27
27
var displayName = safeDisplayName ;
28
28
var groupChatId = "" ;
@@ -198,6 +198,7 @@ define(['jquery', 'underscore', 'text!partials/chat.html', 'text!partials/chatro
198
198
var options = $ . extend ( { } , opts ) ;
199
199
var subscope = controller . rooms [ id ] ;
200
200
var index = controller . visibleRooms . length ;
201
+ var buddy = buddyData . lookup ( id ) ;
201
202
if ( ! subscope ) {
202
203
console . log ( "Create new chatroom" , [ id ] ) ;
203
204
if ( settings . group ) {
@@ -219,6 +220,9 @@ define(['jquery', 'underscore', 'text!partials/chat.html', 'text!partials/chatro
219
220
subscope . p2pstate = false ;
220
221
subscope . active = false ;
221
222
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 ;
222
226
if ( ! subscope . isgroupchat ) {
223
227
buddyData . push ( id ) ;
224
228
}
@@ -336,6 +340,19 @@ define(['jquery', 'underscore', 'text!partials/chat.html', 'text!partials/chatro
336
340
subscope . doClear = function ( ) {
337
341
subscope . $broadcast ( "clear" ) ;
338
342
} ;
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 ) ;
339
356
//console.log("Creating new chat room", controller, subscope, index);
340
357
subscope . $on ( "submit" , function ( event , input ) {
341
358
subscope . seen ( ) ;
@@ -500,6 +517,8 @@ define(['jquery', 'underscore', 'text!partials/chat.html', 'text!partials/chatro
500
517
return ;
501
518
}
502
519
delete controller . rooms [ id ] ;
520
+ contacts . e . off ( "contactadded" , subscope . updateContactStatus ) ;
521
+ contacts . e . off ( "contactremoved" , subscope . updateContactStatus ) ;
503
522
$timeout ( function ( ) {
504
523
subscope . $destroy ( ) ;
505
524
} , 0 ) ;
0 commit comments