2020 */
2121define ( [ '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 ) ;
0 commit comments