private void ShowPendingContactOptions() { try { UIActionSheet actionSheet; actionSheet = new UIActionSheet(); if (!string.IsNullOrEmpty(this.mobile)) actionSheet.AddButton(this.mobile); if (!string.IsNullOrEmpty(this.email)) actionSheet.AddButton(this.email); actionSheet.AddButton("Cancel"); actionSheet.Clicked += delegate(object a, UIButtonEventArgs b) { using (var conn = new SQLite.SQLiteConnection(AppDelegate._dbPath)) { string recipient = ""; //int present_thread_id = 0; if (actionSheet.ButtonTitle(b.ButtonIndex) == this.mobile) { try { var phoneUtil = PhoneNumberUtil.GetInstance(); recipient = phoneUtil.Format(phoneUtil.Parse(this.mobile, AppDelegate.GetCountryCode()), PhoneNumberFormat.E164); } catch (Exception e) { recipient = this.mobile; } } else if (actionSheet.ButtonTitle(b.ButtonIndex) == this.email) { recipient = this.email; } if (actionSheet.ButtonTitle(b.ButtonIndex) != "Cancel") { /* List<PushChatThread> pctList = conn.Query<PushChatThread>("select * from PushChatThread"); foreach (PushChatThread pct in pctList) { if (pct.Number.Equals(recipient)) { present_thread_id = pct.ID; break; } } */ PushChatThread thread = conn.FindWithQuery<PushChatThread>("select * from PushChatThread where Number = ?", recipient); //if (present_thread_id == 0) { if (thread == null) { PushContact contact = conn.FindWithQuery<PushContact>("select * from PushContact where Number = ?", recipient); thread = new PushChatThread { DisplayName = contact.Name, Number = recipient, Recipient_id = 0, TimeStamp = AppDelegate.CurrentTimeMillis(), Message_count = 0, Snippet = "", Read = 0, Type = "PushLocal" }; conn.Insert(thread); conn.Commit(); conn.Close(); //present_thread_id = pct_val.ID; } //appDelegate.chatView.setThreadID(present_thread_id); appDelegate.chatView.setThreadID(thread.ID); appDelegate.chatView.setNumber(recipient); appDelegate.chatView.setThreadSelected(thread.DisplayName + " (" + recipient + ")"); appDelegate.GoToView(appDelegate.chatView); } } }; actionSheet.ShowInView(View); } catch (Exception ex) { Console.Write(ex.Message); } }
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(); }