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); }
public async static Task <long> send( OutgoingTextMessage message, long threadId) { //EncryptingSmsDatabase database = DatabaseFactory.getEncryptingSmsDatabase(context); TextMessageDatabase database = DatabaseFactory.getTextMessageDatabase(); Recipients recipients = message.Recipients; bool keyExchange = message.IsKeyExchange; long allocatedThreadId; if (threadId == -1) { allocatedThreadId = DatabaseFactory.getThreadDatabase().GetThreadIdForRecipients(recipients); } else { allocatedThreadId = threadId; } long messageId = database.InsertMessageOutbox(allocatedThreadId, message, TimeUtil.GetDateTimeMillis()); await sendTextMessage(recipients, keyExchange, messageId); return(allocatedThreadId); }
public async Task SendAsync(OutgoingTextMessage sms) { if (string.IsNullOrEmpty(sms.Number)) { throw new Exception("Sms Number is required"); } if (string.IsNullOrEmpty(sms.ReceiverCountryCode)) { throw new Exception("ReceiverCountryCode is required"); } var loopSms = new TextMessage { FullMessage = sms.Message, Message = sms.Message, OriginNumber = sms.Number, }; var msg = new Message { Body = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(loopSms, Formatting.Indented)), MessageId = Guid.NewGuid().ToString("n"), }; msg.UserProperties.Add("SenderSource", "Internal"); _logger.Information($"Sending sms: {sms.Number}| {sms.Message}"); await _sender.SendAsync(msg); }
/* * 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); }
private long handleSynchronizeSentTextMessage(SentTranscriptMessage message, May <long> smsMessageId) { var textMessageDatabase = DatabaseFactory.getTextMessageDatabase();//getEncryptingSmsDatabase(context); Recipients recipients = getSyncMessageDestination(message); String body = message.getMessage().getBody().HasValue ? message.getMessage().getBody().ForceGetValue() : ""; OutgoingTextMessage outgoingTextMessage = new OutgoingTextMessage(recipients, body); long threadId = DatabaseFactory.getThreadDatabase().GetThreadIdForRecipients(recipients); long messageId = textMessageDatabase.InsertMessageOutbox(threadId, outgoingTextMessage, TimeUtil.GetDateTime(message.getTimestamp())); textMessageDatabase.MarkAsSent(messageId); textMessageDatabase.MarkAsPush(messageId); textMessageDatabase.MarkAsSecure(messageId); if (smsMessageId.HasValue) { textMessageDatabase.Delete(smsMessageId.ForceGetValue()); } return(threadId); }
public long InsertMessageOutbox(long threadId, OutgoingTextMessage message, DateTime date) { var type = MessageTypes.BASE_OUTBOX_TYPE; 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; } var insert = new Message(); insert.Address = message.Recipients.PrimaryRecipient.Number; // PhoneNumberUtils.formatNumber(message.Recipients.getPrimaryRecipient().getNumber()); // TODO: insert.ThreadId = threadId; insert.Body = message.MessageBody; insert.DateReceived = TimeUtil.GetDateTimeMillis(); insert.DateSent = date; insert.Read = true; insert.Type = type; var tmp = new TextMessageRecord(insert); // TODO: debug conn.Insert(insert); long messageId = insert.MessageId; DatabaseFactory.getThreadDatabase().Update(threadId); notifyConversationListeners(threadId); //jobManager.add(new TrimThreadJob(context, threadId)); return(messageId); }
public Task SendAsync(OutgoingTextMessage sms) { if (string.IsNullOrEmpty(sms.Number)) { throw new Exception("Sms Number is required"); } if (string.IsNullOrEmpty(sms.ReceiverCountryCode)) { throw new Exception("ReceiverCountryCode is required"); } var msg = new Message { Body = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(sms, Formatting.Indented)), MessageId = Guid.NewGuid().ToString("n"), }; msg.UserProperties.Add("SenderSource", _settings.ServiceName); // msg.UserProperties.Add(nameof(Internals.BoundedContext), Internals.BoundedContext); _logger.Information($"Sending sms: {sms.Number}| {sms.Message}"); return(_sender.SendAsync(msg)); }