Skip to content

Instantly share code, notes, and snippets.

View new_conversation_service.rb
Group::MessageBroadcastJob.perform_later(message, nil, nil)
View notification.js
// if a user was added to a new group conversation
if (data['notification'] == 'added-to-group-conversation') {
$('#conversations-menu ul').prepend(data['link_to_conversation']);
if (gon.user_id == data['message_author']) {
$('#conversations-menu ul li a')[0].click();
View message_broadcast_job.rb
def perform(message, previous_message, current_user)
# if the message's attribute added_new_users has present values
# broadcast a notification to those users that they were added to a group conv
if message.added_new_users.present?
conversation = message.conversation
message.added_new_users.each do |user_id|
notification: 'added-to-group-conversation',
View options.js
// on the add-user-to-contacts link click
// remove the link and notify, that the request has been sent
'.add-user-to-contacts, .add-user-to-contacts-notif',
function(e) {
var conversation_window = $(this).parents('.conversation-window,\
.replaceWith('<div class="contact-request-sent"\
View contact.rb
after_create_commit { ContactRequestBroadcastJob.perform_later(self) }
View contact_requests.js
$(document).on('turbolinks:load', function() {
// when a contact request is accepted, mark it as accepted
$('body').on('click', '.accept-request a', function() {
var sender_user_name = $('nav #user-name').html();
var receiver_user_name = $(this)
var requests_menu_item = $('#contacts-requests ul');
requests_menu_item = requests_menu_item
View notification.js
App.notification = App.cable.subscriptions.create("NotificationChannel", {
connected: function() {},
disconnected: function() {},
received: function(data) {
// if a contact request was accepted
if (data['notification'] == 'accepted-contact-request') {
// if a contact request was declined
if (data['notification'] == 'declined-contact-request') {
View _request.html.erb
<li class="contact-request" data-user-name="<%= %>">
<div class="sixty-percent">
<span class="contact-name"><%= %></span>
<div class="forty-percent">
<span class="accept-request">
<%= link_to "Accept",
remote: true,
method: "put" %>
View navigation.scss
#contacts-requests {
li {
color: black;
background-color: $backgroundColor;
border-bottom: 1px solid $navbarColor;
i {
position: relative;
.sixty-percent {
View _dropdowns.html.erb
<div class='pull-right' id='contacts-requests'>
<%= render 'layouts/navigation/header/dropdowns/contact_requests' %>