Skip to content

Commit 2c11386

Browse files
committed
Removed pullMessage, ping
1 parent d074133 commit 2c11386

File tree

2 files changed

+5
-210
lines changed

2 files changed

+5
-210
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
private_*
12

23
## Ignore Visual Studio temporary files, build results, and
34
## files generated by popular Visual Studio add-ons.

fbchat-sharp/API/Client.cs

Lines changed: 4 additions & 210 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,10 @@ public class Client
4444
/// Mqtt client for receiving messages
4545
private IMqttClient mqttClient;
4646

47-
private string _sticky = null;
48-
private string _pool = null;
49-
private int _sequence_id = 0;
5047
private int _mqtt_sequence_id = 0;
5148
private string _sync_token = null;
5249
private string _default_thread_id = null;
5350
private ThreadType? _default_thread_type = null;
54-
private int _pull_channel = 0;
5551
private bool _markAlive = false;
5652
private Dictionary<string, FB_ActiveStatus> _buddylist = null;
5753

@@ -70,14 +66,10 @@ public class Client
7066
/// </summary>
7167
public Client()
7268
{
73-
this._sticky = null;
74-
this._pool = null;
75-
this._sequence_id = 0;
7669
this._mqtt_sequence_id = 0;
7770
this._sync_token = null;
7871
this._default_thread_id = null;
7972
this._default_thread_type = null;
80-
this._pull_channel = 0;
8173
this._markAlive = true;
8274
this._buddylist = new Dictionary<string, FB_ActiveStatus>();
8375
}
@@ -2715,40 +2707,6 @@ public async Task unmuteThreadMentions(string thread_id = null)
27152707

27162708
#region LISTEN METHODS
27172709

2718-
private async Task _ping(CancellationToken cancellationToken = default(CancellationToken))
2719-
{
2720-
var data = new Dictionary<string, object>() {
2721-
{ "seq", this._sequence_id},
2722-
{ "channel", "p_" + this._uid },
2723-
{ "clientid", this._state._client_id },
2724-
{ "partition", -2},
2725-
{ "cap", 0},
2726-
{ "uid", this._uid},
2727-
{ "sticky_token", this._sticky },
2728-
{ "sticky_pool", this._pool },
2729-
{ "viewer_uid", this._uid },
2730-
{ "state", "active" },
2731-
};
2732-
var j = await this._get(
2733-
string.Format("https://{0}-edge-chat.facebook.com/active_ping", this._pull_channel), data, cancellationToken);
2734-
}
2735-
2736-
private async Task<JToken> _pullMessage(CancellationToken cancellationToken = default(CancellationToken))
2737-
{
2738-
/*Call pull api with seq value to get message data.*/
2739-
var data = new Dictionary<string, object>() {
2740-
{ "seq", this._sequence_id },
2741-
{ "msgs_recv", 0 },
2742-
{ "sticky_token", this._sticky },
2743-
{ "sticky_pool", this._pool },
2744-
{ "clientid", this._state._client_id },
2745-
{ "state", this._markAlive ? "active" : "offline" },
2746-
};
2747-
2748-
return await this._get(
2749-
string.Format("https://{0}-edge-chat.facebook.com/pull", this._pull_channel), data, cancellationToken);
2750-
}
2751-
27522710
private Tuple<string, ThreadType> getThreadIdAndThreadType(JToken msg_metadata)
27532711
{
27542712
/*Returns a tuple consisting of thread ID and thread type*/
@@ -3369,136 +3327,6 @@ await this.onPendingMessage(
33693327
await this.onUnknownMesssageType(msg: m);
33703328
}
33713329

3372-
private async Task _parseMessage(JToken content)
3373-
{
3374-
/*Get message and author name from content. May contain multiple messages in the content.*/
3375-
this._sequence_id = content.get("seq")?.Value<int>() ?? _sequence_id;
3376-
3377-
if (content.get("lb_info") != null)
3378-
{
3379-
this._sticky = content.get("lb_info")?.get("sticky")?.Value<string>();
3380-
this._pool = content.get("lb_info")?.get("pool")?.Value<string>();
3381-
}
3382-
3383-
if (content.get("batches") != null)
3384-
{
3385-
foreach (var batch in content.get("batches"))
3386-
await this._parseMessage(batch);
3387-
}
3388-
3389-
if (content.get("ms") == null) return;
3390-
3391-
foreach (var m in content.get("ms"))
3392-
{
3393-
var mtype = m.get("type").Value<string>();
3394-
try
3395-
{
3396-
// Things that directly change chat
3397-
if (mtype == "delta")
3398-
{
3399-
await this._parseDelta(m);
3400-
}
3401-
// Inbox
3402-
else if (mtype == "inbox")
3403-
{
3404-
await this.onInbox(unseen: m.get("unseen").Value<int>(), unread: m.get("unread").Value<int>(), recent_unread: m.get("recent_unread").Value<int>(), msg: m);
3405-
}
3406-
// Typing
3407-
else if (mtype == "typ" || mtype == "ttyp")
3408-
{
3409-
var author_id = m.get("from")?.Value<string>();
3410-
var thread_id = m.get("thread_fbid")?.Value<string>();
3411-
var thread_type = ThreadType.USER;
3412-
if (thread_id != null)
3413-
{
3414-
thread_type = ThreadType.GROUP;
3415-
}
3416-
else
3417-
{
3418-
thread_type = ThreadType.USER;
3419-
if (author_id == this._uid)
3420-
thread_id = m.get("to")?.Value<string>();
3421-
else
3422-
thread_id = author_id;
3423-
}
3424-
var typing_status = (TypingStatus)(m.get("st")?.Value<int>());
3425-
await this.onTyping(
3426-
author_id: author_id,
3427-
status: typing_status,
3428-
thread_id: thread_id,
3429-
thread_type: thread_type,
3430-
msg: m
3431-
);
3432-
}
3433-
// Delivered
3434-
3435-
// Seen
3436-
//else if (mtype == "m_read_receipt":
3437-
//
3438-
// this.onSeen(m.get('realtime_viewer_fbid'), m.get('reader'), m.get('time'))
3439-
3440-
else if (mtype == "jewel_requests_add")
3441-
{
3442-
var from_id = m.get("from")?.Value<string>();
3443-
await this.onFriendRequest(from_id: from_id, msg: m);
3444-
}
3445-
3446-
// Happens on every login
3447-
else if (mtype == "qprimer")
3448-
await this.onQprimer(ts: m.get("made")?.Value<long>() ?? 0, msg: m);
3449-
3450-
// Is sent before any other message
3451-
else if (mtype == "deltaflow")
3452-
{ }
3453-
3454-
// Chat timestamp
3455-
else if (mtype == "chatproxy-presence")
3456-
{
3457-
var statuses = new Dictionary<string, FB_ActiveStatus>();
3458-
if (m.get("buddyList") != null)
3459-
{
3460-
foreach (var payload in m.get("buddyList").Value<JObject>().Properties())
3461-
{
3462-
statuses[payload.Name] = FB_ActiveStatus._from_chatproxy_presence(payload.Name, payload.Value);
3463-
this._buddylist[payload.Name] = statuses[payload.Name];
3464-
}
3465-
await this.onChatTimestamp(buddylist: statuses, msg: m);
3466-
}
3467-
}
3468-
3469-
// Buddylist overlay
3470-
else if (mtype == "buddylist_overlay")
3471-
{
3472-
var statuses = new Dictionary<string, FB_ActiveStatus>();
3473-
if (m.get("overlay") != null)
3474-
{
3475-
foreach (var payload in m.get("overlay").Value<JObject>().Properties())
3476-
{
3477-
bool old_in_game = false;
3478-
if (this._buddylist.ContainsKey(payload.Name))
3479-
old_in_game = this._buddylist[payload.Name].in_game;
3480-
3481-
statuses[payload.Name] = FB_ActiveStatus._from_buddylist_overlay(
3482-
payload.Value, old_in_game
3483-
);
3484-
this._buddylist[payload.Name] = statuses[payload.Name];
3485-
}
3486-
await this.onBuddylistOverlay(statuses: statuses, msg: m);
3487-
}
3488-
// Unknown message type
3489-
else
3490-
{
3491-
await this.onUnknownMesssageType(msg: m);
3492-
}
3493-
}
3494-
}
3495-
catch (Exception ex)
3496-
{
3497-
await this.onMessageError(exception: ex, msg: m);
3498-
}
3499-
}
3500-
}
3501-
35023330
private async Task<int> _fetch_mqtt_sequence_id()
35033331
{
35043332
// Get the sync sequence ID used for the /messenger_sync_create_queue call later.
@@ -3781,28 +3609,10 @@ await this.onTyping(
37813609
* :rtype: bool
37823610
*/
37833611

3784-
try
3785-
{
3786-
if (this._markAlive) await this._ping(cancellationToken);
3787-
var content = await this._pullMessage(cancellationToken);
3788-
if (content != null) await this._parseMessage(content);
3789-
}
3790-
catch (FBchatFacebookError ex)
3791-
{
3792-
if (new int[] { 502, 503 }.Contains(ex.request_status_code))
3793-
{
3794-
// Bump pull channel, while contraining withing 0-4
3795-
this._pull_channel = (this._pull_channel + 1) % 5;
3796-
}
3797-
else
3798-
{
3799-
throw (ex);
3800-
}
3801-
}
3802-
catch (Exception ex)
3803-
{
3804-
return await this.onListenError(exception: ex);
3805-
}
3612+
// TODO: Remove this wierd check, and let the user handle the chat_on parameter
3613+
//if self._markAlive != self._mqtt._chat_on:
3614+
//self._mqtt.set_chat_on(self._markAlive)
3615+
await Task.Yield();
38063616

38073617
return true;
38083618
}
@@ -3824,8 +3634,6 @@ public async Task stopListening()
38243634

38253635
// Cleans up the variables from startListening
38263636
this.listening = false;
3827-
this._sticky = null;
3828-
this._pool = null;
38293637
this._sync_token = null;
38303638
}
38313639

@@ -3902,20 +3710,6 @@ protected virtual async Task onListening()
39023710
await Task.Yield();
39033711
}
39043712

3905-
/// <summary>
3906-
/// Called when an error was encountered while listening
3907-
/// </summary>
3908-
/// <param name="exception">The exception that was encountered</param>
3909-
protected virtual async Task<bool> onListenError(Exception exception = null)
3910-
{
3911-
/*
3912-
* Called when an error was encountered while listening
3913-
* :param exception: The exception that was encountered
3914-
*/
3915-
Debug.WriteLine(string.Format("Got exception while listening: {0}", exception));
3916-
return await Task.FromResult(true);
3917-
}
3918-
39193713
/// <summary>
39203714
/// Called when an error was encountered while listening on mqtt
39213715
/// </summary>

0 commit comments

Comments
 (0)