Created
July 8, 2019 16:27
-
-
Save dongido001/9aaa0e05ea9ac4cd5c3c12935fe209e6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// [...] | |
/** | |
* Create or get channel | |
*/ | |
public function createOrGetChannel(Request $request) | |
{ | |
$from = $request->input('from'); | |
$to = $request->input('to'); | |
$from_username = $request->input('from_username'); | |
$to_username = $request->input('to_username'); | |
$channel = Channel::whereIn('from_id', [$from, $to]) | |
->whereIn('to_id', [$from, $to]) | |
->first(); | |
// If channel if already created,return it else create it. | |
if ($channel) { | |
$channel_name = $channel->name; | |
} else { | |
$channel_name = "private-{$from_username}-{$to_username}"; | |
$channel = new Channel(); | |
$channel->name = $channel_name; | |
$channel->from_id = $from; | |
$channel->to_id = $to; | |
$channel->save(); | |
// Create channel to Stream Chat | |
$channel = $this->client->getChannel("messaging", $channel_name); | |
$channel->create($from_username, [$to_username]); | |
} | |
return response()->json([ | |
'channel' => $channel_name | |
], 200); | |
} | |
// [...] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment