@ -5,216 +5,194 @@
@@ -5,216 +5,194 @@
function requestDMsnippetList ( dmThreadList ) {
var followList = [ ] ;
for ( var i = 0 ; i < followingUsers . length ; i ++ ) {
for ( var i = 0 ; i < followingUsers . length ; i ++ )
followList . push ( { username : followingUsers [ i ] } ) ;
}
for ( var i = 0 ; i < groupChatAliases . length ; i ++ ) {
for ( var i = 0 ; i < groupChatAliases . length ; i ++ )
followList . push ( { username : groupChatAliases [ i ] } ) ;
}
twisterRpc ( "getdirectmsgs" , [ defaultScreenName , 1 , followList ] ,
function ( req , ret ) { processDMsnippet ( ret , dmThreadList ) ; } , dmThreadList ,
function ( req , ret ) { console . log ( "ajax error:" + ret ) ; } , null ) ;
twisterRpc ( 'getdirectmsgs' , [ defaultScreenName , 1 , followList ] ,
function ( req , ret ) { processDMsnippet ( ret , dmThreadList ) ; } , dmThreadList ,
function ( req , ret ) { console . log ( 'ajax error:' + ret ) ; } , null
) ;
}
function processDMsnippet ( dmUsers , dmThreadList ) {
dmThreadList . empty ( ) ;
for ( var u in dmUsers ) {
if ( dmUsers . hasOwnProperty ( u ) ) {
// convert snipped to html and add it to date-sorted list
var dmItem = dmDataToSnippetItem ( dmUsers [ u ] [ 0 ] , u ) ;
var timeDmItem = parseInt ( dmItem . attr ( "data-time" ) ) ;
var existingItems = dmThreadList . children ( ) ;
var j = 0 ;
for ( j = 0 ; j < existingItems . length ; j ++ ) {
var streamItem = existingItems . eq ( j ) ;
var timeExisting = streamItem . attr ( "data-time" ) ;
if ( timeExisting == undefined ||
timeDmItem > parseInt ( timeExisting ) ) {
// this post in stream is older, so post must be inserted above
streamItem . before ( dmItem ) ;
break ;
}
}
if ( j == existingItems . length ) {
dmThreadList . append ( dmItem ) ;
for ( var u in dmUsers ) {
// convert snipped to html and add it to date-sorted list
var dmItem = dmDataToSnippetItem ( dmUsers [ u ] [ 0 ] , u ) ;
var timeDmItem = parseInt ( dmItem . attr ( 'data-time' ) ) ;
var existingItems = dmThreadList . children ( ) ;
for ( var j = 0 ; j < existingItems . length ; j ++ ) {
var streamItem = existingItems . eq ( j ) ;
var timeExisting = streamItem . attr ( 'data-time' ) ;
if ( typeof timeExisting === 'undefined' || timeDmItem > parseInt ( timeExisting ) ) {
// this post in stream is older, so post must be inserted above
streamItem . before ( dmItem ) ;
break ;
}
}
if ( j === existingItems . length )
dmThreadList . append ( dmItem ) ;
}
$ . MAL . dmThreadListLoaded ( ) ;
}
function openDmConversation ( dm _screenname , dmTitleName , dmConversation ) {
if ( dm _screenname . length && dm _screenname [ 0 ] === '*' )
getGroupChatName ( dm _screenname , dmTitleName ) ;
else
getFullname ( dm _screenname , dmTitleName ) ;
dmConversation . attr ( "data-dm-screen-name" , dm _screenname ) ;
var dmConvo = dmConversation . find ( ".direct-messages-thread" ) ;
dmConvo . empty ( ) ;
requestDmConversationModal ( dmConvo , dm _screenname ) ;
}
function requestDmConversationModal ( dmConvo , dm _screenname ) {
if ( dmConvo . parents ( ".modal-blackout" ) . css ( "display" ) == 'none' )
return ;
requestDmConversation ( dmConvo , dm _screenname ) ;
setTimeout ( function ( ) { requestDmConversationModal ( dmConvo , dm _screenname ) ; } , 1000 ) ;
function requestDmConversationModal ( postboard , dm _screenname ) {
if ( postboard . is ( 'html *' ) ) {
requestDmConversation ( postboard , dm _screenname ) ;
setTimeout ( requestDmConversationModal , 1000 , postboard , dm _screenname ) ;
}
}
function requestDmConversation ( dmConvo , dm _screenname ) {
function requestDmConversation ( postboard , dm _screenname ) {
var since _id = undefined ;
var oldItems = dmConvo . children ( ) ;
if ( oldItems . length ) {
since _id = parseInt ( oldItems . eq ( oldItems . length - 1 ) . attr ( "data-id" ) ) ;
}
var oldItems = postboard . children ( ) ;
if ( oldItems . length )
since _id = parseInt ( oldItems . eq ( oldItems . length - 1 ) . attr ( 'data-id' ) ) ;
var userDmReq = [ { username : dm _screenname } ] ;
if ( typeof since _id !== 'undefined' )
userDmReq [ 0 ] . since _id = since _id ;
var userDmReq = [ { username : dm _screenname } ] ;
if ( since _id != undefined ) userDmReq [ 0 ] . since _id = since _id ;
var count = 100 ;
twisterRpc ( "getdirectmsgs" , [ defaultScreenName , count , userDmReq ] ,
function ( args , ret ) { processDmConversation ( args . dmConvo , args . dmUser , ret ) ; } ,
{ dmConvo : dmConvo , dmUser : dm _screenname } ,
function ( arg , ret ) { var msg = ( "message" in ret ) ? ret . message : ret ;
alert ( polyglot . t ( "ajax_error" , { error : msg } ) ) ; } , null ) ;
twisterRpc ( 'getdirectmsgs' , [ defaultScreenName , count , userDmReq ] ,
function ( args , ret ) { processDmConversation ( args . postboard , args . dm _screenname , ret ) ; } ,
{ postboard : postboard , dm _screenname : dm _screenname } ,
function ( arg , ret ) {
var msg = ( ret . message ) ? ret . message : ret ;
alert ( polyglot . t ( 'ajax_error' , { error : msg } ) ) ;
} , null
) ;
}
function processDmConversation ( dmConvo , dm _screenname , dmData ) {
function processDmConversation ( postboard , dm _screenname , dmData ) {
var lastId = undefined ;
if ( dm _screenname in dmData ) {
if ( dmData [ dm _screenname ] ) {
var dmList = dmData [ dm _screenname ] ;
if ( dmList . length ) {
for ( var i = 0 ; i < dmList . length ; i ++ ) { ;
var dmItem = dmDataToConversationItem ( dmList [ i ] , defaultScreenName , dm _screenname ) ;
dmItem . attr ( "data-id" , dmList [ i ] . id ) ;
dmConvo . append ( dmItem ) ;
if ( dmList . length ) {
for ( var i = 0 ; i < dmList . length ; i ++ ) {
var dmItem = dmDataToConversationItem ( dmList [ i ] , defaultScreenName , dm _screenname )
. attr ( 'data-id' , dmList [ i ] . id )
. appendTo ( postboard )
;
lastId = dmList [ i ] . id ;
}
$ . MAL . dmChatListLoaded ( dmConvo ) ;
$ . MAL . dmChatListLoaded ( postboard ) ;
}
}
if ( lastId != undefined ) {
if ( typeof lastId !== 'undefined' )
resetNewDMsCountForUser ( dm _screenname , lastId ) ;
}
}
function directMsgSubmit ( e )
{
function directMsgSubmit ( e ) {
e . stopPropagation ( ) ;
e . preventDefault ( ) ;
var $this = $ ( this ) ;
var $replyText = $this . closest ( ".post-area-new" ) . find ( "textarea" ) ;
var $dmConversation = $ ( ".directMessages" ) ;
var replyText = $ ( this ) . closest ( '.post-area-new' ) . find ( 'textarea' ) ;
newDirectMsg ( $ replyText. val ( ) , $dmConversation . attr ( "data-dm-screen-name" ) ) ;
newDirectMsg ( replyText . val ( ) , $ ( '.directMessages' ) . attr ( 'data-dm-screen-name' ) ) ;
$ replyText. val ( "" ) ;
replyText . val ( '' ) ;
}
function newDirectMsg ( msg , dm _screenname ) {
if ( lastPostId != undefined ) {
var paramsOrig = [ defaultScreenName , lastPostId + 1 , dm _screenname , msg ]
var paramsOpt = paramsOrig
var copySelf = ( $ . Options . dmCopySelf . val === 'enable' )
if ( copySelf && dm _screenname [ 0 ] !== '*' ) {
if ( typeof lastPostId !== 'undefined' ) {
var paramsOrig = [ defaultScreenName , lastPostId + 1 , dm _screenname , msg ] ;
var paramsOpt = paramsOrig ;
var copySelf = $ . Options . dmCopySelf . val === 'enable' ;
if ( copySelf && dm _screenname [ 0 ] !== '*' )
paramsOpt = paramsOrig . concat ( true )
}
twisterRpc ( "newdirectmsg" , paramsOpt ,
function ( arg , ret ) {
incLastPostId ( ) ;
if ( arg . copySelf ) incLastPostId ( ) ;
} , { copySelf : copySelf } ,
function ( arg , ret ) {
// fallback for older twisterd (error: no copy_self parameter)
twisterRpc ( "newdirectmsg" , arg . paramsOrig ,
function ( arg , ret ) { incLastPostId ( ) ; } , null ,
function ( arg , ret ) {
var msg = ( "message" in ret ) ? ret . message : ret ;
alert ( "Ajax error: " + msg ) ;
} , null ) ;
} , { paramsOrig : paramsOrig }
twisterRpc ( 'newdirectmsg' , paramsOpt ,
function ( arg , ret ) {
incLastPostId ( ) ;
if ( arg . copySelf )
incLastPostId ( ) ;
} , { copySelf : copySelf } ,
function ( arg , ret ) {
// fallback for older twisterd (error: no copy_self parameter)
twisterRpc ( 'newdirectmsg' , arg . paramsOrig ,
function ( arg , ret ) { incLastPostId ( ) ; } , null ,
function ( arg , ret ) {
var msg = ( ret . message ) ? ret . message : ret ;
alert ( 'Ajax error: ' + msg ) ;
} , null
) ;
} , { paramsOrig : paramsOrig }
) ;
} else {
alert ( polyglot . t ( "Internal error: lastPostId unknown (following yourself may fix!)" ) ) ;
}
} else
alert ( polyglot . t ( 'Internal error: lastPostId unknown (following yourself may fix!)' ) ) ;
}
//dispara o modal de direct messages
function directMessagesPopup ( )
{
if ( ! defaultScreenName )
{
alert ( polyglot . t ( "You have to log in to use direct messages." ) ) ;
// dispara o modal de direct messages
function directMessagesPopup ( ) {
if ( ! defaultScreenName ) {
alert ( polyglot . t ( 'You have to log in to use direct messages.' ) ) ;
return ;
}
var directMessagesClass = "directMessages" ;
openModal ( directMessagesClass ) ;
var directMessagesContent = $ ( ".direct-messages-template" ) . html ( ) ;
$ ( directMessagesContent ) . clone ( ) . appendTo ( ".directMessages .modal-content" ) ;
//título do modal
$ ( ".directMessages h3" ) . text ( polyglot . t ( "Direct Messages" ) ) ;
modal = openModal ( {
classAdd : 'directMessages' ,
content : $ ( '.direct-messages-template' ) . children ( ) . clone ( true ) ,
title : polyglot . t ( 'Direct Messages' )
} ) ;
requestDMsnippetList ( $ ( ".directMessages" ) . find ( ".direct-messages-list" ) ) ;
$ ( '.mark-all-as-read' ) . css ( 'display' , 'inline' ) ;
$ ( '.mark-all-as-read' ) . attr ( 'title' , polyglot . t ( "Mark all as read" ) ) ;
requestDMsnippetList ( modal . content . find ( '.direct-messages-list' ) ) ;
$ ( '.mark-all-as-read' ) . on ( 'click' , function ( ) {
for ( var k in _newDMsPerUser ) {
_newDMsPerUser [ k ] = 0 ;
}
saveDMsToStorage ( ) ;
$ . MAL . updateNewDMsUI ( getNewDMsCount ( ) ) ;
} ) ;
modal . self . find ( '.mark-all-as-read' )
. css ( 'display' , 'inline' )
. attr ( 'title' , polyglot . t ( 'Mark all as read' ) )
. on ( 'click' , function ( ) {
for ( var user in _newDMsPerUser ) {
_newDMsPerUser [ user ] = 0 ;
}
saveDMsToStorage ( ) ;
$ . MAL . updateNewDMsUI ( getNewDMsCount ( ) ) ;
} )
;
}
function openDmWithUserModal ( dm _screenname )
{
if ( ! defaultScreenName ) {
alert ( polyglot . t ( "You have to log in to use direct messages." ) ) ;
function openDmWithUserModal ( dm _screenname ) {
if ( ! defaultScreenName ) {
alert ( polyglot . t ( 'You have to log in to use direct messages.' ) ) ;
return ;
}
var directMessagesClass = "directMessages" ;
openModal ( directMessagesClass ) ;
modal = openModal ( {
classAdd : 'directMessages' ,
content : $ ( '.messages-thread-template' ) . children ( ) . clone ( true ) ,
title : polyglot . t ( 'direct_messages_with' , { username : '<span>' + dm _screenname + '</span>' } )
} ) ;
//para poder exibir a thread selecionada...
var retweetContent = $ ( ".messages-thread-template" ) . html ( ) ;
$ ( retweetContent ) . clone ( ) . appendTo ( ".directMessages .modal-content" ) . hide ( ) . fadeIn ( "fast" ) ;
modal . self . attr ( 'data-dm-screen-name' , dm _screenname ) ;
var dmTitle = $ ( ".directMessages h3" ) ;
dmTitle . html ( polyglot . t ( "Direct messages with" ) + " <span></span>" ) ;
dmTitle = dmTitle . find ( "span" ) ;
var dmConversation = $ ( ".directMessages" ) ;
openDmConversation ( dm _screenname , dmTitle , dmConversation ) ;
if ( dm _screenname . length && dm _screenname [ 0 ] === '*' )
getGroupChatName ( dm _screenname , modal . self . find ( '.modal-header h3 span' ) ) ;
else
getFullname ( dm _screenname , modal . self . find ( '.modal-header h3 span' ) ) ;
var $dmForm = $ ( ".dm-form-template" ) . children ( ) . clone ( true ) ;
$dmForm . addClass ( "open" ) ;
$dmForm . appendTo ( ".directMessages .modal-wrapper" ) . hide ( ) . fadeIn ( "fast" ) ;
}
requestDmConversationModal ( modal . self . find ( '.direct-messages-thread' ) . empty ( ) , dm _screenname ) ;
$ ( '.dm-form-template' ) . children ( ) . clone ( true )
. addClass ( 'open' ) . appendTo ( modal . content ) . fadeIn ( 'fast' ) ;
}
function initInterfaceDirectMsg ( ) {
$ ( '.direct-messages' ) . attr ( 'href' , '#directmessages' ) ;
$ ( '.userMenu-messages a' ) . attr ( 'href' , '#directmessages' ) ;
$ ( ".direct-messages" ) . attr ( "href" , "#directmessages" ) ;
$ ( ".userMenu-messages a" ) . attr ( "href" , "#directmessages" ) ;
$ ( "#dm-snippet-template" ) . bind ( "click" , function ( ) {
window . location . hash = '#directmessages?user=' + $ ( this ) . attr ( "data-dm-screen-name" ) ;
} ) ;
$ ( ".dm-submit" ) . click ( directMsgSubmit ) ;
$ ( ".direct-messages-with-user" ) . bind ( "click" , function ( ) {
window . location . hash = '#directmessages?user=' + $ ( this ) . closest ( "[data-screen-name]" ) . attr ( "data-screen-name" ) ;
} ) ;
$ ( '#dm-snippet-template' ) . on ( 'click' , function ( ) {
window . location . hash = '#directmessages?user=' + $ ( this ) . attr ( 'data-dm-screen-name' ) ;
} ) ;
$ ( '.dm-submit' ) . on ( 'click' , directMsgSubmit ) ;
$ ( '.direct-messages-with-user' ) . on ( 'click' , function ( ) {
window . location . hash = '#directmessages?user=' +
$ ( this ) . closest ( '[data-screen-name]' ) . attr ( 'data-screen-name' ) ;
} ) ;
}