Skip to content

Instantly share code, notes, and snippets.

Domantas G domagude

View GitHub Profile
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') {
subToGroupConversationChannel(data['conversation_id']);
$('#conversations-menu ul').prepend(data['link_to_conversation']);
calculateUnseenConversations();
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|
ActionCable.server.broadcast(
"notifications_#{user_id}",
notification: 'added-to-group-conversation',
conversation_id: conversation.id,
View options.js
// on the add-user-to-contacts link click
// remove the link and notify, that the request has been sent
$(document).on('click',
'.add-user-to-contacts, .add-user-to-contacts-notif',
function(e) {
var conversation_window = $(this).parents('.conversation-window,\
.conversation');
conversation_window
.find('.add-user-to-contacts')
.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)
.parents('[data-user-name]')
.attr('data-user-name');
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="<%= user.name %>">
<div class="sixty-percent">
<span class="contact-name"><%= user.name %></span>
</div>
<div class="forty-percent">
<span class="accept-request">
<%= link_to "Accept",
contact_path(id: user.id),
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' %>
</div>
You can’t perform that action at this time.