Пример #1
0
        public static void NotifyMessageDeliveryFailed(Recipients recipients, long threadId)
        {
            var content = new ToastContent()
            {
                Launch = new QueryString()
                {
                    {"action", "viewConversation" },
                    { "threadId",  threadId.ToString() }
                }.ToString(),

                Visual = new ToastVisual()
                {
                    TitleText = new ToastText()
                    {
                        Text = $"Message delivery failed"
                    },
                },

                /*Audio = new ToastAudio()
                {
                    Src = new Uri("ms-winsoundevent:Notification.IM")
                }*/
            };

            var doc = content.GetXml();

            // Generate WinRT notification
            var noti = new ToastNotification(doc);
            ToastNotificationManager.CreateToastNotifier().Show(noti);
        }
Пример #2
0
        public async Task<long> GetThreadIdFor(Recipients recipients, int distributionType)
        {
            long[] recipientIds = getRecipientIds(recipients);
            string recipientsList = getRecipientsAsString(recipientIds);


            try
            {
                var query = context.Threads.Where(t => t.RecipientIds == recipientsList);// TODO: recipient refactor
                var first = query.Count() == 0 ? null : query.First();

                if (query != null && first != null)
                    return first.ThreadId;
                else
                    return await CreateThreadForRecipients(recipients, recipientIds.Length, distributionType);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
            finally
            {

            }
        }
Пример #3
0
 public Record(BodyRecord body, Recipients recipients, DateTime dateSent,
                      DateTime dateReceived, long threadId, long type)
 {
     this.ThreadId = threadId;
     this.Recipients = recipients;
     this.DateSent = dateSent;
     this.DateReceived = dateReceived;
     this.Type = type;
     this.Body = body;
 }
Пример #4
0
        private long CreateForRecipients(Recipients recipients, int distributionType)
        {
            var thread = new Thread()
            {
                Date = TimeUtil.GetDateTimeMillis(),
                Count = 0,
                Recipients = recipients,
                Type = distributionType
            };

            var rows = conn.Insert(thread);

            return thread.ThreadId;
        }
Пример #5
0
        public static long[] getRecipientIds(Recipients recipients)
        {
            HashSet<long> recipientSet = new HashSet<long>();
            List<Recipient> recipientList = recipients.getRecipientsList();

            foreach (Recipient recipient in recipientList)
            {
                recipientSet.Add(recipient.getRecipientId());
            }

            long[] recipientArray = new long[recipientSet.Count];
            int i = 0;

            foreach (long recipientId in recipientSet)
            {
                recipientArray[i++] = recipientId;
            }

            Array.Sort(recipientArray);

            return recipientArray;
        }
Пример #6
0
 public long GetThreadIdForRecipients(Recipients recipients)
 {
     return GetThreadIdForRecipients(recipients, DistributionTypes.DEFAULT);
 }
Пример #7
0
 public Task<long> GetThreadIdFor(Recipients recipients)
 {
     throw new NotImplementedException();
 }
Пример #8
0
        private async Task<long> CreateThreadForRecipients(Recipients recipients, int recipientCount, int distributionType)
        {
            long[] recipientIds = getRecipientIds(recipients);
            string recipientsList = getRecipientsAsString(recipientIds);

            var thread = new Thread()
            {
                Date = DateTime.Now,
                RecipientIds = recipientsList,
                //Recipients = recipients.getRecipientsList(),
                Count = 0
            };

            if (recipientCount > 1)
            {
                thread.Type = distributionType;
            }

            context.Add(thread);
            await context.SaveChangesAsync();

            return thread.ThreadId;
        }
Пример #9
0
        /*
        private static void sendMediaMessage(Context context, MasterSecret masterSecret,
                                             Recipients recipients, boolean forceSms, long messageId)
      throws MmsException
        {
    if (!forceSms && isSelfSend(context, recipients)) {
                sendMediaSelf(context, masterSecret, messageId);
            } else if (isGroupPushSend(recipients)) {
                sendGroupPush(context, recipients, messageId, -1);
            } else if (!forceSms && isPushMediaSend(context, recipients)) {
                sendMediaPush(context, recipients, messageId);
            } else {
                sendMms(context, messageId);
            }
        }
        */
        private static async Task sendTextMessage(Recipients recipients, bool keyExchange, long messageId)
        {
            if (isSelfSend(recipients))
            {
                sendTextSelf(messageId);
            }
            else
            {
                await sendTextPush(recipients, messageId);
            }

        }
Пример #10
0
        internal Recipients getRecipients(long[] recipientIds, bool asynchronous)
        {
            Recipients cachedRecipients;
            recipientsCache.TryGetValue(new RecipientIds(recipientIds), out cachedRecipients);

            if (cachedRecipients != null) return cachedRecipients;

            List<Recipient> recipientList = new List<Recipient>();

            foreach (long recipientId in recipientIds)
            {
                recipientList.Add(getRecipient(recipientId, asynchronous));
            }

            if (asynchronous && false) cachedRecipients = null;//cachedRecipients = new Recipients(recipientList, getRecipientsPreferences(recipientIds)); // TODO fix
            else cachedRecipients = new Recipients(recipientList, null/*getRecipientsPreferencesSync(recipientIds)*/);

            recipientsCache.Add(new RecipientIds(recipientIds), cachedRecipients);
            return cachedRecipients;
        }
Пример #11
0
 public OutgoingTextMessage(Recipients recipients, string message)
 {
     this.Recipients = recipients;
     this.MessageBody = message;
 }
Пример #12
0
        protected Pair<long, long> InsertMessageInbox(IncomingTextMessage message, long type)
        { // TODO : https://github.com/WhisperSystems/Signal-Android/blob/e9b53cc164d7ae2d838cc211dbd88b7fd4f5669e/src/org/thoughtcrime/securesms/database/SmsDatabase.java
            if (message.isPreKeyBundle())
            {
                type |= MessageTypes.KEY_EXCHANGE_BIT | MessageTypes.KEY_EXCHANGE_BUNDLE_BIT;
            }
            else if (message.isSecureMessage())
            {
                type |= MessageTypes.SECURE_MESSAGE_BIT;
            }
            /*else if (message.isGroup()) TODO: GROUP enable
            {
                type |= MessageTypes.SECURE_MESSAGE_BIT;
                if (((IncomingGroupMessage)message).isUpdate()) type |= MessageTypes.GROUP_UPDATE_BIT;
                else if (((IncomingGroupMessage)message).isQuit()) type |= MessageTypes.GROUP_QUIT_BIT;
            }*/
            else if (message.IsEndSession)
            {
                type |= MessageTypes.SECURE_MESSAGE_BIT;
                type |= MessageTypes.END_SESSION_BIT;
            }

            if (message.IsPush) type |= MessageTypes.PUSH_MESSAGE_BIT;

            Recipients recipients;

            if (message.getSender() != null)
            {
                recipients = RecipientFactory.getRecipientsFromString(message.getSender(), true);
            }
            else
            {
                //Log.w(TAG, "Sender is null, returning unknown recipient");
                recipients = new Recipients(Recipient.getUnknownRecipient());
            }

            Recipients groupRecipients;

            if (message.GroupId == null)
            {
                groupRecipients = null;
            }
            else
            {
                groupRecipients = RecipientFactory.getRecipientsFromString(message.GroupId, true);
            }

            bool unread = /*org.thoughtcrime.securesms.util.Util.isDefaultSmsProvider() ||*/
                                    message.isSecureMessage() || message.isPreKeyBundle();

            long threadId;

            if (groupRecipients == null) threadId = DatabaseFactory.getThreadDatabase().GetThreadIdForRecipients(recipients); // TODO CHECK
            else threadId = DatabaseFactory.getThreadDatabase().GetThreadIdForRecipients(groupRecipients);

            /*ContentValues values = new ContentValues(6);
            values.put(ADDRESS, message.getSender());
            values.put(ADDRESS_DEVICE_ID, message.getSenderDeviceId());
            values.put(DATE_RECEIVED, System.currentTimeMillis());
            values.put(DATE_SENT, message.getSentTimestampMillis());
            values.put(PROTOCOL, message.getProtocol());
            values.put(READ, unread ? 0 : 1);

            if (!TextUtils.isEmpty(message.getPseudoSubject()))
                values.put(SUBJECT, message.getPseudoSubject());

            values.put(REPLY_PATH_PRESENT, message.isReplyPathPresent());
            values.put(SERVICE_CENTER, message.getServiceCenterAddress());
            values.put(BODY, message.getMessageBody());
            values.put(TYPE, type);
            values.put(THREAD_ID, threadId);*/

            var insert = new Message()
            {
                Address = message.getSender(),
                AddressDeviceId = message.getSenderDeviceId(),
                DateReceived = TimeUtil.GetDateTimeMillis(), // force precision to millis not to ticks
                DateSent = TimeUtil.GetDateTime(message.SentTimestampMillis),
                Read = !unread,
                Body = message.getMessageBody(),
                Type = type,
                ThreadId = threadId
            };

            long rows = conn.Insert(insert);

            long messageId = insert.MessageId;

            if (unread)
            {
                DatabaseFactory.getThreadDatabase().SetUnread(threadId);
            }

            DatabaseFactory.getThreadDatabase().Refresh(threadId);
            notifyConversationListeners(threadId);
            //jobManager.add(new TrimThreadJob(context, threadId)); // TODO

            return new Pair<long, long>(messageId, threadId);
        }
Пример #13
0
        /*
    private static boolean isPushMediaSend(Context context, Recipients recipients)
    {
        try
        {
            if (!TextSecurePreferences.isPushRegistered(context))
            {
                return false;
            }

            if (recipients.getRecipientsList().size() > 1)
            {
                return false;
            }

            Recipient recipient = recipients.getPrimaryRecipient();
            String destination = Util.canonicalizeNumber(context, recipient.getNumber());

            return isPushDestination(context, destination);
        }
        catch (InvalidNumberException e)
        {
            Log.w(TAG, e);
            return false;
        }
    }

    private static boolean isGroupPushSend(Recipients recipients)
    {
        return GroupUtil.isEncodedGroup(recipients.getPrimaryRecipient().getNumber());
    }*/

        private static bool isSelfSend(Recipients recipients)
        {
            try
            {
                if (!TextSecurePreferences.isPushRegistered())
                {
                    return false;
                }

                if (!recipients.IsSingleRecipient)
                {
                    return false;
                }

                if (recipients.IsGroupRecipient)
                {
                    return false;
                }

                String e164number = Utils.canonicalizeNumber(recipients.getPrimaryRecipient().getNumber());
                return TextSecurePreferences.getLocalNumber().Equals(e164number);
            }
            catch (InvalidNumberException e)
            {
                //Log.w("MessageSender", e);
                return false;
            }
        }
Пример #14
0
        /*
            private static void sendMediaPush(Context context, Recipients recipients, long messageId)
            {
                JobManager jobManager = ApplicationContext.getInstance(context).getJobManager();
                jobManager.add(new PushMediaSendJob(context, messageId, recipients.getPrimaryRecipient().getNumber()));
            }

            private static void sendGroupPush(Context context, Recipients recipients, long messageId, long filterRecipientId)
            {
                JobManager jobManager = ApplicationContext.getInstance(context).getJobManager();
                jobManager.add(new PushGroupSendJob(context, messageId, recipients.getPrimaryRecipient().getNumber(), filterRecipientId));
            }

            private static void sendSms(Context context, Recipients recipients, long messageId)
            {
                JobManager jobManager = ApplicationContext.getInstance(context).getJobManager();
                jobManager.add(new SmsSendJob(context, messageId, recipients.getPrimaryRecipient().getName()));
            }

            private static void sendMms(Context context, long messageId)
            {
                JobManager jobManager = ApplicationContext.getInstance(context).getJobManager();
                jobManager.add(new MmsSendJob(context, messageId));
            }
            */
        private async static Task<bool> isPushTextSend(Recipients recipients, bool keyExchange)
        {
            try
            {
                if (!TextSecurePreferences.isPushRegistered())
                {
                    return false;
                }

                if (keyExchange)
                {
                    return false;
                }

                Recipient recipient = recipients.getPrimaryRecipient();
                String destination = Utils.canonicalizeNumber(recipient.getNumber());

                return await isPushDestination(destination);
            }
            catch (InvalidNumberException e)
            {
                //Log.w(TAG, e);
                return false;
            }
        }
Пример #15
0
        }/*

        private static void sendMediaSelf(Context context, MasterSecret masterSecret, long messageId)
      throws MmsException
        {
            MmsDatabase database = DatabaseFactory.getMmsDatabase(context);
            database.markAsSent(messageId, "self-send".getBytes(), 0);
            database.markAsPush(messageId);

    long newMessageId = database.copyMessageInbox(masterSecret, messageId);
        database.markAsPush(newMessageId);
  }
  */
        private async static Task<bool> sendTextPush(Recipients recipients, long messageId)
        {



            App.Current.Worker.AddTaskActivities(new PushTextSendTask(messageId, recipients.getPrimaryRecipient().getNumber()));
            return true;
        }
Пример #16
0
        public long GetThreadIdForRecipients(Recipients recipients, int distributionType)
        {
            long[] recipientIds = getRecipientIds(recipients);
            String recipientsList = getRecipientsAsString(recipientIds);

            try
            {
                var query = conn.Table<Thread>().Where(t => t.RecipientIds == recipientsList); // use internal property
                var first = query.Count() == 0 ? null : query.First();

                if (query != null && first != null)
                    return (long)first.ThreadId;
                else
                    return CreateForRecipients(recipientsList, recipientIds.Length, distributionType);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
Пример #17
0
        public async Task<long> getThreadIdIfExistsFor(Recipients recipients)
        {
            long[] recipientIds = getRecipientIds(recipients);
            String recipientsList = getRecipientsAsString(recipientIds);

            try
            {
                var query = conn.Table<Thread>().Where(t => t.Recipients == recipients);
                var first = query.First();
                //cursor = db.query(TABLE_NAME, new String[] { ID }, where, recipientsArg, null, null, null);

                if (query != null && first != null)
                    return (long)first.ThreadId;
                else
                    return -1L;
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
            finally
            {
                // if (cursor != null)
                //    cursor.close();
            }
        }
Пример #18
0
        /*public OutgoingMediaMessage(Recipients recipients, PduBody body,
                                    String message, int distributionType)
        {
            this.recipients = recipients;
            this.body = body;
            this.distributionType = distributionType;

            if (!TextUtils.isEmpty(message))
            {
                this.body.addPart(new TextSlide(context, message).getPart());
            }
        }

        public OutgoingMediaMessage(Context context, Recipients recipients, SlideDeck slideDeck,
                                    String message, int distributionType)
        {
            this(context, recipients, slideDeck.toPduBody(), message, distributionType);
        }

        public OutgoingMediaMessage(Context context, MasterSecretUnion masterSecret,
                                    Recipients recipients, List<TextSecureAttachment> attachments,
                                    String message)
        {
            this(context, recipients, pduBodyFor(masterSecret, attachments), message,
                 ThreadDatabase.DistributionTypes.CONVERSATION);
        }*/

        public OutgoingMediaMessage(OutgoingMediaMessage that)
        {
            this.recipients = that.getRecipients();
            //this.body = that.body;
            this.distributionType = that.distributionType;
        }
Пример #19
0
 public OutgoingEncryptedMessage(Recipients recipients, string body)
     : base(recipients, body)
 {
 }
 public OutgoingKeyExchangeMessage(Recipients recipients, string message)
     : base(recipients, message)
 {
 }