private void updateChatThread(IncomingMessage message, string msg)
		{
			// Figure out where the SQLite database will be.
			var conn = new SQLite.SQLiteConnection(_dbPath);
			String number = message.Sender;
			// Check if there is an existing thread for this sender

			PushChatThread thread = conn.FindWithQuery<PushChatThread>("select * from PushChatThread where Number = ?", number);
			if (thread != null) {
				conn.Execute("UPDATE PushChatThread Set Snippet = ?, TimeStamp = ?, Message_count = ?, Read = ?, Type = ? WHERE ID = ?", msg, message.MessageId, 1, 1, "Push", thread.ID);
				conn.Commit();
			} else {
				PushContact contact = conn.FindWithQuery<PushContact>("select * from PushContact where Number = ?", number);
				thread = new PushChatThread {
					DisplayName = contact.Name,
					Number = number,
					Recipient_id = 0,
					TimeStamp = Convert.ToInt64(message.MessageId),
					Message_count = 1,
					Snippet = msg,
					Read = 1,
					Type = "Push"
				};
				conn.Insert(thread);
				//conn.Execute("UPDATE PushChatThread Set Recipient_id = ? WHERE Number = ?", present_thread_id, sender);
			}

			var pmessage = new PushMessage {
				Thread_id = thread.ID,
				Number = number,
				TimeStamp = CurrentTimeMillis(),
				TimeStamp_Sent = Convert.ToInt64(message.MessageId),
				Read = 1,
				Message = msg,
				Status = true,
				Service = "Push"
			};
			conn.Insert(pmessage);
			conn.Commit();
			conn.Close();
			RefreshChatListView();
		}
예제 #2
0
		private async void SendMessageThread(bool isattachment, string message)
		{
			DateTime now = DateTime.Now;
			const string format = "ddd HH:mm tt";
			bool delivered = false;
			try {
				MessageManager.SendMessage(MessageManager.PrepareOutgoingMessage(message, Number));
				delivered = true;
			} catch (StaleDevicesException e) {
				MessageManager.EndSession(Number);
			} catch (Exception e) {
				
				Console.WriteLine("Exception while sending message...." + e.Message);
			}

			using (var conn = new SQLite.SQLiteConnection(AppDelegate._dbPath)) {
				var pmessage = new PushMessage {
					Thread_id = ThreadID,
					Number = Number,
					TimeStamp = AppDelegate.CurrentTimeMillis(),
					TimeStamp_Sent = Convert.ToInt64(AppDelegate.CurrentTimeMillis()),
					Read = 0,
					Message = message,
					Status = delivered,
					Service = "PushLocal"
				};
				conn.Insert(pmessage);
				conn.Commit();
				conn.Close();
			}

			PointF pf = new PointF(0f, (messages.Count + 3) * 64 - table.Bounds.Size.Height);
			table.SetContentOffset(pf, true);

			ChatBubbleCell cell = new ChatBubbleCell(false, false, delivered);
			cell.Update(message, now.ToString(format));
			TableRowHeight = cell.getHeight();
			if (!delivered)
				cell.SetAsUndelivered();
			if (isattachment)
				cell.setImagePreview(thumbnail);
			LoadTable(cell);

			AddDataToConversation();
		}