-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMessage.php
More file actions
366 lines (315 loc) · 8.46 KB
/
Copy pathMessage.php
File metadata and controls
366 lines (315 loc) · 8.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
<?php
declare(strict_types=1);
namespace BeeperDesktop;
use BeeperDesktop\Core\Attributes\Optional;
use BeeperDesktop\Core\Attributes\Required;
use BeeperDesktop\Core\Concerns\SdkModel;
use BeeperDesktop\Core\Contracts\BaseModel;
use BeeperDesktop\Message\Type;
/**
* @phpstan-import-type AttachmentShape from \BeeperDesktop\Attachment
* @phpstan-import-type ReactionShape from \BeeperDesktop\Reaction
*
* @phpstan-type MessageShape = array{
* id: string,
* accountID: string,
* chatID: string,
* senderID: string,
* sortKey: string,
* timestamp: \DateTimeInterface,
* attachments?: list<Attachment|AttachmentShape>|null,
* isSender?: bool|null,
* isUnread?: bool|null,
* linkedMessageID?: string|null,
* reactions?: list<Reaction|ReactionShape>|null,
* senderName?: string|null,
* text?: string|null,
* type?: null|Type|value-of<Type>,
* }
*/
final class Message implements BaseModel
{
/** @use SdkModel<MessageShape> */
use SdkModel;
/**
* Message ID.
*/
#[Required]
public string $id;
/**
* Beeper account ID the message belongs to.
*/
#[Required]
public string $accountID;
/**
* Unique identifier of the chat.
*/
#[Required]
public string $chatID;
/**
* Sender user ID.
*/
#[Required]
public string $senderID;
/**
* A unique, sortable key used to sort messages.
*/
#[Required]
public string $sortKey;
/**
* Message timestamp.
*/
#[Required]
public \DateTimeInterface $timestamp;
/**
* Attachments included with this message, if any.
*
* @var list<Attachment>|null $attachments
*/
#[Optional(list: Attachment::class)]
public ?array $attachments;
/**
* True if the authenticated user sent the message.
*/
#[Optional]
public ?bool $isSender;
/**
* True if the message is unread for the authenticated user. May be omitted.
*/
#[Optional]
public ?bool $isUnread;
/**
* ID of the message this is a reply to, if any.
*/
#[Optional]
public ?string $linkedMessageID;
/**
* Reactions to the message, if any.
*
* @var list<Reaction>|null $reactions
*/
#[Optional(list: Reaction::class)]
public ?array $reactions;
/**
* Resolved sender display name (impersonator/full name/username/participant name).
*/
#[Optional]
public ?string $senderName;
/**
* Plain-text body if present. May include a JSON fallback with text entities for rich messages.
*/
#[Optional]
public ?string $text;
/**
* Message content type. Useful for distinguishing reactions, media messages, and state events from regular text messages.
*
* @var value-of<Type>|null $type
*/
#[Optional(enum: Type::class)]
public ?string $type;
/**
* `new Message()` is missing required properties by the API.
*
* To enforce required parameters use
* ```
* Message::with(
* id: ...,
* accountID: ...,
* chatID: ...,
* senderID: ...,
* sortKey: ...,
* timestamp: ...,
* )
* ```
*
* Otherwise ensure the following setters are called
*
* ```
* (new Message)
* ->withID(...)
* ->withAccountID(...)
* ->withChatID(...)
* ->withSenderID(...)
* ->withSortKey(...)
* ->withTimestamp(...)
* ```
*/
public function __construct()
{
$this->initialize();
}
/**
* Construct an instance from the required parameters.
*
* You must use named parameters to construct any parameters with a default value.
*
* @param list<Attachment|AttachmentShape>|null $attachments
* @param list<Reaction|ReactionShape>|null $reactions
* @param Type|value-of<Type>|null $type
*/
public static function with(
string $id,
string $accountID,
string $chatID,
string $senderID,
string $sortKey,
\DateTimeInterface $timestamp,
?array $attachments = null,
?bool $isSender = null,
?bool $isUnread = null,
?string $linkedMessageID = null,
?array $reactions = null,
?string $senderName = null,
?string $text = null,
Type|string|null $type = null,
): self {
$self = new self;
$self['id'] = $id;
$self['accountID'] = $accountID;
$self['chatID'] = $chatID;
$self['senderID'] = $senderID;
$self['sortKey'] = $sortKey;
$self['timestamp'] = $timestamp;
null !== $attachments && $self['attachments'] = $attachments;
null !== $isSender && $self['isSender'] = $isSender;
null !== $isUnread && $self['isUnread'] = $isUnread;
null !== $linkedMessageID && $self['linkedMessageID'] = $linkedMessageID;
null !== $reactions && $self['reactions'] = $reactions;
null !== $senderName && $self['senderName'] = $senderName;
null !== $text && $self['text'] = $text;
null !== $type && $self['type'] = $type;
return $self;
}
/**
* Message ID.
*/
public function withID(string $id): self
{
$self = clone $this;
$self['id'] = $id;
return $self;
}
/**
* Beeper account ID the message belongs to.
*/
public function withAccountID(string $accountID): self
{
$self = clone $this;
$self['accountID'] = $accountID;
return $self;
}
/**
* Unique identifier of the chat.
*/
public function withChatID(string $chatID): self
{
$self = clone $this;
$self['chatID'] = $chatID;
return $self;
}
/**
* Sender user ID.
*/
public function withSenderID(string $senderID): self
{
$self = clone $this;
$self['senderID'] = $senderID;
return $self;
}
/**
* A unique, sortable key used to sort messages.
*/
public function withSortKey(string $sortKey): self
{
$self = clone $this;
$self['sortKey'] = $sortKey;
return $self;
}
/**
* Message timestamp.
*/
public function withTimestamp(\DateTimeInterface $timestamp): self
{
$self = clone $this;
$self['timestamp'] = $timestamp;
return $self;
}
/**
* Attachments included with this message, if any.
*
* @param list<Attachment|AttachmentShape> $attachments
*/
public function withAttachments(array $attachments): self
{
$self = clone $this;
$self['attachments'] = $attachments;
return $self;
}
/**
* True if the authenticated user sent the message.
*/
public function withIsSender(bool $isSender): self
{
$self = clone $this;
$self['isSender'] = $isSender;
return $self;
}
/**
* True if the message is unread for the authenticated user. May be omitted.
*/
public function withIsUnread(bool $isUnread): self
{
$self = clone $this;
$self['isUnread'] = $isUnread;
return $self;
}
/**
* ID of the message this is a reply to, if any.
*/
public function withLinkedMessageID(string $linkedMessageID): self
{
$self = clone $this;
$self['linkedMessageID'] = $linkedMessageID;
return $self;
}
/**
* Reactions to the message, if any.
*
* @param list<Reaction|ReactionShape> $reactions
*/
public function withReactions(array $reactions): self
{
$self = clone $this;
$self['reactions'] = $reactions;
return $self;
}
/**
* Resolved sender display name (impersonator/full name/username/participant name).
*/
public function withSenderName(string $senderName): self
{
$self = clone $this;
$self['senderName'] = $senderName;
return $self;
}
/**
* Plain-text body if present. May include a JSON fallback with text entities for rich messages.
*/
public function withText(string $text): self
{
$self = clone $this;
$self['text'] = $text;
return $self;
}
/**
* Message content type. Useful for distinguishing reactions, media messages, and state events from regular text messages.
*
* @param Type|value-of<Type> $type
*/
public function withType(Type|string $type): self
{
$self = clone $this;
$self['type'] = $type;
return $self;
}
}