Exemplo n.º 1
0
        /// <summary>
        /// Send a message to a group.
        /// </summary>
        /// <param name="token">The cancellation token</param>
        /// <param name="recipients">The group members.</param>
        /// <param name="message">The group message.</param>
        public async Task SendMessage(CancellationToken token, List <SignalServiceAddress> recipients, SignalServiceDataMessage message)
        {
            byte[] content = await CreateMessageContent(token, message);

            long timestamp = message.Timestamp;
            SendMessageResponseList response = await SendMessage(token, recipients, timestamp, content);

            try
            {
                if (response != null && response.NeedsSync)
                {
                    byte[] syncMessage = CreateMultiDeviceSentTranscriptContent(content, May <SignalServiceAddress> .NoValue, (ulong)timestamp);
                    await SendMessage(token, localAddress, timestamp, syncMessage, false);
                }
            }
            catch (UntrustedIdentityException e)
            {
                response.UntrustedIdentities.Add(e);
            }

            if (response.HasExceptions())
            {
                throw new EncapsulatedExceptions(response.UntrustedIdentities, response.UnregisteredUsers, response.NetworkExceptions);
            }
        }
Exemplo n.º 2
0
        private async Task <SendMessageResponseList> SendMessage(CancellationToken token, List <SignalServiceAddress> recipients, long timestamp, byte[] content)
        {
            SendMessageResponseList responseList = new SendMessageResponseList();

            foreach (SignalServiceAddress recipient in recipients)
            {
                try
                {
                    var response = await SendMessage(token, recipient, timestamp, content, false);

                    responseList.AddResponse(response);
                }
                catch (UntrustedIdentityException e)
                {
                    Logger.LogError("SendMessage() untrusted identity");
                    responseList.UntrustedIdentities.Add(e);
                }
                catch (UnregisteredUserException e)
                {
                    Logger.LogError("SendMessage() unregistered user");
                    responseList.UnregisteredUsers.Add(e);
                }
                catch (PushNetworkException e)
                {
                    Logger.LogError("SendMessage() failed: {0}\n{1}", e.Message, e.StackTrace);
                    responseList.NetworkExceptions.Add(new NetworkFailureException(recipient.E164number, e));
                }
            }
            return(responseList);
        }
Exemplo n.º 3
0
        private SendMessageResponseList sendMessage(List <SignalServiceAddress> recipients, long timestamp, byte[] content, bool legacy)
        {
            SendMessageResponseList responseList = new SendMessageResponseList();

            foreach (SignalServiceAddress recipient in recipients)
            {
                try
                {
                    var response = sendMessage(recipient, timestamp, content, legacy, false);
                    responseList.AddResponse(response);
                }
                catch (UntrustedIdentityException e)
                {
                    Debug.WriteLine("untrusted identity: " + recipient, TAG);
                    responseList.UntrustedIdentities.Add(e);
                }
                catch (UnregisteredUserException e)
                {
                    Debug.WriteLine("unregistered user: "******"PushNetWorkException for:" + recipient, TAG);
                    responseList.NetworkExceptions.Add(new NetworkFailureException(recipient.getNumber(), e));
                }
            }
            return(responseList);
        }