typ
event “long poll” /pull
(long polling). A small study showed that the event is really sent out for each chat , even if the recipient did not open it and never received it.__d(name, dependencies, factory)
. There are also require
and requireLazy
for importing modules.__d(
and see the list of modules available for import. For the main page there are only 3000 modules.<ChatTabComposerContainer />
and <MercuryLastMessageIndicator />
.__d('ChatTyping
in the code base React finds two modules: ChatTypingIndicator.react.js
and ChatTypingIndicators.react.js
. This is exactly what we need, says Kirzenberg. He notices that some modules are loaded as needed, so ChatTypingIndicators.react.js
can only be found from the second time. function() { var k = c('MercuryThreadInformer').getForFBID(this.props.viewer) , l = c('MercuryTypingReceiver').getForFBID(this.props.viewer); this._subscriptions = new (c('SubscriptionsHandler'))(); this._subscriptions.addSubscriptions( l.addRetroactiveListener( 'state-changed', this.typingStateChanged ), k.subscribe( 'messages-received', this.messagesReceived ) ); },
c('MercuryTypingReceiver')
. > MercuryTypingReceiver.getForFBID // function (i){var j=this._getInstances();if(!j[i])j[i]=new this(i);return j[i];} > MercuryTypingReceiver.get // function (){return this.getForFBID(c('CurrentUser').getID());}
MercuryThreads
studying the code in more detail, he found two more useful modules MercuryThreads
and ShortProfiles
. The first one gets all the information about the Messenger thread by its ID, the second one does the same for the profile. function getUserId(fbid) { return fbid.split(':')[1]; } requireLazy( ['MercuryTypingReceiver', 'MercuryThreads', 'ShortProfiles'], (MercuryTypingReceiver, MercuryThreads, ShortProfiles) => { MercuryTypingReceiver .get() .addRetroactiveListener('state-changed', onStateChanged); // Called every time a user starts or stops typing in a thread function onStateChanged(state) { // State is a dictionary that maps thread ids to the list of the // currently typing users ids' const threadIds = Object.keys(state); // Walk through all threads in order to retrieve a list of all // user ids const userIds = threadIds.reduce( (res, threadId) => res.concat(state[threadId].map(getUserId)), [] ); MercuryThreads.get().getMultiThreadMeta(threadIds, threads => { ShortProfiles.getMulti(userIds, users => { // Now that we've retrieved all the information we need // about the threads and the users, we send it to the // Chrome application to process and display it to the user. window.postMessage({ type: 'update', threads, users, state, }, '*'); }); }); } } );
Source: https://habr.com/ru/post/302506/
All Articles