Skip to content

Commit 24d535b

Browse files
committed
Cleanup
1 parent 82e0bd2 commit 24d535b

9 files changed

Lines changed: 65 additions & 37 deletions

File tree

psalm-baseline.xml

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3455,6 +3455,9 @@
34553455
<InvalidReturnType>
34563456
<code><![CDATA[?MTProtoOutgoingMessage]]></code>
34573457
</InvalidReturnType>
3458+
<PropertyTypeCoercion>
3459+
<code><![CDATA[new WeakMap()]]></code>
3460+
</PropertyTypeCoercion>
34583461
</file>
34593462
<file src="src/MTProto/MTProtoIncomingMessage.php">
34603463
<InvalidPropertyAssignmentValue>
@@ -3812,31 +3815,33 @@
38123815
</PossiblyInvalidArgument>
38133816
</file>
38143817
<file src="src/MTProtoSession/Session.php">
3818+
<DocblockTypeContradiction>
3819+
<code><![CDATA[new LinkedList]]></code>
3820+
<code><![CDATA[new LinkedList]]></code>
3821+
<code><![CDATA[null]]></code>
3822+
<code><![CDATA[null]]></code>
3823+
</DocblockTypeContradiction>
38153824
<MissingConstructor>
3816-
<code><![CDATA[$check_queue]]></code>
38173825
<code><![CDATA[$mainPendingOutgoing]]></code>
38183826
<code><![CDATA[$msgIdHandler]]></code>
38193827
<code><![CDATA[$new_incoming]]></code>
38203828
<code><![CDATA[$unencryptedPendingOutgoing]]></code>
3821-
<code><![CDATA[$unencrypted_check_queue]]></code>
38223829
<code><![CDATA[$uninitedPendingOutgoing]]></code>
38233830
</MissingConstructor>
38243831
<MixedPropertyTypeCoercion>
38253832
<code><![CDATA[$q]]></code>
38263833
</MixedPropertyTypeCoercion>
3827-
<PropertyTypeCoercion>
3828-
<code><![CDATA[$this->check_queue ??= new WeakMap]]></code>
3829-
<code><![CDATA[$this->unencrypted_check_queue ??= new WeakMap]]></code>
3830-
</PropertyTypeCoercion>
38313834
<RedundantCondition>
3832-
<code><![CDATA[$this->mainPendingOutgoing]]></code>
38333835
<code><![CDATA[$this->unencryptedPendingOutgoing]]></code>
3834-
<code><![CDATA[$this->uninitedPendingOutgoing]]></code>
38353836
</RedundantCondition>
3837+
<RedundantConditionGivenDocblockType>
3838+
<code><![CDATA[$this->mainPendingOutgoing]]></code>
3839+
<code><![CDATA[$this->mainPendingOutgoing]]></code>
3840+
<code><![CDATA[$this->uninitedPendingOutgoing]]></code>
3841+
<code><![CDATA[$this->uninitedPendingOutgoing]]></code>
3842+
</RedundantConditionGivenDocblockType>
38363843
<TypeDoesNotContainType>
38373844
<code><![CDATA[null]]></code>
3838-
<code><![CDATA[null]]></code>
3839-
<code><![CDATA[null]]></code>
38403845
</TypeDoesNotContainType>
38413846
</file>
38423847
<file src="src/MTProtoTools/AuthKeyHandler.php">

src/Loop/Connection/ReadLoop.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,13 @@ public function readMessage(): ?int
246246
$this->API->referenceDatabase->reset();
247247
}
248248

249-
$message = new MTProtoIncomingMessage($this->connection, $deserialized, $message_id, $unencrypted);
249+
$message = new MTProtoIncomingMessage(
250+
$this->connection,
251+
$deserialized,
252+
$message_id,
253+
$unencrypted,
254+
false
255+
);
250256
if (isset($seq_no)) {
251257
$message->setSeqNo($seq_no);
252258
}

src/Loop/Connection/WriteLoop.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ public function loop(): ?float
142142
}
143143
public function unencryptedWriteLoop(): void
144144
{
145-
if (0 !== ($queue = $this->connection->unencrypted_check_queue)->count()) {
146-
$this->connection->unencrypted_check_queue = new WeakMap;
145+
if (0 !== ($queue = $this->queue->check_queue)->count()) {
146+
$this->queue->check_queue = new WeakMap;
147147
foreach ($queue as $msg => $_) {
148148
// TODO: wait for actual re-queueing
149149
$this->connection->methodRecall($msg);
@@ -175,11 +175,11 @@ public function encryptedWriteLoop(): void
175175
(
176176
!$this->queue->isEmpty()
177177
|| $this->connection->ack_queue
178-
|| $this->connection->check_queue->count()
178+
|| $this->queue->check_queue->count()
179179
)
180180
) {
181-
if (0 !== ($check = $this->connection->check_queue)->count()) {
182-
$this->connection->check_queue = new WeakMap;
181+
if (0 !== ($check = $this->queue->check_queue)->count()) {
182+
$this->queue->check_queue = new WeakMap;
183183
$deferred = new DeferredFuture();
184184
$deferred->getFuture()->catch(function (\Throwable $e): void {
185185
$this->API->logger("Got exception in check loop for DC {$this->datacenter}");

src/MTProto/LinkedList.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
namespace danog\MadelineProto\MTProto;
2222

23+
use WeakMap;
24+
2325
/**
2426
* @internal
2527
*/
@@ -31,10 +33,18 @@ final class LinkedList
3133

3234
public MTProtoOutgoingMessage|LinkedList $prev;
3335

36+
/**
37+
* Check queue.
38+
*
39+
* @var WeakMap<MTProtoOutgoingMessage, true>
40+
*/
41+
public WeakMap $check_queue;
42+
3443
public function __construct()
3544
{
3645
$this->next = $this;
3746
$this->prev = $this;
47+
$this->check_queue = new WeakMap();
3848
}
3949

4050
public function isEmpty(): bool

src/MTProto/MTProtoIncomingMessage.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,13 @@ final class MTProtoIncomingMessage extends MTProtoMessage
7272
* @param array $content Content
7373
* @param boolean $fromContainer Whether this message was in a container
7474
*/
75-
public function __construct(private readonly Connection $connection, array $content, int $msgId, public readonly bool $unencrypted, public readonly bool $fromContainer = false)
76-
{
75+
public function __construct(
76+
private readonly Connection $connection,
77+
array $content,
78+
int $msgId,
79+
public readonly bool $unencrypted,
80+
public readonly bool $fromContainer,
81+
) {
7782
$this->content = $content;
7883
$this->msgId = $msgId;
7984

src/MTProto/MTProtoOutgoingMessage.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,11 @@ private function check(): void
236236

237237
\assert($this->msgId !== null);
238238
if ($this->unencrypted) {
239-
$this->connection->unencrypted_check_queue[$this] = true;
239+
$this->connection->unencryptedPendingOutgoing->check_queue[$this] = true;
240+
} elseif ($this->specialMethodType === SpecialMethodType::UNAUTHED_METHOD) {
241+
$this->connection->uninitedPendingOutgoing->check_queue[$this] = true;
240242
} else {
241-
$this->connection->check_queue[$this] = true;
243+
$this->connection->mainPendingOutgoing->check_queue[$this] = true;
242244
}
243245
$this->connection->flush(true);
244246
}

src/MTProtoSession/CallHandler.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
use danog\MadelineProto\DataCenterConnection;
2929
use danog\MadelineProto\MTProto;
3030
use danog\MadelineProto\MTProto\Container;
31+
use danog\MadelineProto\MTProto\LinkedList;
3132
use danog\MadelineProto\MTProto\MTProtoOutgoingMessage;
3233
use danog\MadelineProto\MTProto\SpecialMethodType;
3334
use danog\MadelineProto\TL\Exception;
@@ -41,6 +42,8 @@
4142
* Manages method and object calls.
4243
*
4344
*
45+
* @property LinkedList $mainPendingOutgoing
46+
* @property LinkedList $uninitedPendingOutgoing
4447
* @property DataCenterConnection $shared
4548
* @property MTProto $API
4649
* @internal

src/MTProtoSession/ResponseHandler.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,13 @@ private function handleContainer(MTProtoIncomingMessage $message): void
139139
$tmp->setIteratorMode(SplQueue::IT_MODE_DELETE);
140140
foreach ($message->read()['messages'] as $msg) {
141141
$this->msgIdHandler->checkIncomingMessageId($msg['msg_id'], true);
142-
$newMessage = new MTProtoIncomingMessage($this, $msg['body'], $msg['msg_id'], $message->unencrypted, true);
142+
$newMessage = new MTProtoIncomingMessage(
143+
$this,
144+
$msg['body'],
145+
$msg['msg_id'],
146+
$message->unencrypted,
147+
true
148+
);
143149
$newMessage->setSeqNo($msg['seqno']);
144150
$this->checkInSeqNo($newMessage);
145151
$newMessage->setSeqNo(null);
@@ -158,7 +164,13 @@ private function handleMsgCopy(MTProtoIncomingMessage $message): void
158164
$this->incoming_messages[$referencedMsgId]->ack();
159165
} else {*/
160166
$this->msgIdHandler->checkIncomingMessageId($referencedMsgId, true);
161-
$message = new MTProtoIncomingMessage($this, $content['orig_message'], $referencedMsgId, $message->unencrypted);
167+
$message = new MTProtoIncomingMessage(
168+
$this,
169+
$content['orig_message'],
170+
$referencedMsgId,
171+
$message->unencrypted,
172+
true
173+
);
162174
$this->incomingCtr?->inc();
163175
//$this->incoming_messages[$referencedMsgId] = $message;
164176
$this->handleMessages([$message]);

src/MTProtoSession/Session.php

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
use danog\MadelineProto\MTProto\MTProtoOutgoingMessage;
3131
use danog\MadelineProto\Tools;
3232
use SplQueue;
33-
use WeakMap;
3433

3534
/**
3635
* Manages MTProto session-specific data.
@@ -109,18 +108,6 @@ trait Session
109108
* @var list<int>
110109
*/
111110
public array $ack_queue = [];
112-
/**
113-
* Check queue.
114-
*
115-
* @var WeakMap<MTProtoOutgoingMessage, true>
116-
*/
117-
public WeakMap $check_queue;
118-
/**
119-
* Check queue.
120-
*
121-
* @var WeakMap<MTProtoOutgoingMessage, true>
122-
*/
123-
public WeakMap $unencrypted_check_queue;
124111
/**
125112
* Message ID handler.
126113
*
@@ -205,8 +192,6 @@ public function createSession(): void
205192
$this->mainPendingOutgoing ??= new LinkedList;
206193
$this->unencryptedPendingOutgoing ??= new LinkedList;
207194
$this->uninitedPendingOutgoing ??= new LinkedList;
208-
$this->check_queue ??= new WeakMap;
209-
$this->unencrypted_check_queue ??= new WeakMap;
210195
if ($this->session_id === null) {
211196
$this->resetSession("creating initial session");
212197
}

0 commit comments

Comments
 (0)