Dart Phone class search with flutter_contacts - flutter

I created a function (using flutter_contacts) that searches contacts on my Phone based on a given contact cell number (input - cellnumber) :
Contact? contact = contacts.firstWhereOrNull((c) => c.phones.contains(Phone(cellnumber)));
It works completely ok when I search for a number without "+" sign (e.g. 12345) and the contact in the contact list has a number without "+" (e.g. 12345).
But it doesn't work when I search for a number with "+" sign (e.g. +12345) and the contact has a number with plus (e.g. +12345).
Anyone knows why is that and how to fix it?

If you look at the code you will see that for the Phone class to be equal to another, there needs to be more components to match than just the phone number.
So to check for phone numbers only, you need to roll your own coparison:
Contact? contact = contacts.firstWhereOrNull((c) => c.phones.any((phone) => phone.number == cellNumber);
If this still does not match, print all the contacts to debug it. I have no idea what your contact list contains or why it would not match.
There is a normalizedNumber property, maybe you need to use that instead to figure out if someone used formatting like "+1 (234) 567-8900".

Related

Multiple conditional emails sent based on Google Form submission

I use the below script with a google form which sends an email to different people based on the answer chosen on the form. The script works and sends an email to the correct person when I use it with a form where the user can only choose one option.
But now I have a form where a user can choose between 1 and 6 options for the selection of cases to match. For every option chosen, I need an email to be sent to the corresponding department. With switch command, I understand that it tests an expression against a list of cases and returns the corresponding value of the first matching case. What I need is for it to test against a list of cases and return ALL corresponding values and then email based on that. Sometimes that would be one email, sometimes that could be 3 emails to 3 different people, etc.
The question on the google form is a checkbox question so a user can choose any and all if it applies. Each option correlates with a different email in my script.
Currently, if the form is filled out and only one option is chosen (see screenshot question "announcement outlet"), the script runs and sends the email as it should. But if two or more options are selected, no email goes out. When I check the trigger notes, the error is:
Exception: Failed to send email: no recipient
at sendFormByEmail(Code:47:13)
Here is my current script which works when only one option can be chosen. I believe I need a different command other than switch, but don't know what. I looked into fallthrough, but don't think that would work for this either.
function sendFormByEmail(e)
{      
// Remember to replace XYZ with your own email address  
var named_values = e.namedValues  
var teachername = named_values["Teacher Name"];    
var info = named_values["Your message/announcement"];  
var time = named_values["Please include time frame"];  
var photos = named_values["Include photos with this form if applicable; you can also create the graphic for social media and include below"];  
var announce = named_values["Choose announcement outlet"].toString();  
var email;
 
 // Optional but change the following variable  
// to have a custom subject for Google Docs emails  
  
// The variable e holds all the form values in an array.  
// Loop through the array and append values to the body.  
var message = "";      
for(var field in e.namedValues) {    
message += field + ' :: ' 
              + e.namedValues[field].toString() + "\n\n"; 
 }   
  switch (announce) {    
case "School Intercom Announcement":      
var email = "person1#school.net";      
break;    
case "MHHS Website":      
var email = "person2#school.net";      
break;    
case "MHHS Social Media (Instagram, Facebook, Twitter)":      
var email = "person3#school.net"     
break;    
case "Week in Pics":      
var email = "person4#school.net"  
var body = "Week in Pics Request"    
break;  
case "Remind text message (goes to students - please specify in your message info if it is all grades or specific grades)":
var email = "person5#school.net"
var subject = "Remind Text Request"
break;
case "Phone call home":
var email = "person6#school.net"
break;
}  
 // This is the MailApp service of Google Apps Script  
// that sends the email. You can also use GmailApp here.  
MailApp.sendEmail(email, subject, message);   
}
When multiple options are chosen, the data in the cell reads "Option 2, Option 4" and all my listed cases in the script above are for only "Option 2" or "Option 4", etc. Is there a way make this happen without having to make a case for every possible combination of the 6 choices that could potentially happen?
One way to fix the code
Remove .toString() from var announce = named_values["Choose announcement outlet"].toString();. Rationale: There is no need to convert an Array into a string for this case.
Instead of switch use if's, more specifically, add one if for each case clause, using an expression to test if the case label is included in announce. Example:
Replace
case "School Intercom Announcement":
by
if(announce.includes("School Intercom Announcement")){
// put here the case clause, don't include break;
// Add the following line before the closing `}` of the if statement
MailApp.sendEmail(email, subject, message);
}
Rationale: It's easier to implement the required control logic using if and Array.prototype.includes rather than doing it using switch.

BlackBerry 10 - Photos from partial contact

I am developing an application that needs to list all contacts in the phone's contacts list. Each cell needs to have the name of the contact and the corresponding photo (primaryPhoto).
I can do this, by fetching contactDetails for each contact. However, if the contacts list has a huge number of elements, this process is too slow. To handle this problem, I am not fetching the contact details and I am using the partial contacts retreived by
contacts = m_contactService->contacts(filter);
The only problem is that this list doesn't contain any photo! And I need the primaryPhoto available.
Is there a way to get the primaryPhoto from a partialContact without the need to fecth all contact details?
Thanks for your help
Implement the following after you get the list of contacts from this returned from the search filter
note: this is not pure C++, do not use this verbatim!
foreach contact in contacts
m_CPhoto = contact->primaryPhoto(); //returns the ContactPhoto id
// if necessary...
m_cPhotoList << m_CPhoto; // you can do this since this would be a list of ids
// to display the actual photo in your list view
m_CPhoto->smallPhoto();
// I only use 'small' since this is a list view; you may use 'original' or 'large'

How to send email to multiple addresses in range of cells that updates weekly?

I am a novice at programming. I have setup a google spreadsheet that will send a weekly email reminder to those who have upcoming assignments. The spreadsheet automatically pulls the 4 email addresses of those who are assigned each week and places them in A1, B1, A2, B2 (i.e. A1:B2). I want the script to find the 4 email addresses (that change each week) and send the same email to all four of them.
When I hardcode the cc recipients into the MailApp line, it works fine. But because the recipients list changes weekly I want to reference the cells A1:B2 instead. When I try to do that, I get an Invalid Email error. The debugger shows that var ccrecipients is picking up the right cells, but I think the problem is that it returns it as an array instead of as a string. That's as far as I'm able to reason through it.
A few snippets of my code:
var ccrecipients = sheet.getRange('A1:B2').getValues();
MailApp.sendEmail(recipients, subject, "", {htmlBody: message, cc: ccrecipients});
Thanks in advance for your help. I've relied heavily on these forums to put together the code that I have. I've always been able to find an answer, until this one. Thanks!
Your observation is almost correct, sheet.getRange('A1:B2').getValues(); return an array of arrays, something like [[A1,B1],[A2,B2]] A & B representing the values in the cells to simplify my example.
And what you need in the end is a "flat" string with all the needed recipients separated by commas "A1,B1,A2,B2".
The simplest way to do that is to flatten the whole thing,that will create a string with comma separations and that's exactly what we need.
sheet.getRange('A1:B2').getValues().toString();
That should do the trick ;-)

Blackberry, searching contacts from list

I want to add an Search Box in list Field. so that When i Enter a letter, then it will show the names starting with the letter 'A' , and so on. Iam using Vector to save the list of contacts same as the image shown :
If you want to select from the Contacts, use the ContactList.choose() method.
DO NOT try to iterate through the entire contacts your self every time. Remember there are lot of people having thousands of contacts and your code will be very unresponsive.
See: https://stackoverflow.com/a/4436816/371534
However, if you want to have 'filter as you type' kind of functionality with some other data, use the KeywordFilterField. You can get a sample code for it in the BlackBerry JDK samples.
Set a FieldChangeListener (or listen for alphanumeric key presses) to your EditField. Then refresh the list each time. Filtering on entries starting with the string contained in the EditField.
I wrote this on a pc without the Blackberry plugin installed, so couldn't test it, but it should be something like this.
String prefix = editField.getText();
Enumeration e = list.items();
while(e.hasMoreElements())
{
PIMItem item = (PIMItem) e.nextElement();
String name = item.getString(PIMItem.NAME,0);
if (name.startsWith(prefix))
{
//TODO display on screen
}
}

How can i get prefix pf phone number?

Hello everyone I am trying to get prefix of phone numbers in order to get the actual phone number without country dialing code. How can I achieve this?
Please note that the phone numbers can be
123456789
0099123456789
+9912345678
or any other formats with country code and area code etc..
if you tried like this then it will help some what but not sure ,
NSString *str=[PhoneNumber substringToIndex:[PhoneNumber length]-10];
Taking a look at the amount of different prefixes you can have List of country calling codes [wikipedia] and Internatioal dialing prefix [wikipedia], one could reach the conclusion that without narrowing the area down you'll probably not get very far with this.
If however you'll be handling phone numbers from a specific region to another specific region you might be able to come up with something.