VRFS-1503 added protocol buffer, chat message model & controller, rest api
This commit is contained in:
parent
b95e1a7f1b
commit
07e141cc8f
|
|
@ -143,3 +143,4 @@ emails.sql
|
|||
email_batch.sql
|
||||
user_progress_tracking2.sql
|
||||
bands_did_session.sql
|
||||
chat_messages.sql
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
CREATE TABLE chat_messages
|
||||
(
|
||||
id character varying(64) NOT NULL DEFAULT uuid_generate_v4(),
|
||||
user_id character varying(64),
|
||||
music_session_id character varying(64),
|
||||
messsage TEXT NOT NULL,
|
||||
created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
|
@ -52,6 +52,7 @@ message ClientMessage {
|
|||
|
||||
// text message
|
||||
TEXT_MESSAGE = 236;
|
||||
CHAT_MESSAGE = 237;
|
||||
|
||||
MUSICIAN_SESSION_FRESH = 240;
|
||||
MUSICIAN_SESSION_STALE = 245;
|
||||
|
|
@ -130,6 +131,7 @@ message ClientMessage {
|
|||
|
||||
// text message
|
||||
optional TextMessage text_message = 236;
|
||||
optional ChatMessage chat_message = 237;
|
||||
|
||||
optional MusicianSessionFresh musician_session_fresh = 240;
|
||||
optional MusicianSessionStale musician_session_stale = 245;
|
||||
|
|
@ -397,6 +399,14 @@ message TextMessage {
|
|||
optional bool clipped_msg = 7;
|
||||
}
|
||||
|
||||
message ChatMessage {
|
||||
optional string sender_name = 1;
|
||||
optional string sender_id = 2;
|
||||
optional string msg = 3;
|
||||
optional string msg_id = 4;
|
||||
optional string created_at = 5;
|
||||
}
|
||||
|
||||
// route_to: client:
|
||||
// sent by server to let the rest of the participants know a client has become active again after going stale
|
||||
message MusicianSessionFresh {
|
||||
|
|
|
|||
|
|
@ -580,6 +580,23 @@ module JamRuby
|
|||
)
|
||||
end
|
||||
|
||||
# creates the session chat message
|
||||
def chat_message(session_id, sender_name, sender_id, msg, msg_id, created_at)
|
||||
chat_message = Jampb::ChatMessage.new(
|
||||
:sender_id => sender_id,
|
||||
:sender_name => sender_name,
|
||||
:msg => msg,
|
||||
:msg_id => msg_id,
|
||||
:created_at => created_at
|
||||
)
|
||||
|
||||
Jampb::ClientMessage.new(
|
||||
:type => ClientMessage::Type::CHAT_MESSAGE,
|
||||
:route_to => SESSION_TARGET_PREFIX + session_id,
|
||||
:chat_message => chat_message
|
||||
)
|
||||
end
|
||||
|
||||
# create a musician fresh session message
|
||||
def musician_session_fresh(session_id, user_id, username, photo_url)
|
||||
fresh = Jampb::MusicianSessionFresh.new(
|
||||
|
|
|
|||
|
|
@ -0,0 +1,27 @@
|
|||
module JamRuby
|
||||
class ChatMessage < ActiveRecord::Base
|
||||
|
||||
self.primary_key = 'id'
|
||||
|
||||
default_scope order('created_at DESC')
|
||||
|
||||
belongs_to :user, :class_name => "JamRuby::User", :foreign_key => "user_id"
|
||||
belongs_to :session, :class_name => "JamRuby::MusicSession", :foreign_key => "session_id"
|
||||
|
||||
validates :message, length: {minimum: 1, maximum: 255}, no_profanity: true
|
||||
|
||||
def self.send_chat_msg(music_session, chat_msg, user)
|
||||
msg = @@message_factory.chat_message(
|
||||
music_session.id,
|
||||
user.name,
|
||||
user.id,
|
||||
chat_msg.message,
|
||||
chat_msg.id,
|
||||
chat_msg.created_at
|
||||
)
|
||||
|
||||
@@mq_router.server_publish_to_session(music_session, msg, sender = {:client_id => chat_msg.user_id})
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
@ -51,6 +51,7 @@
|
|||
|
||||
// text message
|
||||
TEXT_MESSAGE : "TEXT_MESSAGE",
|
||||
CHAT_MESSAGE : "CHAT_MESSAGE",
|
||||
|
||||
// broadcast notifications
|
||||
SOURCE_UP_REQUESTED : "SOURCE_UP_REQUESTED",
|
||||
|
|
|
|||
|
|
@ -944,6 +944,24 @@
|
|||
});
|
||||
}
|
||||
|
||||
function createChatMessage(session_id, options) {
|
||||
return $.ajax({
|
||||
type: "POST",
|
||||
url: '/api/sessions/' + session_id + '/chat?' + $.param(options),
|
||||
dataType: "json",
|
||||
contentType: 'application/json'
|
||||
});
|
||||
}
|
||||
|
||||
function getChatMessages(session_id, options) {
|
||||
return $.ajax({
|
||||
type: "GET",
|
||||
url: '/api/sessions/' + session_id + '/chats' + $.param(options),
|
||||
dataType: "json",
|
||||
contentType: 'application/json'
|
||||
});
|
||||
}
|
||||
|
||||
function initialize() {
|
||||
return self;
|
||||
}
|
||||
|
|
@ -1026,6 +1044,8 @@
|
|||
this.createFbInviteUrl = createFbInviteUrl;
|
||||
this.createTextMessage = createTextMessage;
|
||||
this.getNotifications = getNotifications;
|
||||
this.createChatMessage = createChatMessage;
|
||||
this.getChatMessages = getChatMessages;
|
||||
|
||||
return this;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
var invitationDialog = null;
|
||||
var textMessageDialog = null;
|
||||
var notificationPanel = null;
|
||||
var chatPanel = null;
|
||||
var me = null;
|
||||
|
||||
function initializeSearchPanel() {
|
||||
|
|
@ -95,6 +96,8 @@
|
|||
}
|
||||
|
||||
function initializeChatPanel() {
|
||||
// chatPanel = new context.JK.ChatPanel(app);
|
||||
// chatPanel.initialize(me, textMessageDialog);
|
||||
}
|
||||
|
||||
function search(query) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,35 @@
|
|||
class ApiChatsController < ApiController
|
||||
|
||||
before_filter :api_signed_in_user, :check_session
|
||||
|
||||
respond_to :json
|
||||
|
||||
def create
|
||||
@chat_msg = ChatMessage.new
|
||||
@chat_msg.user_id = current_user.id
|
||||
@chat_msg.session_id = params[:music_session]
|
||||
@chat_msg.message = params[:msg]
|
||||
if @chat_msg.save
|
||||
ChatMessage.send_chat_msg @music_session, @chat_msg, current_user
|
||||
end
|
||||
|
||||
respond_with_model(@chat_msg)
|
||||
end
|
||||
|
||||
def index
|
||||
@chat_msgs = ChatMessage.find_by_session_id(params[:music_session])
|
||||
.paginate(page: params[:page], per_page: pararms[:per_page] || 20)
|
||||
end
|
||||
|
||||
def check_session
|
||||
@music_session = MusicSession.find(params[:music_session])
|
||||
if @music_session.nil?
|
||||
raise ArgumentError, 'specified session not found'
|
||||
end
|
||||
|
||||
unless @music_session.access? current_user
|
||||
raise PermissionError, 'not allowed to join the specified session'
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
@ -259,6 +259,10 @@ SampleApp::Application.routes.draw do
|
|||
match '/users/:id/share/session/:provider' => 'api_users#share_session', :via => :get
|
||||
match '/users/:id/share/recording/:provider' => 'api_users#share_recording', :via => :get
|
||||
|
||||
# session chat
|
||||
match '/sessions/:id/chat' => 'api_chats#create', :via => :post
|
||||
match '/sessions/:id/chats' => 'api_chats#index', :via => :get
|
||||
|
||||
# user recordings
|
||||
# match '/users/:id/recordings' => 'api_users#recording_index', :via => :get
|
||||
# match '/users/:id/recordings/:recording_id' => 'api_users#recording_show', :via => :get, :as => 'api_recording_detail'
|
||||
|
|
|
|||
Loading…
Reference in New Issue