({
from,
to,
text,
attachments,
sticker,
preview,
quote,
desktop,
timestamp = Date.now(),
}: {
from: PrimaryDevice;
to: PrimaryDevice | Device | GroupInfo;
text: string | undefined;
attachments?: Array<Proto.AttachmentPointer.Params>;
sticker?: Proto.DataMessage.Sticker.Params;
preview?: Proto.Preview.Params;
quote?: Proto.DataMessage.Quote.Params;
desktop: Device;
timestamp?: number;
})
| 198 | } |
| 199 | |
| 200 | export function sendTextMessage({ |
| 201 | from, |
| 202 | to, |
| 203 | text, |
| 204 | attachments, |
| 205 | sticker, |
| 206 | preview, |
| 207 | quote, |
| 208 | desktop, |
| 209 | timestamp = Date.now(), |
| 210 | }: { |
| 211 | from: PrimaryDevice; |
| 212 | to: PrimaryDevice | Device | GroupInfo; |
| 213 | text: string | undefined; |
| 214 | attachments?: Array<Proto.AttachmentPointer.Params>; |
| 215 | sticker?: Proto.DataMessage.Sticker.Params; |
| 216 | preview?: Proto.Preview.Params; |
| 217 | quote?: Proto.DataMessage.Quote.Params; |
| 218 | desktop: Device; |
| 219 | timestamp?: number; |
| 220 | }): Promise<void> { |
| 221 | const isSync = from.secondaryDevices.includes(desktop); |
| 222 | const toDevice = isSync || isToGroup(to) ? desktop : getDevice(to); |
| 223 | const groupInfo = isToGroup(to) ? to : undefined; |
| 224 | return from.sendRaw( |
| 225 | toDevice, |
| 226 | maybeWrapInSyncMessage({ |
| 227 | isSync, |
| 228 | to: to as PrimaryDevice, |
| 229 | dataMessage: { |
| 230 | ...EMPTY_DATA_MESSAGE, |
| 231 | body: text ?? null, |
| 232 | attachments: attachments ?? null, |
| 233 | sticker: sticker ?? null, |
| 234 | preview: preview == null ? null : [preview], |
| 235 | quote: quote ?? null, |
| 236 | timestamp: BigInt(timestamp), |
| 237 | groupV2: groupInfo |
| 238 | ? { |
| 239 | masterKey: groupInfo.group.masterKey, |
| 240 | revision: groupInfo.group.revision, |
| 241 | groupChange: null, |
| 242 | } |
| 243 | : null, |
| 244 | }, |
| 245 | sentTo: groupInfo ? groupInfo.members : [to as PrimaryDevice | Device], |
| 246 | }), |
| 247 | { timestamp } |
| 248 | ); |
| 249 | } |
| 250 | |
| 251 | export function sendReaction({ |
| 252 | from, |
no test coverage detected