Skip to content

Commit 51731fd

Browse files
committed
Merge remote-tracking branch 'remotes/upstream/master'
2 parents 0f52e06 + 832a2da commit 51731fd

File tree

5 files changed

+139
-101
lines changed

5 files changed

+139
-101
lines changed

src/Embera/Adapter.php

+38
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88

99
namespace Nahid\Talk\Embera;
1010

11+
<<<<<<< HEAD
12+
=======
13+
14+
>>>>>>> remotes/upstream/master
1115
use Embera\Adapters\Service;
1216

1317
/**
@@ -17,6 +21,7 @@
1721
*/
1822
class Adapter extends Service
1923
{
24+
<<<<<<< HEAD
2025
protected $config;
2126

2227
/**
@@ -48,4 +53,37 @@ protected function validateUrl()
4853

4954
return preg_match('#' . $parsedUrl['host'] . '#i', (string) $this->url);
5055
}
56+
=======
57+
protected $config;
58+
59+
/**
60+
* Adapter constructor.
61+
*
62+
* @param string $url
63+
* @param array $config
64+
* @param $oembed
65+
*/
66+
public function __construct($url, array $config = array(), $oembed)
67+
{
68+
$this->apiUrl = config('talk.oembed.url');
69+
parent::__construct($url, $config, $oembed);
70+
}
71+
72+
/**
73+
* Validates that the url belongs to this service.
74+
* Should be implemented on all children and should
75+
* return a boolean (preg_match returns 0 or 1 that
76+
* is why I'm also allowing 'int' as a return type).
77+
*
78+
* The current url is made available via $this->url
79+
*
80+
* @return bool|int
81+
*/
82+
protected function validateUrl()
83+
{
84+
$parsedUrl = parse_url($this->apiUrl);
85+
86+
return preg_match('#' . $parsedUrl['host'] . '#i', (string)$this->url);
87+
}
88+
>>>>>>> remotes/upstream/master
5189
}

src/Html/HtmlString.php

+66-66
Original file line numberDiff line numberDiff line change
@@ -8,80 +8,80 @@
88

99
class HtmlString implements Htmlable
1010
{
11-
/**
12-
* @var string
13-
*/
14-
protected $string;
11+
/**
12+
* @var string
13+
*/
14+
protected $string;
1515

16-
/**
17-
* @var Embera
18-
*/
19-
protected $driver;
16+
/**
17+
* @var Embera
18+
*/
19+
protected $driver;
2020

21-
/**
22-
* HtmlString constructor.
23-
*
24-
* @param $string
25-
*/
26-
public function __construct($string, Embera $driver)
27-
{
28-
$this->setDriver($driver);
29-
$this->setString($string);
30-
}
21+
/**
22+
* HtmlString constructor.
23+
*
24+
* @param $string
25+
*/
26+
public function __construct($string, Embera $driver)
27+
{
28+
$this->setDriver($driver);
29+
$this->setString($string);
30+
}
3131

32-
/**
33-
* Get content as a string of HTML.
34-
*
35-
* @return string
36-
*/
37-
public function toHtml()
38-
{
39-
if (config('talk.oembed.enabled')) {
40-
$parsedUrl = parse_url(config('talk.oembed.url'));
41-
$this->driver->addProvider(
42-
$parsedUrl['host'],
43-
Adapter::class,
44-
[
45-
'api_key' => config('talk.oembed.key'),
46-
]
47-
);
48-
}
32+
/**
33+
* Get content as a string of HTML.
34+
*
35+
* @return string
36+
*/
37+
public function toHtml()
38+
{
39+
if (config('talk.oembed.enabled')) {
40+
$parsedUrl = parse_url(config('talk.oembed.url'));
41+
$this->driver->addProvider(
42+
$parsedUrl['host'],
43+
Adapter::class,
44+
[
45+
'api_key' => config('talk.oembed.key'),
46+
]
47+
);
48+
}
4949

50-
$result = $this->driver->autoEmbed($this->string);
50+
$result = $this->driver->autoEmbed($this->string);
5151

52-
return $result;
53-
}
52+
return $result;
53+
}
5454

55-
/**
56-
* @return string
57-
*/
58-
public function getString()
59-
{
60-
return $this->string;
61-
}
55+
/**
56+
* @return string
57+
*/
58+
public function getString()
59+
{
60+
return $this->string;
61+
}
6262

63-
/**
64-
* @param string $string
65-
*/
66-
public function setString($string)
67-
{
68-
$this->string = $string;
69-
}
63+
/**
64+
* @param string $string
65+
*/
66+
public function setString($string)
67+
{
68+
$this->string = $string;
69+
}
7070

71-
/**
72-
* @return Embera
73-
*/
74-
public function getDriver()
75-
{
76-
return $this->driver;
77-
}
71+
/**
72+
* @return Embera
73+
*/
74+
public function getDriver()
75+
{
76+
return $this->driver;
77+
}
7878

79-
/**
80-
* @param Embera $driver
81-
*/
82-
public function setDriver($driver)
83-
{
84-
$this->driver = $driver;
85-
}
79+
/**
80+
* @param Embera $driver
81+
*/
82+
public function setDriver($driver)
83+
{
84+
$this->driver = $driver;
85+
}
8686

8787
}

src/Html/HtmlStringInterface.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212

1313
interface HtmlStringInterface
1414
{
15-
/**
16-
* @return Htmlable
17-
*/
18-
public function toHtmlString();
15+
/**
16+
* @return Htmlable
17+
*/
18+
public function toHtmlString();
1919
}

src/Messages/Message.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class Message extends Model implements HtmlStringInterface
3535
public function getHumansTimeAttribute()
3636
{
3737
//laravel sometimes has $this=null but attributes proprty works perfectly well
38-
$date = \Carbon\Carbon::parse($this->attributes['created_at']);
38+
$date = Carbon::parse($this->attributes['created_at']);
3939
$now = $date->now();
4040

4141
return $date->diffForHumans($now, true);

src/Messages/MessageRepository.php

+30-30
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,34 @@
66

77
class MessageRepository extends Repository
88
{
9-
public function takeModel()
10-
{
11-
return Message::class;
12-
}
13-
14-
public function deleteMessages($conversationId)
15-
{
16-
return (boolean) Message::where('conversation_id', $conversationId)->delete();
17-
}
18-
19-
public function softDeleteMessage($messageId, $authUserId)
20-
{
21-
$message = $this->with(['conversation' => function ($q) use ($authUserId) {
22-
$q->where('user_one', $authUserId);
23-
$q->orWhere('user_two', $authUserId);
24-
}])->find($messageId);
25-
26-
if (is_null($message->conversation)) {
27-
return false;
28-
}
29-
30-
if ($message->user_id == $authUserId) {
31-
$message->deleted_from_sender = 1;
32-
} else {
33-
$message->deleted_from_receiver = 1;
34-
}
35-
36-
return (boolean) $this->update($message);
37-
38-
}
9+
public function takeModel()
10+
{
11+
return Message::class;
12+
}
13+
14+
public function deleteMessages($conversationId)
15+
{
16+
return (boolean) Message::where('conversation_id', $conversationId)->delete();
17+
}
18+
19+
public function softDeleteMessage($messageId, $authUserId)
20+
{
21+
$message = $this->with(['conversation' => function ($q) use ($authUserId) {
22+
$q->where('user_one', $authUserId);
23+
$q->orWhere('user_two', $authUserId);
24+
}])->find($messageId);
25+
26+
if (is_null($message->conversation)) {
27+
return false;
28+
}
29+
30+
if ($message->user_id == $authUserId) {
31+
$message->deleted_from_sender = 1;
32+
} else {
33+
$message->deleted_from_receiver = 1;
34+
}
35+
36+
return (boolean) $this->update($message);
37+
38+
}
3939
}

0 commit comments

Comments
 (0)