Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-12235] BlackBerry: Implement important Titanium.Contacts functionality

GitHub Issuen/a
TypeNew Feature
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2014-06-12T11:34:54.000+0000
Affected Version/sn/a
Fix Version/s2013 Sprint 12 BB, 2013 Sprint 12, Release 3.1.2, Release 3.2.0, Release 3.3.0
ComponentsBlackBerry
Labelscontacts, notable, qe-3.3.0, qe-testadded, regression
ReporterRussell McMahon
AssigneePedro Enrique
Created2013-01-07T13:19:43.000+0000
Updated2014-06-20T18:19:44.000+0000

Description

Comments

  1. Pedro Enrique 2013-05-31

    PR: https://github.com/appcelerator/titanium_mobile_blackberry/pull/63
  2. Josh Roesslein 2013-06-05

    Left code review comments on the pull request.
  3. Josh Roesslein 2013-06-12

    Tested the pull request and ran into some issues. Left comments on the pull request describing the issues.
  4. Russell McMahon 2013-07-26

    Test 1
       function Label(_title, _message) {
           if(typeof _message == 'object') {
               _message = JSON.stringify(_message)
           }
           return Ti.UI.createLabel({
               top: 10,
               left: 10,
               text: _title + ': ' + _message
           });
       }
       
       function ContactWindow(_contactId) {
       
       	var contact = Ti.Contacts.getPersonByID(_contactId);
           Ti.API.info(JSON.stringify(contact.address));
           
           var win = Ti.UI.createWindow();
           var scrollView = Ti.UI.createScrollView({
              layout: 'vertical',
              top: 0,
              height: Ti.UI.FILL
           });
           var closeButton = Ti.UI.createButton({
               top: 0,
           	title: 'close'
           });
       
           scrollView.add(closeButton);
           scrollView.add(Label('address',contact.address));
           scrollView.add(Label('birthday',contact.birthday));
           scrollView.add(Label('created',contact.created));
           scrollView.add(Label('department',contact.department));
           scrollView.add(Label('email',contact.email));
           scrollView.add(Label('firstName', contact.firstName));
           scrollView.add(Label('fullName', contact.fullName));
           scrollView.add(Label('firstPhonetic', contact.firstPhonetic));
           scrollView.add(Label('id', contact.id));
           scrollView.add(Label('image', contact.image));
           scrollView.add(Label('instantMessage', contact.instantMessage));
           scrollView.add(Label('jobTitle', contact.jobTitle));
           scrollView.add(Label('kind', contact.kind));
           scrollView.add(Label('lastName', contact.lastName));
           scrollView.add(Label('lastPhonetic', contact.lastPhonetic));
           scrollView.add(Label('middleName', contact.middleName));
           scrollView.add(Label('middlePhonetic', contact.middlePhonetic));
           scrollView.add(Label('modified', contact.modified));
           scrollView.add(Label('nickname', contact.nickname));
           scrollView.add(Label('note', contact.note));
           scrollView.add(Label('organization', contact.organization));
           scrollView.add(Label('phone', contact.phone));
           scrollView.add(Label('prefix', contact.prefix));
           scrollView.add(Label('recordId', contact.recordId));
           scrollView.add(Label('relatedNames', contact.relatedNames));
           scrollView.add(Label('suffix', contact.suffix));
           scrollView.add(Label('url', contact.url));
       
           win.add(scrollView);
           
           closeButton.addEventListener('click', function() {
               win.close();
           });
           return win;
       }
       
       
       
       function createContact(){
           Ti.Contacts.createPerson({
                 firstName: 'Paul',
                 lastName: 'Dowsett',
                 address:{
                   work:[
                     {
                       CountryCode: 'gb', // determines how the address is displayed
                       Street: '200 Brook Drive\nGreen Park',
                       City: 'Reading',
                       County: 'Berkshire',
                       Country: 'England',
                       ZIP: 'RG2 6UB'
                     },
                     {
                       CountryCode: 'gb', // determines how the address is displayed
                       Street: '1 St Pauls Road\nClerkenwell',
                       City: 'City of London',
                       State: 'London',
                       Country: 'England',
                       ZIP: 'EC1 1AA'
                     }
                   ],
                   home:[
                     {
                       CountryCode: 'gb', // determines how the address is displayed
                       Street: '2 Boleyn Court',
                       City: 'London',
                       State: 'Greenwich',
                       Country: 'England',
                       ZIP: 'SE10'
                     }
                   ]
                 },
                 birthday: new Date(),
                 instantMessage:{
               	  AIM: ['leisureAIM'],
               	  MSN: ['no_paul_here@msn.com', 'lala@lala.com'],
               	  skype: ['pec1985', 'pecdev']
                 },
                 organization: 'Appcelerator',
                 phone:{
                   mobile: ['07900 000001', '07900 000002'],
                   work: ['+44 (0)118 925 6128', '+44 (0)118 000 0000']
                 },
                 url:{
                   homepage: ['www.google.com'],
                   work: ['www.appcelerator.com', 'www.example.com']
                 }
               });
       
       }
       function MainWindow() {
           
           var allContacts = Ti.Contacts.getAllPeople();
           var createButton = Ti.UI.createButton({
               title: 'create contact',
               top: 0,
               height: Ti.UI.SIZE
           });
           
       
           var tableData = [];
           for(var i = 0, len = allContacts.length; i < len; i++) {
               tableData.push({
                   title: allContacts[i].firstName + ' ' + allContacts[i].lastName,
                   contactId: allContacts[i].id
               });
           }
       
           var win = Ti.UI.createWindow({
           	layout:'vertical'
           });
       
           createButton.addEventListener('click', function(){
           	alert('creating contact, please look at the phone\'s address book')
           	createContact();
           });
           var v = Ti.UI.createView({
           	top: 0,
           	height: Ti.UI.FILL
           });
           var table = Ti.UI.createTableView({
               data: tableData
           });
       
           table.addEventListener('click', function(e){
               ContactWindow(e.rowData.contactId).open();
           });
           v.add(table);
           win.add(createButton);
           win.add(v);
           
           return win;
       }
       
       MainWindow().open();
       
  5. Lokesh Choudhary 2013-08-09

    Verified the feature & now we can create a contact in BB successfully with the given code. Thus closing Environment: Appcel Studio : 3.1.2.201308082014 Ti SDK : 3.1.2.v20130808180613 Mac OSX : 10.8.4 Alloy : 1.2.0-alpha6 CLI - 3.1.2-alpha win 7 Win 8 Z10 BB simulator : 10.0.10.822 Z10 device running 10.0.10.88
  6. Olga Romero 2014-05-28

    Tested with: Mac osx 10.9.3 Mavericks Appcelerator Studio, build: 3.3.0.201405271647 Titanium SDK, build: 3.3.0.v20140524224144 Node.JS Version: v0.10.13 NPM Version: 1.3.2 acs@1.0.14 alloy@1.4.0-beta npm@1.3.2 titanium@3.3.0-beta titanium-code-processor@1.1.1 Device: BB Z10 (10.2.1)

    Steps

    1. Click "create contact" 2. Dismiss the alert and check the phone contacts

    Actual result

    no log output no contact has been created
  7. Pedro Enrique 2014-05-30

    I'm investigating, not sure why this is failing. It could be a BB bug since this is also failing with a simple native app. This is the actual error I'm getting when debugging the Titanium app through Momentics:
       * About to connect() to 127.0.0.1 port 8888 (#0)
       *   Trying 127.0.0.1...
       * TCP_NODELAY set
       * Local Interface lo0 is ip 127.0.0.1 using address family 2
       * Local port: 0
       * connected
       * Connected to 127.0.0.1 (127.0.0.1) port 8888 (#0)
       > PUT /contact/4/0?enterprise=0 HTTP/1.1
       Host: 127.0.0.1:8888
       Accept: */*
       Content-Type: application/x-www-form-urlencoded
       pim-session: 299074c3-cd26-4c2f-9ecb-77468dea5695
       api-version: 1.0
       User-Agent: com.app.timob12235.testDev__timob1223591d878c2
       Content-Length: 2079
       
       * We are completely uploaded and fine
       < HTTP/1.1 500 Internal Server Error
       < Content-Length: 21
       < Content-Type: application/json
       < Date: Fri, 30 May 2014 06:40:01 GMT
       < Server: BLACKBERRY-D20A
       < 
       * Closing connection #0
       PIMCoreAccessPool::getPca   0  Thread Id  0x1 
       PIMCoreAccessPool::getPca a new PimAccess   0 
       POST   0x1   
       Curl Easy perform 
       Curl Easy GetInfo response code 
       Curl easy getInfo content_length_download 
       Curl Error Code 0 
       Response Code 500 
       Status Code 500 
       Exception String "'attributes'" 
       Error occurred! Investigate!  createContactHelper  L 565 
       PIMCoreAccessPool::getPca   0  Thread Id  0x1 
       PIMCoreAccessPool::getPca a new PimAccess   0 
       updateContact called with account id  4   contact id:  0 
       PUT   0x1   
       Curl Easy perform 
       Curl Easy GetInfo response code 
       Curl easy getInfo content_length_download 
       Curl Error Code 0 
       Response Code 500 
       Status Code 500 
       Exception String "" 
       
  8. Ingo Muschenetz 2014-06-09

    [~penrique] Can you please log a bug with BB for this?
  9. Pedro Enrique 2014-06-12

    Ok, figured it out. When we first implemented this, it worked and now it does not. When a contact if first created in Titanium, an empty BB contact was created and then updated as properties are passed in the object. This now fails as BB does not allow us to create an empty contact. Fixed it by checking if the created contact is valid before updating it, and then added the property. PR: https://github.com/appcelerator/titanium_mobile_blackberry/pull/266
  10. Pedro Enrique 2014-06-12

    Please use this code for testing. It incrementes the contacts first name, last name, etc... so that duplicated can be created and better tested.
        function Label(_title, _message) {
            if(typeof _message == 'object') {
                _message = JSON.stringify(_message)
            }
            return Ti.UI.createLabel({
                top: 10,
                left: 10,
                text: _title + ': ' + _message
            });
        }
         
        function ContactWindow(_contactId) {
         
            var contact = Ti.Contacts.getPersonByID(_contactId);
            Ti.API.info(JSON.stringify(contact.address));
             
            var win = Ti.UI.createWindow();
            var scrollView = Ti.UI.createScrollView({
               layout: 'vertical',
               top: 0,
               height: Ti.UI.FILL,
               width: Ti.UI.FILL,
               contentHeight: Ti.UI.SIZE,
               contentWidth: Ti.UI.FILL
            });
            var closeButton = Ti.UI.createButton({
                top: 0,
                title: 'close'
            });
         
            scrollView.add(closeButton);
            scrollView.add(Label('address',contact.address));
            scrollView.add(Label('birthday',contact.birthday));
            scrollView.add(Label('created',contact.created));
            scrollView.add(Label('department',contact.department));
            scrollView.add(Label('email',contact.email));
            scrollView.add(Label('firstName', contact.firstName));
            scrollView.add(Label('fullName', contact.fullName));
            scrollView.add(Label('firstPhonetic', contact.firstPhonetic));
            scrollView.add(Label('id', contact.id));
            scrollView.add(Label('image', contact.image));
            scrollView.add(Label('instantMessage', contact.instantMessage));
            scrollView.add(Label('jobTitle', contact.jobTitle));
            scrollView.add(Label('kind', contact.kind));
            scrollView.add(Label('lastName', contact.lastName));
            scrollView.add(Label('lastPhonetic', contact.lastPhonetic));
            scrollView.add(Label('middleName', contact.middleName));
            scrollView.add(Label('middlePhonetic', contact.middlePhonetic));
            scrollView.add(Label('modified', contact.modified));
            scrollView.add(Label('nickname', contact.nickname));
            scrollView.add(Label('note', contact.note));
            scrollView.add(Label('organization', contact.organization));
            scrollView.add(Label('phone', contact.phone));
            scrollView.add(Label('prefix', contact.prefix));
            scrollView.add(Label('recordId', contact.recordId));
            scrollView.add(Label('relatedNames', contact.relatedNames));
            scrollView.add(Label('suffix', contact.suffix));
            scrollView.add(Label('url', contact.url));
         
            win.add(scrollView);
             
            closeButton.addEventListener('click', function() {
                win.close();
            });
            return win;
        }
         
         var x = 0;
         
        function createContact(){
            Ti.Contacts.createPerson({
                  firstName: 'Paul ' + (x++),
                  lastName: 'Dowsett ' + (x++),
                  address:{
                    work:[
                      {
                        CountryCode: 'gb', // determines how the address is displayed
                        Street: '200 Brook Drive\nGreen Park ' + (x++),
                        City: 'Reading',
                        County: 'Berkshire',
                        Country: 'England',
                        ZIP: 'RG2 6UB'
                      },
                      {
                        CountryCode: 'gb', // determines how the address is displayed
                        Street: '1 St Pauls Road\nClerkenwell ' + (x++),
                        City: 'City of London',
                        State: 'London',
                        Country: 'England',
                        ZIP: 'EC1 1AA'
                      }
                    ],
                    home:[
                      {
                        CountryCode: 'gb', // determines how the address is displayed
                        Street: '2 Boleyn Court ' + (x++),
                        City: 'London',
                        State: 'Greenwich',
                        Country: 'England',
                        ZIP: 'SE10'
                      }
                    ]
                  },
                  birthday: new Date(),
                  instantMessage:{
                      AIM: ['leisureAIM ' + (x++)],
                      MSN: ['no_paul_here@msn.com', 'lala@lala.com'],
                      skype: ['pec1985 ' + (x++), 'pecdev ' + (x++)]
                  },
                  organization: 'Appcelerator ' + (x++),
                });
         
        }
        function MainWindow() {
             
            var allContacts = Ti.Contacts.getAllPeople();
            var createButton = Ti.UI.createButton({
                title: 'create contact',
                top: 0,
                height: Ti.UI.SIZE
            });
             
         
            var tableData = [];
            for(var i = 0, len = allContacts.length; i < len; i++) {
                tableData.push({
                    title: allContacts[i].firstName + ' ' + allContacts[i].lastName,
                    contactId: allContacts[i].id
                });
            }
         
            var win = Ti.UI.createWindow({
                layout:'vertical'
            });
         
            createButton.addEventListener('click', function(){
                createContact();
                alert('creating contact, please look at the phone\'s address book')
                setTimeout(function(){
                  var tableData = [];
                  var allContacts = Ti.Contacts.getAllPeople();
                  for(var i = 0, len = allContacts.length; i < len; i++) {
                      tableData.push({
                          title: allContacts[i].firstName + ' ' + allContacts[i].lastName,
                          contactId: allContacts[i].id
                      });
                  }
                  table.data = tableData;
                }, 300);
            });
            var v = Ti.UI.createView({
                top: 0,
                height: Ti.UI.FILL
            });
            var table = Ti.UI.createTableView({
                data: tableData
            });
         
            table.addEventListener('click', function(e){
                ContactWindow(e.rowData.contactId).open();
            });
            v.add(table);
            win.add(createButton);
            win.add(v);
             
            return win;
        }
         
        MainWindow().open();
        
  11. Samuel Dowse 2014-06-18

    Verified fixed on: Mac OSX 10.9.3 Appcelerator Studio, build: 3.3.0.201406111953 Titanium SDK, build: 3.3.0.v20140617161713 Titanium CLI, build: 3.3.0-rc Alloy: 1.4.0-rc BlackBerry SDK, build: 10.2.0.1155 BlackBerry Simulator: 10.3.0.440 BlackBerry Device: 10.2.1.2947 Contact is created successfully. Closing.

JSON Source