public async static Task <long> send( OutgoingTextMessage message, long threadId) { long type = MessageTypes.BASE_OUTBOX_TYPE; //EncryptingSmsDatabase database = DatabaseFactory.getEncryptingSmsDatabase(context); MessageDatabase database = DatabaseFactory.getMessageDatabase(); Recipients recipients = message.getRecipients(); bool keyExchange = message.isKeyExchange(); long allocatedThreadId; if (threadId == -1) { allocatedThreadId = DatabaseFactory.getThreadDatabase().GetThreadIdForRecipients(recipients); } else { allocatedThreadId = threadId; } long messageId = await database.insertMessageOutbox(allocatedThreadId, message, type, TimeUtil.GetDateTimeMillis()); // notify user interface Messenger.Default.Send(new AddMessageMessage() { ThreadId = allocatedThreadId, MessageId = messageId }); await sendTextMessage(recipients, keyExchange, messageId); return(allocatedThreadId); }
/* * Inbox/Outbox */ public async Task <long> insertMessageOutbox(long threadId, OutgoingTextMessage message, long type, DateTime date) { if (message.isKeyExchange()) { type |= MessageTypes.KEY_EXCHANGE_BIT; } else if (message.isSecureMessage()) { type |= MessageTypes.SECURE_MESSAGE_BIT; } else if (message.isEndSession()) { type |= MessageTypes.END_SESSION_BIT; } //if (forceSms) type |= MessageTypes.MESSAGE_FORCE_SMS_BIT; /*ContentValues contentValues = new ContentValues(6); * contentValues.put(ADDRESS, PhoneNumberUtils.formatNumber(message.getRecipients().getPrimaryRecipient().getNumber())); * contentValues.put(THREAD_ID, threadId); * contentValues.put(BODY, message.getMessageBody()); * contentValues.put(DATE_RECEIVED, date); * contentValues.put(DATE_SENT, date); * contentValues.put(READ, 1); * contentValues.put(TYPE, type);*/ var insert = new Message() { //address = PhoneNumberUtils.formatNumber(message.getRecipients().getPrimaryRecipient().getNumber()), Address = message.getRecipients().getPrimaryRecipient().getNumber(), ThreadId = threadId, Body = message.getMessageBody(), DateReceived = date, DateSent = date, Read = false, Type = type }; //SQLiteDatabase db = databaseHelper.getWritableDatabase(); //long messageId = db.insert(TABLE_NAME, ADDRESS, contentValues); long messageId = conn.Insert(insert); // TODO: await DatabaseFactory.getThreadDatabase().update(threadId); notifyConversationListeners(threadId); //jobManager.add(new TrimThreadJob(context, threadId)); return(insert.MessageId); }