2222"use strict" ;
2323define ( [ '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 ) ;
0 commit comments