Replace sendMessage recursion with a clean do-while loop.

parent 096bd751
...@@ -381,8 +381,6 @@ class Request ...@@ -381,8 +381,6 @@ class Request
/** /**
* Send message * Send message
* *
* @todo Could do with some cleaner recursion
*
* @param array $data * @param array $data
* *
* @return mixed * @return mixed
...@@ -390,17 +388,18 @@ class Request ...@@ -390,17 +388,18 @@ class Request
*/ */
public static function sendMessage(array $data) public static function sendMessage(array $data)
{ {
$text = $data['text']; $text = $data['text'];
$string_len_utf8 = mb_strlen($text, 'UTF-8');
if ($string_len_utf8 > 4096) { do {
//Chop off and send the first message
$data['text'] = mb_substr($text, 0, 4096); $data['text'] = mb_substr($text, 0, 4096);
self::send('sendMessage', $data); $response = self::send('sendMessage', $data);
$data['text'] = mb_substr($text, 4096, $string_len_utf8);
return self::sendMessage($data); //Prepare the next message
} $text = mb_substr($text, 4096);
} while (mb_strlen($text, 'UTF-8') > 0);
return self::send('sendMessage', $data); return $response;
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment