-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RES-1910 Event chat and attendee count inconsistencies #668
Merged
Merged
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
bfdb9bb
Merge branch 'RES-1885_vue_event_create_edit' into RES-1910_event_cha…
edwh 4cec8ed
Move maintenance of volunteer count/Discourse thread into an Observer.
edwh 006969c
Queue up Discourse thread operations rather than do inline.
edwh 3818e3d
Test fixes.
edwh c712411
Merge branch 'develop' into RES-1910_event_chat_counts
edwh cffacfa
Implement remove from Discourse private message.
edwh c7dc679
Observer not invoked for bulk deletes.
edwh 30b3ad2
Merge branch 'develop' into RES-1910_event_chat_counts
edwh 662cf6a
Review comments.
edwh 74b7a91
Tweak logic for adding a host.
edwh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace App\Events; | ||
|
||
use App\Group; | ||
use Illuminate\Broadcasting\Channel; | ||
use Illuminate\Broadcasting\InteractsWithSockets; | ||
use Illuminate\Broadcasting\PresenceChannel; | ||
use Illuminate\Broadcasting\PrivateChannel; | ||
use Illuminate\Contracts\Broadcasting\ShouldBroadcast; | ||
use Illuminate\Foundation\Events\Dispatchable; | ||
use Illuminate\Queue\SerializesModels; | ||
|
||
class UserConfirmedEvent | ||
{ | ||
use Dispatchable, InteractsWithSockets, SerializesModels; | ||
|
||
public $idevents; | ||
public $iduser; | ||
|
||
/** | ||
* Create a new event instance. | ||
* | ||
* @return void | ||
*/ | ||
public function __construct($idevents, $iduser) | ||
{ | ||
$this->idevents = $idevents; | ||
$this->iduser = $iduser; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace App\Events; | ||
|
||
use App\Group; | ||
use Illuminate\Broadcasting\Channel; | ||
use Illuminate\Broadcasting\InteractsWithSockets; | ||
use Illuminate\Broadcasting\PresenceChannel; | ||
use Illuminate\Broadcasting\PrivateChannel; | ||
use Illuminate\Contracts\Broadcasting\ShouldBroadcast; | ||
use Illuminate\Foundation\Events\Dispatchable; | ||
use Illuminate\Queue\SerializesModels; | ||
|
||
class UserLeftEvent | ||
{ | ||
use Dispatchable, InteractsWithSockets, SerializesModels; | ||
|
||
public $idevents; | ||
public $iduser; | ||
|
||
/** | ||
* Create a new event instance. | ||
* | ||
* @return void | ||
*/ | ||
public function __construct($idevents, $iduser) | ||
{ | ||
$this->idevents = $idevents; | ||
$this->iduser = $iduser; | ||
} | ||
} |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
namespace App\Listeners; | ||
|
||
use App\Events\UserConfirmedEvent; | ||
use App\Party; | ||
use App\Role; | ||
use App\Services\DiscourseService; | ||
use App\User; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
|
||
class AddUserToDiscourseThreadForEvent implements ShouldQueue { | ||
private $discourseService; | ||
|
||
public function __construct(DiscourseService $discourseService) | ||
{ | ||
$this->discourseService = $discourseService; | ||
} | ||
|
||
private function getHost($idevents) { | ||
$hosts = User::join('events_users', 'events_users.user', '=', 'users.id') | ||
->where('events_users.event', $idevents) | ||
->where('events_users.role', Role::HOST) | ||
->select('users.*') | ||
->get(); | ||
|
||
return $hosts->count() ? $hosts[0] : null; | ||
} | ||
|
||
public function handle(UserConfirmedEvent $e) { | ||
if ($e->iduser) { | ||
$event = Party::find($e->idevents); | ||
$user = User::find($e->iduser); | ||
|
||
// Might not exist - timing windows. | ||
if ($event && $user && $event->discourse_thread) { | ||
// We need a host of the event to add the user to the thread. | ||
$host = $this->getHost($event->idevents); | ||
|
||
if ($host) { | ||
$this->discourseService->addUserToPrivateMessage( | ||
$event->discourse_thread, | ||
$host->username, | ||
$user->username | ||
); | ||
} | ||
} | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
namespace App\Listeners; | ||
|
||
use App\Events\UserLeftEvent; | ||
use App\Party; | ||
use App\Role; | ||
use App\Services\DiscourseService; | ||
use App\User; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
|
||
class RemoveUserFromDiscourseThreadForEvent implements ShouldQueue { | ||
private $discourseService; | ||
|
||
public function __construct(DiscourseService $discourseService) | ||
{ | ||
$this->discourseService = $discourseService; | ||
} | ||
|
||
private function getHost($idevents) { | ||
$hosts = User::join('events_users', 'events_users.user', '=', 'users.id') | ||
->where('events_users.event', $idevents) | ||
->where('events_users.role', Role::HOST) | ||
->select('users.*') | ||
->get(); | ||
|
||
return $hosts->count() ? $hosts[0] : null; | ||
} | ||
|
||
public function handle(UserLeftEvent $e) { | ||
if ($e->iduser) { | ||
$event = Party::find($e->idevents); | ||
$user = User::find($e->iduser); | ||
|
||
// Might not exist - timing windows. | ||
if ($event && $user && $event->discourse_thread) { | ||
// We need a host of the event to add the user to the thread. | ||
$host = $this->getHost($event->idevents); | ||
|
||
if ($host) { | ||
$this->discourseService->removeUserFromPrivateMessage( | ||
$event->discourse_thread, | ||
$host->username, | ||
$user->username | ||
); | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should just be
$eventRole = $u && Fixometer::userIsHostOfGroup($party->group, $user) ? Role::HOST : Role::RESTARTER;
as there could be admins or network coordinators who are host of the group, and should get set with $eventRole = Role::HOST, even if their overall role ($u->role) might not be Role::HOST.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. I've made that change.