diff --git a/src/danog/MadelineProto/MTProtoTools/DialogHandler.php b/src/danog/MadelineProto/MTProtoTools/DialogHandler.php new file mode 100644 index 000000000..6b1267807 --- /dev/null +++ b/src/danog/MadelineProto/MTProtoTools/DialogHandler.php @@ -0,0 +1,36 @@ +. +*/ + +namespace danog\MadelineProto\MTProtoTools; + +trait DialogHandler +{ + public $dialog_params = ['limit' => 0, 'offset_date' => 0, 'offset_id' => 0, 'offset_peer' => ['_' => 'inputPeerEmpty']]; + public function get_dialogs() { + $this->getting_state = true; + $res = ['dialogs' => [0]]; + $datacenter = $this->datacenter->curdc; + $count = 0; + while (count($res['dialogs'])) { + \danog\MadelineProto\Logger::log(['Getting dialogs...']); + $res = $this->method_call('messages.getDialogs', $this->dialog_params, ['datacenter' => $datacenter, 'FloodWaitLimit' => 100]); + $count += count($res['dialogs']); + $old_params = $this->dialog_params; + $this->dialog_params['offset_date'] = end($res['messages'])['date']; + $this->dialog_params['offset_peer'] = end($res['dialogs'])['peer']; + $this->dialog_params['offset_id'] = end($res['messages'])['id']; + if ($this->dialog_params === $old_params) break; + } + + $this->getting_state = false; + } +}