/*1357657703,178142511*/

if (self.CavalryLogger) { CavalryLogger.start_js(["6zvDz"]); }

/** js/components/UFI/UFILegacyUtils.js */
__d("UFILegacyUtils",["CSS","MenuX","MenuXItem","MenuXSeparator","Popover","PopoverMenu","PopoverMenuOverlappingBorder","Toggler"],function(a,b,c,d,e,f){



var g=b('CSS'),
h=b('MenuX'),
i=b('MenuXItem'),
j=b('MenuXSeparator'),
k=b('Popover'),
l=b('PopoverMenu'),
m=b('PopoverMenuOverlappingBorder'),
n=b('Toggler');

function o(q){
return q.separator?
{ctor:j}:

{ctor:i,
className:q.className,
href:q.href,
label:q.label,
value:q.value,
title:''};}



var p=





{createCommentMenu:function(q,r,s){


var t=q.parentNode,



u=new h(null,null,r.map(o),{});

u.subscribe('itemclick',function(v,w){
s(w.getValue());});





new l
(new k(t,q,null,{alignh:'right'}),
q,
u,
[m]);




g.addClass(t,'uiPopover');
n.show(t);

return u;}};




e.exports=p;});

/** js/desktop/client/chat_window/FbdChatPresence.js */
__d("FbdChatPresence",["Arbiter","ChatVisibility","DOM","CSS","FbdConstants","FbdExternal","$","Event","FbdEnvData"],function(a,b,c,d,e,f){


var g=b('Arbiter'),
h=b('ChatVisibility'),
i=b('DOM'),
j=b('CSS'),
k=b('FbdConstants'),
l=b('FbdExternal'),
m=b('$'),

n=c('FbdEnvData'),

o=b('Event'),
p=m('offline-notification'),
q=m('unavailable-notification'),
r=i.scry(q,'.turn-on-chat-link')[0];

if(r)
o.listen(r,'click',h.goOnline.shield(this));


function s(){
if(h.isOnline()){
var w=l.isIdle()?2:1;
l.sendMessage('/presence',JSON.stringify({state:w}));}}



function t(w,x){
s();}


function u(){
j.hide(q);
j.hide(p);
if(!l.isMqttConnected()){
j.show(p);}else
if(!h.isOnline())
j.show(q);}



var v=

{setPresenceNotificationsBottom:function(w){
q.style.bottom=p.style.bottom=
w+'px';},


updateOnlineStatus:u};



g.subscribe(k.appIdleStateChanged,t);


s();
setInterval(s,60*1000);
u();

e.exports=v;});

/** js/desktop/client/chat_window/renderers/FbdChatRenderer.js */
__d("FbdChatRenderer",["Env","FbdFunctionDispatcher","MercuryThreadMetadataRawRenderer"],function(a,b,c,d,e,f){



var g=b('Env'),
h=b('FbdFunctionDispatcher'),
i=
b('MercuryThreadMetadataRawRenderer');

function j
(k,
l,
m){
h.dispatchWorkerAsyncFunctionCall
('MercuryParticipants',
'getMulti',
[l],
function(n){
h.dispatchWorkerFunctionCall
('MercuryServerRequests',
'getServerThreadIDNow',
[k.thread_id],
function(o){
i.
renderParticipantListWithNoThreadName
(o,
k,
l,
n,
[],

{check_length:true,
callback:m,
last_separator_uses_and:true,
names_renderer:
i.renderShortNames});});});}





e.exports=
{renderChatTabTitle:function(k,l){
h.dispatchWorkerAsyncFunctionCall
('MercuryThreads',
'getThreadMeta',
[k],
function(m){

if(m.name){
var n=
i.renderRawTitleWithUnreadCount
(m.name,
0);

l(n);}else{


var o=m.participants;
if(m.participants.length>1){
o=m.participants.filter(function(p){
return p!="fbid:"+g.user;});

j
(m,
o,
l);}else 

j
(m,
o,
l);}}.


bind(this));},


renderTitanLink:function(k,l,m){
if(k.substr(0,k.indexOf(':'))=='user'){
i.renderUserCanonicalTitanLink
(k,
l,
m);}else 



h.dispatchWorkerAsyncFunctionCall
('MercuryServerRequests',
'getServerThreadID',
[k],
function(n){
i.renderTitanLinkWithServerID
(n,
l,
m);});}};});

/** js/desktop/client/chat_window/ui/DesktopAddFriendsTabSheet.js */
__d("DesktopAddFriendsTabSheet",["ChatAddFriendsTabSheetRawRenderer","FbdFunctionDispatcher","FbdCore","SocialFoxConstants","copyProperties"],function(a,b,c,d,e,f){



var g=
b('ChatAddFriendsTabSheetRawRenderer'),
h=b('FbdFunctionDispatcher'),
i=b('FbdCore'),
j=b('SocialFoxConstants'),

k=b('copyProperties');

function l
(o,
p,
q){
this._thread=o;
this._rootElement=p;
this._sheetView=q;}


k(l.prototype,
{render:function(){
var o=this._thread.is_canonical_user?
m:
n;
g.render
(this,
this._sheetView,
this._rootElement,
this._thread,
o.curry(this._thread));},



isPermanent:function(){
return true;},


getType:function(){
return 'add_friends_type';},



open:function(){
this._sheetView.open(this);}});



function m(o,p){
h.dispatchWorkerFunctionCall
("FbdChatDataWorker",
"createNewMultichatTab",
[o,p],
function(q){
i.inform(j.newMultichat,{thread_id:q});});}



function n(o,p){
h.dispatchWorkerFunctionCall
("FbdChatDataWorker",
"addPeopleToMultichatTab",
[o,p]);}


e.exports=l;});

/** js/desktop/client/chat_window/FbdConversation.js */
__d("FbdConversation",["array-extensions","date-extensions","Event","Arbiter","ChatPrivacyActionController","MercurySheetView","CSS","DesktopAddFriendsTabSheet","DOM","DOMQuery","Env","FbdChatRenderer","FbdConstants","FbdCore","FbdExternal","FbdFunctionDispatcher","FbdUtils","FbdVerticalScrollbar","HTML","JSLogger","Keys","Layer","MercuryEmoji","MercuryThreadMetadataRawRenderer","MessagesEmoticonView","Style","Toggler","Tooltip","UFILegacyUtils","URI","$","ge","bind","copyProperties","htmlHyperlink","tx","PlaceholderListener","ChatTabTemplates","MercuryConstants","FbdChatTemplates","FbdChatData","FbdChatTimeFormats","FbdEnvData"],function(a,b,c,d,e,f){



b('array-extensions');
b('date-extensions');
var g=b('Event'),

h=b('Arbiter'),
i=b('ChatPrivacyActionController'),
j=b('MercurySheetView'),
k=b('CSS'),
l=b('DesktopAddFriendsTabSheet'),
m=b('DOM'),
n=b('DOMQuery'),
o=b('Env'),
p=b('FbdChatRenderer'),
q=b('FbdConstants'),
r=b('FbdCore'),
s=b('FbdExternal'),
t=b('FbdFunctionDispatcher'),
u=b('FbdUtils'),
v=b('FbdVerticalScrollbar'),
w=b('HTML'),
x=b('JSLogger'),
y=b('Keys'),
z=b('Layer'),
aa=b('MercuryEmoji'),
ba=
b('MercuryThreadMetadataRawRenderer'),
ca=b('MessagesEmoticonView'),
da=b('Style'),
ea=b('Toggler'),
fa=b('Tooltip'),
ga=b('UFILegacyUtils'),
ha=b('URI'),

ia=b('$'),
ja=b('ge'),
ka=b('bind'),
la=b('copyProperties'),
ma=b('htmlHyperlink'),
na=b('tx');

b('PlaceholderListener');

var oa=b('ChatTabTemplates'),
pa=b('MercuryConstants'),
qa=b('FbdChatTemplates'),
ra=20,
sa='current-conversation',

ta=b('FbdChatData'),
ua=c('FbdEnvData'),

va=x.create('desktop_conversation'),

wa=
function(lb,mb,nb,ob){
this._closeConversationHandler=ob;


db();


this.thread=lb;
this.id=lb.thread_id;
this.name=mb;
this.is_friend=nb;


this._historyLoaded=false;
this._receivedMessages={};
this._isActive=false;


this._eventHandlers=[];


this._lastTypingState=0;
this._lastSentTypingState=0;
this._sentTypingNotification=false;

this.prevMessage=null;


if(ya)
this.headerDiv=ya?
u.applyTemplate
(ya,{name:mb}):
null;

this.contentDiv=u.applyTemplate
(za,{name:mb});
this.input=m.scry(this.contentDiv,'.chat-input')[0];
this._maxlength=parseInt(this.input.getAttribute('maxlength'),10);
this.messagesList=m.scry(this.contentDiv,'.messages-list')[0];
this.messagesFrame=m.scry(this.contentDiv,'.messages-frame')[0];
this._indicatorContainer=
m.scry(this.contentDiv,".is-typing-container")[0];
this._indicatorLine=
m.scry(this._indicatorContainer,".is-typing-display")[0];
this._indicatorIcon=
m.scry(this._indicatorContainer,".is-typing-icon")[0];


this.eventListen
(this.input,
'keydown',
this._onKeyDown.bind(this));
this.eventListen
(this.input,
'keyup',
this._updateTypingState.bind(this));

t.dispatchWorkerFunctionCall
("FbdChatDataWorker",
"subscribeToChatDataIndicatorController",
[this.id]);

v.attach(this.messagesFrame);
v.attach(this.input);

this.handleThreadsUpdated(lb);
this.refreshHistory();

var pb=m.find(this.contentDiv,'.emoticons');
this._emoticonView=new ca
(pb,
this.input);
if(ua.isSocialFox){
var qb=m.find(this.contentDiv,'.emoticonsPanel');

da.set(qb,'bottom','0px');}

this._sheetView=new j
(this.id,
m.find(this.contentDiv,".sheet"),
this.contentDiv);
this._tabSheet=new l
(this.thread,
m.find(this.contentDiv,".sheet"),
this._sheetView);

this._attachGearMenu();



g.listen(a,'unload',function(){
r.inform(q.chatTabUnloaded,
{thread_id:this.id});
this._closeConversationHandler(this.id,false);}.
bind(this));

h.subscribe(q.dialogResult,this._unsubscribe.bind(this));

h.subscribe(q.appIdleStateChanged,
this.handleIdleStateChanged.bind(this));


this.layers=[];
z.subscribe('show',function(rb,sb){
this.layers.push(sb);}.
bind(this));
z.subscribe('hide',function(rb,sb){
var tb=this.layers.indexOf(sb);
if(tb!==-1)
this.layers.splice(tb,1);}.

bind(this));},



xa=false,

ya,
za,
ab,
bb,
cb;

function db(){
if(xa)
return;

xa=true;

ya=ja('conversation-header-template');
za=ia('conversation-content-template');
ab=ia('message-group-template');
bb=ia('date-break-template');
cb=ia('message-event-template');}



var eb=b('FbdChatTimeFormats'),

fb=eb.timeOnlyFmt,
gb=eb.monthDayFmt,
hb=eb.monthDayYearFmt;

la(wa.prototype,
{activate:function(){
this._isActive=true;

if(this.headerDiv){
k.addClass(this.headerDiv,sa);
this._updateTabCSS();}

setTimeout(ka(this,function(){
this.input.focus();}),
0);

this._markReadIfAppropriate();


if(this._historyLoaded)
t.dispatchWorkerFunctionCall
("FbdChatDataWorker",
"checkMercuryChannelForConsistency",
[]);},



_appendMessage:function(lb,mb,nb){
va.debug('append_message',{message:nb,time:mb});
if(!lb)
va.debug('append_message_no_participant');



if(nb.status==pa.MercuryActionStatus.RESENT){
va.debug('message_resent',nb);
return;}



if(this._receivedMessages[nb.message_id]){
va.debug('message_in_received_messages',nb);
return;}


if(nb.is_cleared)
return;


if(!this.lastDate||
mb-this.lastDate>1000*3600*24||
mb.getDate()!==this.lastDate.getDate()){
var ob=new Date().getFullYear()!=mb.getFullYear()?
mb.format(hb):
mb.format(gb),
pb=u.applyTemplate(bb,
{date:ob});
this.messagesList.appendChild(pb);
this.lastDate=mb;}


var qb=this._getMessageGroup(lb,mb);
if(qb){
var rb=m.scry(qb,'.messages')[0],

sb=m.create
('div',

{className:'fbDesktopChatMessage',
id:'entry_'+nb.message_id});


this._renderFullMessage(sb,nb);

m.appendContent(rb,sb);

this._receivedMessages[nb.message_id]=sb;
this.prevMessage=nb;}else 

va.debug('no_group_for_message',nb);},



_appendMessages:function(lb,mb){
if(!(lb&&lb.length>0)){
va.debug('no_append_messages',lb);
return;}


var nb=this.isAtBottom(),

ob=
lb.map(function(pb){
return pb.author;});

t.dispatchWorkerAsyncFunctionCall
("MercuryParticipants",
"getMulti",
[ob],
function(pb){
va.debug('append_messages');
if(mb){
this._historyLoaded=true;
this._receivedMessages={};

m.empty(this.messagesList);
this.lastGroup=null;
this.lastDate=null;}


lb.forEach(function(qb){
this._appendMessage
(pb[qb.author],
new Date(parseInt(qb.timestamp,10)),
qb);}.
bind(this));

if(nb)
this.scrollMessagesToBottom();


this._markReadIfAppropriate();

t.dispatchWorkerFunctionCall
("FbdChatDataWorker",
"setIndicatorControllerLastMessage",
[this.id,this.prevMessage]);}.
bind(this));},


_attachGearMenu:function(){
var lb;
t.dispatchWorkerFunctionCall
("MercuryThreads",
"getCanonicalUserInThread",
[this.id],
function(mb){
if(this.is_friend){
lb=
[{label:"Add Friends to Chat...",value:'addFriendsLink'},
{label:'',value:'togglePrivacy',className:'togglePrivacy'},
{separator:true},
{label:"See Full Conversation",
className:'conversationLink',
href:'#'},
{label:"Clear Window",value:'clearWindowLink'}];


if(!ua.isSocialFox){
lb.push({separator:true});
lb.push
({label:"Report as Spam",
value:'reportSpamLink'});}

this._addGearMenuItems(lb,mb);}else
if(mb){

lb=
[{label:"Add Friends to Chat...",value:'addFriendsLink'},
{separator:true},
{label:"See Full Conversation",
className:'conversationLink',
href:'#'},
{label:"Clear Window",value:'clearWindowLink'}];

this._addGearMenuItems(lb,mb);}else 

t.dispatchWorkerAsyncFunctionCall
("MercuryThreads",
"getThreadMeta",
[this.id],
function(nb){
if(!nb.is_canonical){
lb=
[{label:"Add Friends to Chat...",
value:'addFriendsLink'},
{separator:true},
{label:"Leave Conversation...",
value:'unsubscribeLink'}];

this._addGearMenuItems(lb);}}.





bind(this));}.

bind(this));},


_addGearMenuItems:function(lb,mb){
var nb=m.find(this.contentDiv,'.options-menu'),
ob=qa[':fb:desktop:chat:gear-button'].
build(),
pb=ob.getRoot(),
qb=m.find(pb,'.uiPopoverButton');
m.setContent(nb,pb);
this.eventListen(qb,'click',function(){
if(!this._gearMenu){
this._gearMenu=ga.createCommentMenu
(qb,
lb,
this._onMenuItemClick.bind(this));

if(mb){
if(this.is_friend)
this._privacyActionController=new i
(mb,
this._updatePrivacyLink.bind(this));


var rb=m.find
(this._gearMenu.getRoot(),
'.conversationLink .itemAnchor');

rb.setAttribute('target','_blank');
k.hide(rb);
p.renderTitanLink
(this.id,
rb,
k.show.bind(k,rb));}



ea.show(qb);}}.

bind(this));},


_onMenuItemClick:function(lb){
if(lb==='addFriendsLink'){
this._tabSheet.open();}else
if(lb==='unsubscribeLink'){
this._leaveConversation();}else
if(lb==='togglePrivacy'){
this._privacyActionController.togglePrivacy();}else
if(lb==='clearWindowLink'){
t.dispatchWorkerFunctionCall
("FbdChatDataWorker",
"clearHistory",
[this.id]);}else
if(lb==='reportSpamLink')
this._reportSpam();},




_updatePrivacyLink:function(lb){
var mb=m.find(this._gearMenu.getRoot(),'.togglePrivacy .itemLabel');
if(lb===i.OFFLINE){
m.setContent(mb,"Turn on chat");}else 

t.dispatchWorkerAsyncFunctionCall
('FbdChatDataWorker',
'fetchPrivacyInfo',
[this.id],
function(nb){
var ob=null;
if(lb===i.BLOCKED){
ob=na._("Turn On Chat for {name}",
{name:nb.short_name});}else 

ob=na._("Turn Off Chat for {name}",
{name:nb.short_name});

m.setContent(mb,ob);});},




_leaveConversation:function(){
if(r.getCapability('nativeDialog')){
this._dialogToken=s.asyncConfirm
("You will stop receiving messages from this conversation and people will see that you left.",
"Leave Conversation?");}else{

this._dialogToken=0;
this._unsubscribe(null,{id:0,result:true});}},



cleanup:function(){
this.input.onkeydown=null;
this.input.onpaste=null;

clearTimeout(this._typingUpdateTimeout);
clearTimeout(this._typingExpireTimeout);

if(this._lastSentTypingState===1)
this._sendTypingNotification(0);


t.dispatchWorkerFunctionCall
("FbdChatDataWorker",
"unsubscribeFromIndicatorController",
[this.id]);

this._emoticonsView&&this._emoticonsView.destroy();
this._sheetView.destroy();

this._eventHandlers.forEach(function(lb){
lb.remove();});


this._gearMenu=null;
this._privacyActionController&&this._privacyActionController.destroy();},


deactivate:function(){
this._isActive=false;

if(this.headerDiv){
k.removeClass(this.headerDiv,sa);
this._updateTabCSS();}




this.layers.forEach(function(lb){
lb.hide();});

this.layers=[];},


eventListen:function(lb,event,mb){
this._eventHandlers.push(g.listen(lb,event,mb));},


_getMessageGroup:function(lb,mb){
if(this.lastGroup&&lb.id===this.lastGroup._userId){
var nb=this.lastGroup._time;
if(mb.getTime()-nb.getTime()<5*60*1000){
this.lastGroup._time=mb;
return this.lastGroup;}}



var ob={};
la(ob,lb);
ob.timestamp=mb.format(fb);

var pb=u.applyTemplate
(ab,
ob),


qb=lb.id.substr(lb.id.indexOf(':')+1),
rb=lb.name;
if(qb==o.user)
rb="You";

var sb=m.create('div',null,rb),
tb=m.find(pb,'.profile-photo');
fa.set(tb,sb,'above','left');

pb._userId=lb.id;
pb._time=mb;

this.messagesList.appendChild(pb);
this.lastGroup=pb;

return pb;},


handleIdleStateChanged:function(lb){
this._markReadIfAppropriate();},


handleIndicatorStateChanged:function(lb){
var mb=this.isAtBottom();
this._rerenderIndicatorLine(lb);
if(mb)
this.scrollMessagesToBottom();},







handleMessagesReceived:function(lb){
this._appendMessages(lb,false);},


handleMessagesReordered:function(lb){
this.refreshHistory();},


handleMessagesUpdated:function(lb){
for(var mb in lb){
var nb=this._receivedMessages[mb];


if(!nb){
this.refreshHistory();
return;}


t.dispatchWorkerFunctionCall
("FbdChatDataWorker",
"fetchMessagesFromIDsNoAttachments",
[[mb]],
function(ob){
var pb=ob[0];
m.empty(nb);
this._renderFullMessage
(nb,
pb);}.
bind(this));}},



handleThreadsUpdated:function(lb){
var mb=function(nb){
this.name=nb.toString();
if(this._isActive)
s.setChatWindowTitle(this.name);

if(this.headerDiv){
var ob=m.find(this.headerDiv,".name");
m.setContent(ob,nb);}}.

bind(this);

p.renderChatTabTitle(this.id,mb);

this._updateTabCSS();},


isAtBottom:function(){
var lb=this.messagesFrame;
return (lb.offsetHeight===0||
lb.offsetHeight===lb.scrollHeight||
lb.scrollTop+lb.offsetHeight===
lb.scrollHeight);},


_markReadIfAppropriate:function(){


if(!this._historyLoaded||
!this._isActive||
s.isIdle()||
!s.isChatWindowActive())
return;



t.dispatchWorkerFunctionCall
('FbdChatDataWorker',
'markThreadAsRead',
[this.id]);},





_messageHistoryCallback:function(lb){
va.debug('message_history_callback',lb);

this._appendMessages(lb,true);},


_onKeyDown:function(lb){
if(lb.keyCode===y.RETURN&&!lb.shiftKey){

if(s.isMqttConnected())
this._send(this.input.value);


lb.kill();}},



refreshHistory:function(){
va.debug('refresh_history');

this.prevMessage=null;


var lb=Math.max
(ra,
Object.keys(this._receivedMessages).length);

t.dispatchWorkerAsyncFunctionCall
("FbdChatDataWorker",
"fetchThreadMessageRangeNoAttachments",
[this.id,0,lb],
this._messageHistoryCallback.bind(this));},


_reportSpam:function(){
t.dispatchWorkerFunctionCall
("MercuryThreads",
"getCanonicalUserInThread",
[this.id],
function(lb){
var mb=ha('/ajax/chat/report.php').
addQueryData({id:lb}).
addQueryData({src:'top_report_link'});

r.inform
(q.showFacebookDialog,
{uri:mb.toString(),
data:{},
method:'POST'});});},




_rerenderIndicatorLine:function(lb){
if(lb.activity=='none'){
k.hide(this._indicatorContainer);
return;}


m.setContent(this._indicatorLine,lb.text);
if(lb.activity.substring(0,4)=='seen'){
k.setClass(this._indicatorIcon,'seen');
if(lb.activity=='seen-by'&&lb.tooltip)
t.dispatchWorkerAsyncFunctionCall
("MercuryParticipants",
"getMulti",
[lb.seenBy],
function(mb){
var nb=m.create('div'),
ob=0;
for(var pb in mb)
if(ob++>=2){
var qb=m.create('div');
m.setContent(qb,mb[pb].name);
m.appendContent(nb,qb);}



var rb=n.find(this._indicatorLine,'a');
fa.set(rb,nb,'above','center');}.
bind(this));}else 


k.setClass(this._indicatorIcon,lb.activity);


k.show(this._indicatorContainer);},


_renderFullMessage:function(lb,mb){
if(mb.subject){
var nb=oa[':fb:chat:conversation:message:subject'].
render();
m.setContent(nb,mb.subject);
m.appendContent(lb,nb);}



if(mb.body)
lb.appendChild(ib(mb));


if(mb.has_attachment||
(mb.attachment&&mb.attachments.length>=1)){
var ob=m.create('a',{},"See Attachment");
ob.setAttribute('target','_blank');
p.renderTitanLink
(this.id,
ob,
k.show.bind(k,ob));

m.appendContent(lb,ob);}


if(mb.forward_count)
m.appendContent(lb,jb(mb));},



scrollMessagesToBottom:function(){
this.messagesFrame.scrollTop=this.messagesFrame.scrollHeight;},


_send:function(lb){

if(!lb||u.trim(lb).length===0)
return;


t.dispatchWorkerFunctionCall
("FbdChatDataWorker",
"sendMessage",
[this.id,lb]);
this.input.value='';
this._lastSentTypingState=0;
this.scrollMessagesToBottom();},


_sendTypingNotification:function(lb){
t.dispatchWorkerFunctionCall
("MercuryThreads",
"getCanonicalUserInThread",
[this.id],
function(mb){
if(mb){
var nb=
{to:mb,
state:lb};

s.sendMessage('/typing',JSON.stringify(nb));}});},




_unsubscribe:function(lb,mb){
if(mb.id===this._dialogToken&&mb.result){
t.dispatchWorkerFunctionCall
("FbdChatDataWorker",
"unsubscribeFromThread",
[this.id]);
this._closeConversationHandler(this.id,true);
this._dialogToken=null;}},



_tryUpdateMultichatTooltip:function(){
var lb=function(mb){
var nb=m.create('div');
mb.forEach(function(ob){

var pb=ob.name,
qb=ob.is_online,

rb=qa[
':fb:mercury:chat:multichat-tooltip-item'].build();

m.setContent(rb.getNode('name'),pb);

k.conditionShow(rb.getNode('icon'),qb);
k.conditionClass
(rb.getNode('name'),
'tooltipItemWithIcon',
qb);


m.appendContent(nb,rb.getRoot());});


if(this.headerDiv)
fa.set(this.headerDiv,nb,'above','center');};


t.dispatchWorkerAsyncFunctionCall
("FbdChatDataWorker",
"fetchDataForChatTooltip",
[this.id,o.user],
lb.bind(this));},


fetchUnreadCount:function(lb){
t.dispatchWorkerFunctionCall
("FbdChatDataWorker",
"fetchThreadMetaNow",
[this.id],
function(mb){
var nb=mb?mb.unread_count:0;
lb(nb);});},



_updateTabCSS:function(){
if(this.headerDiv)
this.fetchUnreadCount
(function(lb){
var mb=
!this._isActive&&lb>0;
k.conditionClass
(this.headerDiv,
'has-new-message',
mb);
var nb=m.find(this.headerDiv,'.num-messages'),
ob=m.find(nb,'.text');
m.setContent
(ob,
lb);
k.conditionShow(nb,mb);}.
bind(this));},




_updateTypingState:function(){
var lb=u.trim(this.input.value),
mb=(lb==='')?0:1;

if(mb!==this._lastTypingState){
clearTimeout(this._typingUpdateTimeout);
if(mb!==this._lastSentTypingState)
this._typingUpdateTimeout=setTimeout(function(){
this._sendTypingNotification(mb);
this._lastSentTypingState=mb;}.
bind(this),1000);}



clearTimeout(this._typingExpireTimeout);
if(mb===1)
this._typingExpireTimeout=setTimeout(function(){
this._sendTypingNotification(0);
this._lastSentTypingState=0;
this._lastTypingState=0;}.
bind(this),8000);


this._lastTypingState=mb;},


showNewMessageToasts:function(lb){
lb.forEach(function(mb){
if(mb.is_unread&&
(this._isActive||
!s.isChatWindowActive()))
t.dispatchWorkerAsyncFunctionCall
("FbdChatDataWorker",
"isAThreadToToast",
[mb.author,o.user],
function(nb){
s.showCustomToastIfAvailable
({type:q.toastTypes.message,
pic_square:nb.image_src,
text:nb.name+": "+mb.body,
friend:nb,
notification_id:this.id});}.

bind(this));}.

bind(this));},


updatePresenceInfo:function(){
t.dispatchWorkerFunctionCall
('MercuryThreads',
'getCanonicalUserInThread',
[this.id],
function(lb){
if(lb){
t.dispatchWorkerAsyncFunctionCall
('FbdChatDataWorker',
'fetchTabPresenceInfoUpdate',
[lb],
function(mb,nb){
if(this.headerDiv){
u.updatePresence
(this.headerDiv,
mb,
nb);}else 

if(nb)
u.updateFavicon(mb);}.


bind(this));}else 

if(this.headerDiv)
this._tryUpdateMultichatTooltip();}.


bind(this));}});



function ib(lb){
var mb=m.create
('div',
{className:'chat-message'},
w(ma
(lb.body||'',
aa.htmlEmojiAndEmote,
null,
true))),



nb=function(){
t.dispatchWorkerFunctionCall
("FbdChatDataWorker",
"resendMessage",
[lb]);},


ob=ba.renderStatusIndicator
(lb.status,
lb.error_data,
nb);



if(!ob&&
lb.author===o.user&&
lb.status===pa.MercuryActionStatus.UNSENT){
var pb=Date.now();
if(pb-lb.timestamp>=
ta.send_failure_timeout)
ob=ba.renderErrorIndicator
({type:pa.MercuryErrorType.SERVER},
nb);}





if(ob){

k.addClass(mb,'errorStatus');

var qb=
oa[':fb:chat:conversation:message:status'].build();
m.appendContent
(qb.getNode('message'),
mb);
m.appendContent(qb.getNode('status'),ob);

return qb.getRoot();}else 

return mb;}




function jb(lb){
var mb=oa[':fb:mercury:chat:message:forward'].build(),

nb=mb.getNode('forwardText');
if(nb){
k.hide(mb.getRoot());
p.renderTitanLink
(lb.thread_id,
mb.getNode('forwardLink'),
k.show.bind(k,mb.getRoot()));


if(lb.forward_count>1){
m.appendContent
(nb,
na._("{count} forwarded messages",{count:lb.forward_count}));}else 


m.appendContent(nb,"1 forwarded message");}



return mb.getRoot();}


function kb(lb){
if(lb.rel==='dialog'&&!ua.useSpotlight){
var mb=new ha(lb.preview_url).addQueryData
({preview:0}).
toString();
lb.url=mb;
lb.rel='ignore';}}



e.exports=wa;});

/** js/desktop/client/chat_window/FbdChatShared.js */
__d("FbdChatShared",["FbdCore","Arbiter","DOM","FbdChatPresence","FbdConstants","FbdExternal","FbdUtils","Keys"],function(a,b,c,d,e,f){



b('FbdCore');

var g=b('Arbiter'),
h=b('DOM'),
i=b('FbdChatPresence'),
j=b('FbdConstants'),
k=b('FbdExternal'),
l=b('FbdUtils'),
m=b('Keys'),

n=null,
o=
{pendingUnseenMessage:false,
setCurrentConversation:function(p){
n=p;},


getCurrentConversation:function(){
return n;},


clearCurrentConversation:function(){
n=null;},


chatWindowActivated:function(){
if(n){
this.pendingUnseenMessage=false;
n.activate();
k.setChatWindowTitle(n.name);}},



onKeyDown:function(p){
if(p.ctrlKey&&!p.altKey)

switch(p.keyCode){
case 87:
case 115:
g.inform(j.chatCommandCloseCurrentTab);
return false;
case m.PAGE_UP:
g.inform(j.chatCommandSwitchToPreviousTab);
return false;
case m.PAGE_DOWN:
g.inform(j.chatCommandSwitchToNextTab);
return false;
case 57:
g.inform(j.chatCommandSwitchToLastTab);
return false;

default:if(p.keyCode>=49&&p.keyCode<=56){
g.inform
(j.chatCommandSwitchToTabIndex,
p.keyCode-49);
return false;}

}


if(p.keyCode===m.TAB){
g.inform
(p.shiftKey?
j.chatCommandSwitchToPreviousTab:
j.chatCommandSwitchToNextTab);
return false;}


if(p.keyCode===m.ESC)
g.inform(j.chatCommandCloseCurrentTab);},



playNewMessageSound:function(){
if(!k.getBoolSetting('ChatSounds'))
return;


if(k.isChatWindowActive())
return;


k.playIncomingMessageSound();},


resize:function(p){
if(n===null)
return;


var q=n.isAtBottom(),

r=l.getWindowHeight();
if(r>0){
var s=r-p,

t=h.scry(n.contentDiv,
'.input-frame')[0],
u=t.offsetHeight,

v=s-u;
if(v>0)
n.messagesFrame.style.height=v+'px';

i.setPresenceNotificationsBottom
(p+u);}


var w=l.getWindowWidth();
if(w>0)
n.messagesList.style.width=
w+'px';


if(q)
n.scrollMessagesToBottom();}};



e.exports=o;});

/** js/desktop/client/chat_window/FbdChat.js */
__d("FbdChat",["array-extensions","Event","Arbiter","AvailableListConstants","CSS","DOM","Env","FbdChatPresence","FbdChatRenderer","FbdConversation","FbdConstants","FbdExternal","FbdFunctionDispatcher","FbdChatShared","FbdUtils","FbdWindowMouseTracker","JSLogger","PresencePrivacy","TextAreaControl","$","tx"],function(a,b,c,d,e,f){



b('array-extensions');
var g=b('Event'),

h=b('Arbiter'),
i=b('AvailableListConstants'),
j=b('CSS'),
k=b('DOM'),
l=b('Env'),
m=b('FbdChatPresence'),
n=b('FbdChatRenderer'),
o=b('FbdConversation'),
p=b('FbdConstants'),
q=b('FbdExternal'),
r=b('FbdFunctionDispatcher'),
s=b('FbdChatShared'),
t=b('FbdUtils'),
u=b('FbdWindowMouseTracker'),
v=b('JSLogger'),
w=b('PresencePrivacy'),
x=b('TextAreaControl'),

y=b('$'),
z=b('tx'),

aa=v.create('desktop');

function ba(ib,jb){
ha(jb.thread_id,
function(kb,lb){
ta(kb);
q.showChatWindow(true);});}



function ca(ib,jb){



jb=jb.substr(2);
r.dispatchWorkerAsyncFunctionCall
('MercuryServerRequests',
'getClientThreadID',
[jb],
function(kb){
ha(kb,
function(lb,mb){
ta(lb);
q.showChatWindow(true);});});}




function da(ib,jb){
if(ib===0)
jb();}


function ea(){
m.updateOnlineStatus();
xa();}



function fa(ib,jb){
if(!ib)
return;


var kb=ab.indexOf(ib.id);


if(ib.headerDiv)
cb.removeChild(ib.headerDiv);

ib.cleanup();
delete za[ib.id];
ab.splice(kb,1);


if(s.getCurrentConversation()===ib)
if(kb<ab.length){
ta(za[ab[kb]]);}else
if(kb>0){
ta(za[ab[kb-1]]);}else{


s.clearCurrentConversation();
q.hideChatWindow();}



sa();
wa();
if(jb)
qa();}



function ga(ib,jb){
for(var kb in za)
if(ib[kb])
jb(za[kb],ib[kb]);}




function ha(ib,jb){
var kb=function(lb,mb,nb,ob){
var pb=function(qb){
var rb=za[ib];
if(rb){
jb(rb,false);
return;}


rb=new o
(lb,
qb.toString(),
nb,
function(tb,ub){
fa(za[tb],ub);});


if(rb.headerDiv){
cb.appendChild(rb.headerDiv);

rb.eventListen(rb.headerDiv,'click',function(tb){
ta(rb);});


rb.eventListen(rb.headerDiv,'mousedown',
function(tb){

if(tb.which===2){
fa(rb,true);
return false;}});



var sb=k.scry(rb.headerDiv,'.close-button')[0];
rb.eventListen(sb,'click',function(tb){
fa(rb,true);
return false;});}


za[ib]=rb;
ab.push(ib);
rb.updatePresenceInfo();
ra();


x.getInstance(rb.input).subscribe
('resize',ra.bind(this));


jb(rb,true);};





if(nb){
pb(ob);}else 

n.renderChatTabTitle(ib,pb);};



r.dispatchWorkerAsyncFunctionCall
('FbdChatDataWorker',
'fetchThreadForLoad',
[ib],
kb.bind(this));}


function ia(ib,jb){
aa.debug('messages_received',jb);

oa(jb,function(){
aa.debug('launched_new_conversations');
ga(jb,function(lb,mb){
lb.handleMessagesReceived(mb);
lb.showNewMessageToasts(mb);});


wa();});


for(var kb in jb)
jb[kb].forEach(function(lb){
r.dispatchWorkerAsyncFunctionCall
("FbdChatDataWorker",
"setMessageActionStatusTimeout",
[lb],
ha.curry(kb,
function(mb,nb){
aa.debug('got_or_created_failed_conversation');

q.showChatWindow(true);
ta(mb);
if(!nb)
mb.refreshHistory();}));});}






function ja(ib,jb){
aa.debug('messages_reordered',jb);
ga(jb,function(kb,lb){
kb.handleMessagesReordered(lb);});}



function ka(ib,jb){
aa.debug('messages_updated',jb);

ga(jb,function(kb,lb){
kb.handleMessagesUpdated(lb);});}



function la(ib,jb){
var kb=za[jb.thread_id];
if(kb)
kb.handleIndicatorStateChanged(jb);}



function ma(ib,jb){
ea();}


function na(ib,jb){
ga(jb,function(kb,lb){
kb.handleThreadsUpdated(lb);});


wa();}


function oa(ib,jb){




var kb=Object.keys(ib).length;
for(var lb in ib){
var mb=ib[lb];
r.dispatchWorkerFunctionCall
("FbdChatDataWorker",
"isAThreadOfInterest",

[l.user,
lb,
mb],

function(nb){
if(nb){
ha(lb,
function(ob,pb){

aa.debug('got_or_created_conversation');
q.showChatWindow(false);
if(!s.getCurrentConversation())

ta(ob);

if(!q.isChatWindowActive()){
var qb="New Messages";
if(!s.pendingUnseenMessage){
s.pendingUnseenMessage=true;
qb="New Message";}

q.setChatWindowTitle(qb);}

kb--;
da
(kb,
function(){
jb();
var rb=za[lb];

if(rb===s.getCurrentConversation())
s.playNewMessageSound();}.

bind(this));});}else{


aa.debug('not_a_thread_of_interest',lb);
kb--;
da(kb,jb);}}.

bind(this));}}



function pa(ib){
for(var jb in za)
fa(za[jb],ib);}



function qa(){
var ib=s.getCurrentConversation(),
jb=ib?ib.id:null;

r.dispatchWorkerFunctionCall
('FbdChatDataWorker',
'fetchServerIDs',
[Object.keys(za)],
function(kb){

var lb=
{user:l.user,
threadOrder:ab,
currentThread:jb,
serverIds:kb};


q.setSetting
(p.openThreads,
JSON.stringify(lb));});}



function ra(){
s.resize(bb.offsetHeight);
sa();}


function sa(){
var ib=ab.length;
if(ib===0)
return;


var jb=za[ab[0]];
if(jb.headerDiv){
var kb=
k.scry(jb.headerDiv,'.conversation-header-edge')[0],

lb=kb.offsetWidth,
mb=t.getWindowWidth(),
nb=
Math.max(0,mb-(ib+1)*lb),

ob=0,
pb=null;
for(var qb in za){
var rb=Math.min
(120,
Math.round(nb/(ib-ob)));
za[qb].headerDiv.style.width=rb+"px";
nb-=rb;
ob++;

if(!pb||rb<pb)
pb=rb;}



j.conditionClass(cb,'narrow-tabs',pb<70);}}



function ta(ib){
aa.debug('show_conversation');
var jb=s.getCurrentConversation();
if(!jb||jb.id!==ib.id){
var kb=jb;
s.setCurrentConversation(ib);
jb=ib;

if(kb)
kb.deactivate();


k.empty(db);
db.appendChild(ib.contentDiv);
ra();

qa();}


if(jb){
jb.activate();
jb.scrollMessagesToBottom();}


q.setChatWindowTitle(ib.name);}



function ua(ib){

if(ib>=0&&
ib<ab.length){
var jb=ab[ib];
ta(za[jb]);}}



function va(ib){
var jb=s.getCurrentConversation();
if(!jb)
return;


var kb=jb.id,
lb=ab.indexOf(kb)+ib;
if(lb>ab.length-1){
lb=0;}else
if(lb<0)
lb=ab.length-1;


var mb=ab[lb];
ta(za[mb]);}


function wa(){

if(!('setUnreadCount' in q))
return;

r.dispatchWorkerAsyncFunctionCall
("FbdChatDataWorker",
"fetchUnreadThreadsCount",
[Object.keys(za)],
function(ib){
q.setUnreadCount(ib);});}



function xa(){
for(var ib in za){
var jb=za[ib];
jb.updatePresenceInfo();}}



function ya(ib,jb,kb){
delete kb.chatManagerForwarded;
ib(jb,kb);}



var za={},
ab=[],


bb=y('conversation-list-frame'),
cb=y('conversation-list'),
db=y('conversation-content-frame');

ea();


g.listen(document,'keydown',s.onKeyDown);




h.subscribe(p.newConversation,ba);
h.subscribe(p.newThread,ca);

h.subscribe
(p.chatManagerPrefix+p.newConversation,
ba);
h.subscribe
(p.chatManagerPrefix+p.newThread,
ca);


h.subscribe
(p.chatManagerPrefix+
i.ON_AVAILABILITY_CHANGED,
xa);



h.subscribe(p.windowResized,ra);
h.subscribe(u.windowClosed,
pa.bind(this,true));

h.subscribe(p.chatWindowActivated,
s.chatWindowActivated);


h.subscribe
(p.mqttConnectionChanged,
ma);

h.subscribe(p.closeConversation,
function(ib,jb){
if(za[jb])
fa(za[jb],true);});




h.subscribe
(p.chatManagerPrefix+'threads-updated',
ya.bind(this,na));
h.subscribe
(p.chatManagerPrefix+'messages-received',
ya.bind(this,ia));
h.subscribe
(p.chatManagerPrefix+'messages-reordered',
ya.bind(this,ja));
h.subscribe
(p.chatManagerPrefix+'messages-updated',
ya.bind(this,ka));
h.subscribe
(p.chatManagerPrefix+'indicator-state-changed',
ya.bind(this,la));


h.subscribe
(p.chatCommandCloseCurrentTab,
function(){
fa(s.getCurrentConversation(),true);});


h.subscribe
(p.chatCommandSwitchToNextTab,
function(){va(1);});

h.subscribe
(p.chatCommandSwitchToPreviousTab,
function(ib,jb){va(-1);});

h.subscribe
(p.chatCommandSwitchToLastTab,
function(ib,jb){
ua(ab.length-1);});


h.subscribe
(p.chatCommandSwitchToTabIndex,
function(ib,jb){
ua(jb);});


w.subscribe
('privacy-changed',
ea);


var eb=null;

try{eb=JSON.parse(q.getSetting(p.openThreads));}catch(
fb){}

if(eb&&
eb.user===l.user&&
eb.currentThread){


var gb=eb.threadOrder.length;
eb.threadOrder.forEach(function(ib){
r.dispatchWorkerAsyncFunctionCall
('FbdChatDataWorker',
'fetchPersistedConversationForReopen',
[ib,eb.serverIds[ib]],
function(){
ha(ib,function(jb,kb){

da(--gb,function(){

var lb=eb.currentThread;
if(!za[lb])
eb.threadOrder.some(function(mb){
lb=mb;
return za[lb];});





if(za[lb]){
ta(za[lb]);


q.showChatWindow(false);}});});});});}









q.startHeartbeat();




var hb={};
e.exports=hb;});

/** js/desktop/client/socialfox/chat/SocialFoxChat.js */
__d("SocialFoxChat",["array-extensions","Event","Arbiter","CSS","Env","FbdChatPresence","FbdConversation","FbdConstants","FbdCore","FbdChatShared","FbdChatRenderer","FbdExternal","FbdFunctionDispatcher","FbdUtils","SocialFoxConstants","FbdWindowMouseTracker","JSLogger","PresencePrivacy","TextAreaControl","URI","$","tx"],function(a,b,c,d,e,f){



b('array-extensions');
var g=b('Event'),

h=b('Arbiter'),
i=b('CSS'),
j=b('Env'),
k=b('FbdChatPresence'),
l=b('FbdConversation'),
m=b('FbdConstants'),
n=b('FbdCore'),
o=b('FbdChatShared'),
p=b('FbdChatRenderer'),
q=b('FbdExternal'),
r=b('FbdFunctionDispatcher'),
s=b('FbdUtils'),
t=b('SocialFoxConstants'),
u=b('FbdWindowMouseTracker'),
v=b('JSLogger'),
w=b('PresencePrivacy'),
x=b('TextAreaControl'),
y=b('URI'),

z=b('$'),
aa=b('tx'),

ba=navigator.mozSocial.isVisible,
ca=ba,
da=v.create('socialfox');

h.subscribe(m.recyclePages,
function(){
q.recycle();});


i.hide(z('conversation-list-frame'));
h.subscribe
(m.chatWindowActivated,
function(wa,xa){
if(ta&&xa.thread_id==ta.id){
o.chatWindowActivated();
n.inform(t.appIdleStateChanged,false);}});



g.listen(a,t.contentFrameShownEvent,
function(){
ca=ba;
ba=true;
n.inform(t.appIdleStateChanged,false);
na(ta);});

g.listen(a,t.contentFrameHiddenEvent,
function(){
if(ta){
ca=ba;
ba=false;
ta.deactivate();}});



function ea(wa,xa){
if(!ta)
return;


ta.cleanup();
ta=null;}


g.listen(document,'focus',function(){
o.chatWindowActivated();
n.inform(t.appIdleStateChanged,false);
na(ta);});


g.listen(document,'blur',function(){
ta.deactivate();});


g.listen(document,'keydown',o.onKeyDown);


h.subscribe
(m.chatCommandCloseCurrentTab,
function(){
ea(o.getCurrentConversation(),true);
window.close();});


function fa(wa){
var xa='fbid:'+j.user;
if(wa&&wa===xa)
return;


if(!ta.isActive){
var ya=document.createEvent('CustomEvent');
ya.initCustomEvent
(t.chatActivity,
true,
true,
{});
document.dispatchEvent(ya);
o.playNewMessageSound();}}



function ga(wa,xa){
da.debug('messages_received',xa);
var ya=xa[ta.id];
if(ya){
ta.handleMessagesReceived(ya);
ya.forEach(function(za){
fa(za.author);});

oa();}}



function ha(wa,xa){
da.debug('messages_reordered',xa);

if(xa[ta.id])
ta.handleMessagesReordered(xa[ta.id]);}



function ia(wa,xa){
da.debug('messages_updated',xa);

if(xa[ta.id])
ta.handleMessagesUpdated(xa[ta.id]);}



function ja(wa,xa){
k.updateOnlineStatus();
pa();}


function ka(wa,xa){
if(xa[ta.id])
ta.handleThreadsUpdated(xa[ta.id]);}



function la(wa){
ea(ta,wa);}


function ma(){
o.resize(0);}


function na(wa){
da.debug('show_conversation');
sa.appendChild(wa.contentDiv);

if(ba!==ca||document.hasFocus()){
o.chatWindowActivated();
n.inform(t.appIdleStateChanged,false);}

ma();
ta.scrollMessagesToBottom();
oa();
ma();}


function oa(){
if(ba!==ca&&navigator.mozSocial.isVisible||
document.hasFocus())
return;

ta.fetchUnreadCount(function(wa){
var xa=ta.name;
if(wa>0)
xa=aa._("{name} ({number})",
{name:ta.name,number:wa});

q.setChatWindowTitle(xa);});}



function pa(){
if(ta)
ta.updatePresenceInfo();}



function qa(wa,xa,ya){
delete ya.chatManagerForwarded;
wa(xa,ya);}



function ra(){
k.updateOnlineStatus();
pa();}



var sa=z('conversation-content-frame');


h.subscribe(u.windowClosed,
la.bind(this,true));

h.subscribe
(m.chatManagerPrefix+
m.mqttPrefix+m.mqttPresenceUpdates,
function(wa,xa){
if(xa&&xa.list)
xa.list.forEach(function(ya){
var za=ya.u,
ab=ta.id.split(':')[1];
if(za==ab)
s.updateFavicon(ya.p);});});




h.subscribe
(m.chatManagerPrefix+m.mqttConnectionChanged,
ja);



h.subscribe
(m.chatManagerPrefix+'threads-updated',
qa.bind(this,ka));
h.subscribe
(m.chatManagerPrefix+'messages-received',
qa.bind(this,ga));
h.subscribe
(m.chatManagerPrefix+'messages-reordered',
qa.bind(this,ha));
h.subscribe
(m.chatManagerPrefix+'messages-updated',
qa.bind(this,ia));

h.subscribe
(m.chatManagerPrefix+'indicator-state-changed',
qa.bind(this,function(wa,xa){
if(ta)
if(xa.thread_id===ta.id)
ta.handleIndicatorStateChanged(xa);}));




h.subscribe
(m.chatCommandCloseCurrentTab,
function(){ea(ta,true);});

var ta=null,
ua=y().getQueryData(),

va=ua.thread_id;


r.dispatchWorkerAsyncFunctionCall
('FbdChatDataWorker',
'fetchThreadForLoad',
[va],
function(wa,xa,ya,za){
var ab=function(bb){
ta=new l
(wa,
bb.toString(),
ya,
ea);

n.inform('get-privacy-data',{id:ta.id});
o.setCurrentConversation(ta);
ta.updatePresenceInfo();
ma();

x.getInstance(ta.input).subscribe('resize',
ma.bind(this));

na(ta);
ra();
if(document.hasFocus()){
o.chatWindowActivated();
n.inform(t.appIdleStateChanged,false);}else{

ta.deactivate();
fa(wa.snippet_sender);}};






if(ya){
ab(za);}else 

p.renderChatTabTitle(va,ab);}.

bind(this));


w.subscribe
('privacy-changed',
ra);

e.exports={};});
