1
0
mirror of https://github.com/nerzhul/ocsms.git synced 2025-06-07 16:06:15 +00:00

Register conversations & add configMapper to smsmapper to use the phone number formatter

This commit is contained in:
Loic Blot 2018-05-17 13:02:03 +02:00
parent ed380fd09e
commit 68971b1d33
No known key found for this signature in database
GPG Key ID: EFAA458E8C153987
3 changed files with 16 additions and 10 deletions

View File

@ -33,6 +33,7 @@ class OcSmsApp extends App {
/** /**
* OcSmsApp constructor. * OcSmsApp constructor.
* @param array $urlParams * @param array $urlParams
* @throws \OCP\AppFramework\QueryException
*/ */
public function __construct (array $urlParams=array()) { public function __construct (array $urlParams=array()) {
parent::__construct('ocsms', $urlParams); parent::__construct('ocsms', $urlParams);
@ -60,7 +61,7 @@ class OcSmsApp extends App {
}); });
$container->registerService('Sms', function(IContainer $c) use ($server) { $container->registerService('Sms', function(IContainer $c) use ($server) {
return new Sms($server->getDb()); return new Sms();
}); });
$container->registerService('ConversationStateMapper', function(IContainer $c) use ($server) { $container->registerService('ConversationStateMapper', function(IContainer $c) use ($server) {
@ -70,7 +71,8 @@ class OcSmsApp extends App {
$container->registerService('SmsMapper', function(IContainer $c) use ($server) { $container->registerService('SmsMapper', function(IContainer $c) use ($server) {
return new SmsMapper( return new SmsMapper(
$server->getDatabaseConnection(), $server->getDatabaseConnection(),
$c->query('ConversationStateMapper') $c->query('ConversationStateMapper'),
$c->query('ConfigMapper')
); );
}); });
@ -117,10 +119,10 @@ class OcSmsApp extends App {
/** /**
* Migration services * Migration services
*/ */
$container->registerService('OCA\OcSms\Migration\FixConversationReadStates', function ($c) { $container->registerService('OCA\OcSms\Migration\FixConversationReadStates', function (IContainer $c) use($server) {
return new FixConversationReadStates( return new FixConversationReadStates(
$c->query('ConversationStateMapper'), $c->query('ConversationStateMapper'),
$c->getServer()->getUserManager() $server->getUserManager()
); );
}); });
} }

View File

@ -42,9 +42,10 @@ class SmsController extends Controller {
* @param IRequest $request * @param IRequest $request
* @param $userId * @param $userId
* @param SmsMapper $mapper * @param SmsMapper $mapper
* @param ConversationStateMapper $cmapper
* @param ConfigMapper $cfgMapper * @param ConfigMapper $cfgMapper
* @param IContactsManager $contactsManager * @param IContactsManager $contactsManager
* @param $urlGenerator * @param IURLGenerator $urlGenerator
*/ */
public function __construct ($appName, IRequest $request, $userId, public function __construct ($appName, IRequest $request, $userId,
SmsMapper $mapper, ConversationStateMapper $cmapper, SmsMapper $mapper, ConversationStateMapper $cmapper,

View File

@ -33,10 +33,12 @@ class SmsMapper extends Mapper {
6 => "queued" 6 => "queued"
); );
private $convStateMapper; private $convStateMapper;
private $configMapper;
public function __construct (IDBConnection $db, ConversationStateMapper $cmapper) { public function __construct (IDBConnection $db, ConversationStateMapper $cmapper, ConfigMapper $configMapper) {
parent::__construct($db, 'ocsms_smsdatas'); parent::__construct($db, 'ocsms_smsdatas');
$this->convStateMapper = $cmapper; $this->convStateMapper = $cmapper;
$this->configMapper = $configMapper;
} }
public function getAllIds ($userId) { public function getAllIds ($userId) {
@ -379,12 +381,13 @@ class SmsMapper extends Mapper {
(int) $sms["type"] (int) $sms["type"]
)); ));
/* $configuredCountry = $this->configMapper->getCountry();
$conversation = $this->getConversationForUserAndPhone($userId, $sms["address"]); $fmtPhoneNumber = PhoneNumberFormatter::format($configuredCountry, $sms["address"]);
$conversation = $this->getConversationForUserAndPhone($userId, $fmtPhoneNumber);
if ($conversation === null) { if ($conversation === null) {
$this->registerConversation($userId, $sms["address"]); $this->registerConversation($userId, $fmtPhoneNumber);
} }
*/
} }
$this->db->commit(); $this->db->commit();