18 Commits
badge ... pm

Author SHA1 Message Date
MrYummy
8bf5164301 just making this so I don't lose work when I switch branches 2017-06-17 17:22:58 +02:00
MrYummy
6a0eedc585 Fixed compatability issues in methods for thread-like messages 2017-06-16 22:27:03 +02:00
MrYummy
4e8d94a7b6 see previous commit 2017-06-16 21:19:13 +02:00
MrYummy
f60edea1be Fixed 'No private messages' bug 2017-06-16 21:16:35 +02:00
MrYummy
2bb75bb0b6 tweaked message 'read' system 2017-06-16 21:14:09 +02:00
MrYummy
dd193e740a Added 'read' check; message name is only bold if unread 2017-06-15 15:04:15 +02:00
MrYummy
9b50ec652c Made messages more thread-like (replies, editing, etc.) 2017-06-15 14:29:25 +02:00
MrYummy
80026caebc Added subject support to messages 2017-06-13 03:48:30 +02:00
MrYummy
f00677a68b Added subject column to messages 2017-06-13 02:35:22 +02:00
MrYummy
b075a5fd75 Apparently that 'unnecessary permission check' was necessary. ¯\_(ツ)_/¯ 2017-06-13 02:19:29 +02:00
MrYummy
4d42fdfeb4 Moved messages index link to users/show.html.erb, added 'message this user' button 2017-06-13 02:08:13 +02:00
MrYummy
dd63941657 Added message length validity (1..8000) and rewrote 'target' method 2017-06-12 21:59:39 +02:00
MrYummy
fbae985d86 Prettified link style in message mail 2017-06-12 21:47:21 +02:00
MrYummy
32231e4eea Updated user_target autocomplete regex, removed unnecessary permission check 2017-06-12 21:40:33 +02:00
MrYummy
895e56ff06 Link to 'all messages' in message email fixed, added "delete_all" action 2017-06-12 21:17:18 +02:00
MrYummy
68ee779c11 Now sends mail to user_target on message creation 2017-06-04 20:02:57 +02:00
MrYummy
7c233c8fef fixed routes and made 'Delete message' appear on cursor hover 2017-06-03 21:29:14 +02:00
MrYummy
e378dfab02 Added messaging feature 2017-05-27 00:34:47 +02:00
46 changed files with 760 additions and 57 deletions

View File

@@ -88,5 +88,45 @@ $(function() {
}], {
debounce: 300
});
$('.md_editor .field_container_user .editor_field').textcomplete([{
// match up to 2 words (everything except some special characters)
// each word can have up to 16 characters (up to 32 total)
// words must be separated by a single space
match: /(^|\s)([^!"§$%&\/()=?.,;+*@\s]{1,16})$/,
search: function (text, callback, match) {
console.log("Searching " + text);
text = text.toLowerCase();
$.ajax("/users/suggestions", {
type: "post",
data: {name: text},
dataType: "json",
headers: {
"X-CSRF-Token": $('meta[name="csrf-token"]').attr("content")
},
success: function(data) {
callback(data);
},
error: function(xhr, status, err) {
console.error(err);
callback([]);
}
});
},
template: function(user) {
var name = user[0];
var ign = user[1];
if (name != ign) {
return name + " <small>(" + ign + ")</small>";
} else {
return ign;
}
},
cache: true,
replace: function (word) {
return "$1" + word[1] + " ";
}
}], {
debounce: 300
});
});
});

View File

@@ -480,6 +480,10 @@ blockquote p {
padding: 4em 1em 1em;
}
}
.field_container_user {
.editor_field {
}
}
}
ul.dropdown-menu {
@@ -646,6 +650,7 @@ tr.spacer {
}
.profile-action {
font-size: 0;
float: right;
}
@@ -1026,4 +1031,4 @@ nav.pagination {
padding: 0.1em 0.2em;
border-radius: 0.2em;
text-shadow: none;
}
}

View File

@@ -75,4 +75,4 @@ class ApplicationController < ActionController::Base
!!(current_user && current_user.confirmed?)
end
end
end

View File

@@ -92,4 +92,4 @@ class ForumsController < ApplicationController
a = [:name, :position, :role_read_id, :role_write_id] + add
params.require(:forum).permit(a)
end
end
end

View File

@@ -92,4 +92,4 @@ class ForumthreadsController < ApplicationController
a += add
params.require(:forumthread).permit(a)
end
end
end

View File

@@ -0,0 +1,77 @@
class MessagerepliesController < ApplicationController
def edit
@reply = Messagereply.find(params[:id])
if mod? || @reply.author.is?(current_user)
else
flash[:alert] = "You are not allowed to edit this reply"
redirect_to @reply.message
end
end
def create
message = Message.find(params[:message_id])
if [message.user_sender, message.user_target].include? current_user
@reply = Messagereply.new(reply_params)
@reply.user_author = current_user
@reply.message = message
if @reply.save
if false
@reply.send_new_message_reply_mail
end
Message.find(params[:message_id]).update_attributes(user_hidden: nil, user_unread_id: current_user.id)
position = message.replies.count - 1
page = position / Kaminari.config.default_per_page + 1
redirect_to message_path(@reply.message, page: page) + "#reply-#{@reply.id}", notice: 'Reply created!'
else
flash[:alert] = "Could not create reply."
redirect_to Message.find(params[:message_id])
end
else
flash[:alert] = "You are not allowed to create replies."
redirect_to Message.find(params[:message_id])
end
end
def update
@reply = Messagereply.find(params[:id])
if mod? || @reply.author.is?(current_user)
old_content = @reply.text_was
if @reply.update_attributes(reply_params)
if false
@reply.send_new_reply_mail(old_content)
end
flash[:notice] = "Reply updated!"
position = @reply.message.replies.index(@reply)
page = position / Kaminari.config.default_per_page + 1
redirect_to message_path(@reply.message, page: page) + "#reply-#{@reply.id}"
else
flash[:alert] = "There was a problem while updating your reply"
render action: "edit"
end
else
flash[:alert] = "You are not allowed to edit this reply"
redirect_to @reply.message
end
end
def destroy
@reply = Messagereply.find(params[:id])
if mod? || @reply.author.is?(current_user)
if @reply.destroy
flash[:notice] = "Reply deleted!"
else
flash[:alert] = "There was a problem while deleting this reply"
end
else
flash[:alert] = "You are not allowed to delete this reply"
end
redirect_to @reply.message
end
private
def reply_params
params.require(:messagereply).permit(:text)
end
end

View File

@@ -0,0 +1,128 @@
class MessagesController < ApplicationController
before_filter :set_current
def set_current
User.current = current_user
end
before_filter :check_permission, only: [:show, :edit, :update, :destroy]
def index
if current_user
@messages = Message.where("(user_sender_id = ? OR user_target_id = ?) AND (user_hidden_id != ? OR user_hidden_id IS NULL)", current_user.id, current_user.id, current_user.id).page(params[:page])
else
flash[:alert] = "Please log in to see your private messages."
redirect_to blogposts_path
end
end
def show
Message.find(@message.id).update_attributes(user_unread: nil) unless @message.user_unread == current_user
@replies = @message.replies.page(params[:page])
end
def edit
unless mod? || @message.author.is?(current_user)
flash[:alert] = "You are not allowed to edit this message!"
redirect_to @message
end
end
def new
if current_user
@message = Message.new
else
flash[:alert] = "Please log in to send a private message."
redirect_to blogposts_path
end
end
def create
unless message_params[:user_target_id]
flash[:alert] = "Please enter a valid IGN before sending."
redirect_to new_message_path
return
end
if message_params[:subject].blank?
flash[:alert] = "Please write a subject before sending."
redirect_to new_message_path
return
elsif message_params[:text].blank?
flash[:alert] = "Please write a message before sending."
redirect_to new_message_path
return
end
@message = Message.new(message_params)
@message.user_target = User.find(@message.user_target_id)
@message.user_unread = User.find(@message.user_unread_id) if @message.user_unread_id
if @message.save
@message.send_new_message_mail
flash[:notice] = "Message sent!"
redirect_to messages_path
else
flash[:alert] = "Something went wrong while creating your message."
render action: "new"
end
end
def update
if mod? || @message.user_sender.is?(current_user)
@message.user_editor_id = current_user.id
@message.attributes = message_params
if @message.save
redirect_to @message, notice: 'Message has been updated.'
else
flash[:alert] = "There was a problem while updating the message."
render action: "edit"
end
else
flash[:alert] = "You are not allowed to edit this message!"
redirect_to @message
end
end
def destroy
if [@message.user_target, @message.user_sender].include?(current_user)
if @message.destroy
flash[:notice] = "Message deleted!"
else
unless @message.user_hidden
flash[:alert] = "There was a problem while deleting this message."
else
Message.find(@message.id).update_attributes(user_hidden: current_user)
end
end
else
flash[:alert] = "You are not allowed to delete this message."
end
redirect_to messages_path
end
def destroy_all
Message.destroy_all(user_target_id: current_user.id)
if Message.where(user_target_id: current_user.id).empty?
flash[:notice] = "Your messages have been deleted!"
else
flash[:alert] = "There was a problem while deleting your messages."
end
redirect_to messages_path
end
def message_params(add = [])
params[:message][:user_target_id] = User.find_by(ign: params[:message][:user_target].strip).try(:id)
params[:message][:user_sender_id] = User.find_by(ign: params[:message][:user_sender]).id
params[:message][:user_hidden_id] = User.find_by(ign: params[:message][:user_hidden]).try(:id)
params[:message][:user_unread_id] = User.find_by(ign: params[:message][:user_unread]).try(:id)
params.require(:message).permit([:subject, :text, :user_target_id, :user_sender_id, :user_hidden_id, :user_unread_id])
end
private
def check_permission
@message = Message.find(params[:id])
unless [@message.user_target, @message.user_sender].include? current_user
flash[:alert] = "You are not allowed to view this message"
redirect_to home_statics_path
end
end
end

View File

@@ -69,4 +69,4 @@ class ThreadrepliesController < ApplicationController
def reply_params
params.require(:threadreply).permit(:content)
end
end
end

View File

@@ -90,4 +90,4 @@ module ApplicationHelper
https://www.youtube-nocookie.com/embed/\\1?theme=light&vq=hd720&hd=1&iv_load_policy=3&showinfo=1&showsearch=0&rel=0&modestbranding&hd=1&autohide=1&html5=1&start=\\3'>
</iframe>")
end
end
end

View File

@@ -24,4 +24,4 @@ module MailerHelper
end
end
end
end
end

View File

@@ -52,4 +52,4 @@ module UsersHelper
end
end
end
end

View File

@@ -44,4 +44,10 @@ class RedstonerMailer < ActionMailer::Base
@user = user
mail(to: @user.email, subject: "Email change on Redstoner.com")
end
def new_message_mail(user, message)
@user = user
@message = message
mail(to: @user.email, subject: "#{message.user_sender.name} sent you a new message")
end
end

View File

@@ -61,4 +61,4 @@ class Comment < ActiveRecord::Base
background_mailer(mails)
end
end
end

75
app/models/message.rb Normal file
View File

@@ -0,0 +1,75 @@
class Message < ActiveRecord::Base
include MailerHelper
belongs_to :user_sender, class_name: "User", foreign_key: "user_sender_id"
belongs_to :user_target, class_name: "User", foreign_key: "user_target_id"
belongs_to :user_editor, class_name: "User", foreign_key: "user_editor_id"
belongs_to :user_hidden, class_name: "User", foreign_key: "user_hidden_id"
belongs_to :user_unread, class_name: "User", foreign_key: "user_unread_id"
validates_presence_of :user_sender, :user_target, :text, :subject
validates_length_of :text, in: 1..8000
validates_length_of :subject, in: 1..2000
has_many :messagereplies
accepts_nested_attributes_for :messagereplies
before_destroy :do_destroy?
def do_destroy?
if user_hidden || user_sender == user_target
return true
else
update_attributes(user_hidden: User.current)
return false
end
end
def to_s
subject
end
def sender
@sender ||= if self.user_sender.present?
user_sender
else
User.first
end
end
def target
@target ||= if self.user_target.present?
user_target
else
User.first
end
end
def editor
@editor ||= (self.user_editor || User.first)
end
def edited?
!!user_editor_id
end
def replies
messagereplies
end
def send_new_message_mail
begin
mail = RedstonerMailer.new_message_mail(user_target, self)
rescue => e
Rails.logger.error "---"
Rails.logger.error "WARNING: Failed to create new_message_mail (view) for message#: #{@message.id}, user: #{@user.name}, #{@user.email}"
Rails.logger.error e.message
Rails.logger.error "---"
end
background_mailer([mail])
end
end

View File

@@ -0,0 +1,67 @@
class Messagereply < ActiveRecord::Base
include MailerHelper
include UsersHelper
belongs_to :message
belongs_to :user_author, class_name: "User", foreign_key: "user_author_id"
belongs_to :user_editor, class_name: "User", foreign_key: "user_editor_id"
validates_presence_of :text
validates_length_of :text, in: 1..8000
def get_message
message
end
def author
@author ||= if self.user_author.present?
user_author
else
User.first
end
end
def editor
# can be nil
@editor ||= user_editor
end
def edited?
!!user_editor_id
end
def send_new_reply_mail(old_content = "")
users = mentions(content) - mentions(old_content)
# thread + replies
posts = message.replies.to_a
posts << message if message.author.mail_own_message_reply?
# only send "reply" mail when reply is new
unless old_content.present?
posts.each do |post|
# don't send mail to the author of this reply, don't send to banned/disabled users
if post.author != author && post.author.normal? && post.author.confirmed? # &&
users << post.author if post.author.mail_other_thread_reply?
end
end
end
# making sure we don't send multiple mails to the same user
users.uniq!
mails = []
users.each do |usr|
begin
mails << RedstonerMailer.new_thread_reply_mail(usr, self)
rescue => e
Rails.logger.error "---"
Rails.logger.error "WARNING: Failed to create new_thread_reply_mail (view) for reply#: #{@self.id}, user: #{@user.name}, #{@user.email}"
Rails.logger.error e.message
Rails.logger.error "---"
end
end
background_mailer(mails)
end
end

View File

@@ -64,4 +64,4 @@ class Threadreply < ActiveRecord::Base
end
background_mailer(mails)
end
end
end

View File

@@ -24,6 +24,8 @@ class User < ActiveRecord::Base
has_many :blogposts
has_many :comments
cattr_accessor :current
# foo.bar.is?(current_user)
def is? (user)
self == user
@@ -173,4 +175,4 @@ class User < ActiveRecord::Base
def set_email_token
self.email_token ||= SecureRandom.hex(16)
end
end
end

View File

@@ -8,4 +8,4 @@
<%= text_area_tag name, content, options %>
<div class="preview"><i>(Loading...)</i></div>
</div>
</div>
</div>

View File

@@ -0,0 +1,8 @@
<div class="md_editor">
<div class="field_container_user">
<% options = (defined?(options) && options || {}) %>
<% options[:class] = "#{options[:class]} editor_field" %>
<% options[:placeholder] ||= "Enter user's name." %>
<%= text_field_tag name, content, options %>
</div>
</div>

View File

@@ -1,5 +1,4 @@
<% title "News" %>
<h1>News</h1>
<%= link_to 'Make new Post', new_blogpost_path, class: "btn blue" if mod? %>
<div id="posts">

View File

@@ -51,4 +51,4 @@
</div>
<% end %>
<%= paginate @threads %>
</div>
</div>

View File

@@ -38,4 +38,4 @@
<p><%= f.submit "Update thread", class: "btn blue left" %></p>
<% end %>
<%= button_to "Delete thread", @thread, :method => "delete", data: {confirm: "Delete thread & comments forever?"}, class: "btn red right" %>
<div class="clear"></div>
<div class="clear"></div>

View File

@@ -32,4 +32,4 @@
<%= f.hidden_field :forum_id %>
<p><%= f.submit "Create thread", class: "btn blue left" %></p>
<div class="clear"></div>
<% end %>
<% end %>

View File

@@ -44,4 +44,4 @@
<% else %>
<p>Please <%= link_to "Log in", login_path(return_path: request.env['PATH_INFO']), action: "new" %> to post a reply.</p>
<% end %>
</div>
</div>

View File

@@ -0,0 +1,5 @@
<%= form_for [reply.get_message, reply] do |f| %>
<%= render partial: "md_editor", locals: {name: "messagereply[text]", content: reply.text} %>
<p><%= f.submit "Reply", class: "btn blue" %></p>
<% end %>

View File

@@ -0,0 +1,17 @@
<div class="item-group thread-reply with-avatar" id="reply-<%= reply.id %>">
<div class="header">
<%= link_to(reply.author.avatar(64), reply.author, title: reply.author.ign) %>
<%= render partial: "users/username", locals: { user: reply.author } %>
<%= link_to "#reply-#{reply.id}" do %>
<%= ago reply.created_at %>
<% end %>
<%= link_to "edit", edit_message_messagereply_path(reply.message, reply), class: "editlink" if mod? || reply.author.is?(current_user) %>
<div class="clear-right"></div>
</div>
<div class="items">
<div class="item content">
<%= render_md(reply.text).html_safe %>
</div>
</div>
</div>

View File

@@ -0,0 +1,15 @@
<% title "Edit Message Reply: #{@reply.message.subject}" %>
<%
position = @reply.message.replies.index(@reply)
page = position / Kaminari.config.default_per_page + 1
%>
<%= link_to "Messages", messages_path %> → <%= link_to @reply.message, message_path(@reply.message, page: page) + "#reply-#{@reply.id}" %> → Edit reply
<h1>Edit reply</h1>
<%= form_for [@reply.message, @reply] do |f| %>
<%= render partial: "md_editor", locals: {name: "messagereply[text]", content: @reply.text} %>
<p><%= f.submit "Reply", class: "btn blue left" %></p>
<% end %>
<p><%= button_to "Delete reply", [@reply.message, @reply], method: "delete", data: {confirm: "Delete reply forever?"}, class: "btn red right" %></p>
<div class="clear"></div>

View File

@@ -0,0 +1,17 @@
<% title "Edit Thread: #{@message}" %>
<h1>Edit thread</h1>
<%= link_to "Messages", messages_path %> → <%= link_to @message, @message %> → Edit Message
<%= form_for @message do |f|%>
<div class="table-cell full-width">
<%= f.text_field :subject, placeholder: "Subject" %>
</div>
<br>
<%= render partial: "md_editor", locals: {name: "message[text]", content: @message.text} %>
<p><%= f.submit "Update message", class: "btn blue left" %></p>
<%= f.hidden_field :user_sender, value: @message.user_sender %>
<%= f.hidden_field :user_target, value: @message.user_target %>
<% end %>
<%= button_to "Delete ", @message, :method => "delete", data: {confirm: "Delete message & comments forever?"}, class: "btn red right" %>
<div class="clear"></div>

View File

@@ -0,0 +1,60 @@
<% if @messages.any? %>
<%= link_to "delete all messages", destroy_all_messages_path, method: "post", class: "btn blue right", data: {confirm: "Delete all of your messages forever?"} %>
<% end %>
<%= link_to "create new message", new_message_path, class: "btn blue right" %>
<br>
<h2>
<% if Message.where("(user_target_id = ? OR user_sender_id = ?) AND user_hidden_id != ?", current_user.id, current_user.id, current_user.id).any? %>
Your private messages:
<% else %>
You have no private messages.
<% end %>
</h2>
<div id="forum_groups">
<% @messages.each do |message| %>
<div class="item-group with-avatar">
<div class="header">
<%
if current_user == message.user_sender
user = message.user_target
else
user = message.user_sender
end
%>
<%= link_to(user.avatar(64), user, title: user.ign) %>
<%= render partial: "users/username", locals: { user: user } %>
<span style="font-size:16px">
&nbsp;
<span class="<%= "bold" if message.user_unread_id && message.user_unread != current_user %>"><%= link_to message.subject, message %></span>
&nbsp; | &nbsp;
</span>
<%= ago message.created_at %>
<div class="right">
<%= link_to "Delete message", message, :method => "delete", class: "editlink", data: {confirm: "Delete this message forever?"} %>
</div>
<div class="clear-right"></div>
</div>
<div class="items">
<div class="item">
<%= truncate message.text, length: 20, omission: "..." %>
<div class="item-info items bold">
<% if rpl = message.replies.last %>
<%= rpl.author.name %>
<%
position = message.replies.count - 1
page = position / Kaminari.config.default_per_page + 1
%>
<%= link_to "replied", message_path(message, page: page) + "#reply-#{rpl.id}" %>
<%= ago rpl.created_at %>.
<% else %>
No replies yet.
<% end %>
</div>
<div class="clear"></div>
</div>
</div>
</div>
<% end %>
<%= paginate @messages %>
</div>

View File

@@ -0,0 +1,26 @@
<h1>New Message</h1>
<%= form_for @message do |f| %>
</table>
<tr>
<td>
<%= render partial: "md_editor_user", locals: {name: "message[user_target]", content: params[:user_target]} %>
</td>
</tr>
<br>
<tr>
<td>
<%= f.text_field :subject, placeholder: "Subject" %>
</td>
</tr>
<br><br>
<tr>
<td>
<%= render partial: "md_editor", locals: {name: "message[text]", content: params[:text]} %>
</td>
</tr>
</table>
<%= f.hidden_field :user_sender, value: current_user %>
<%= f.hidden_field :user_unread, value: current_user %>
<br>
<p><%= f.submit "Send Message", class: "btn blue left" %></p>
<% end %>

View File

@@ -0,0 +1,33 @@
<%= link_to "Messages", messages_path %>
<h1><%= title @message.subject %></h1>
<div class="item-group thread with-avatar" id="message-<%= @message.id %>">
<div class="header">
<%= link_to(@message.sender.avatar(64), @message.sender, title: @message.sender.ign) %>
<%= render partial: "users/username", locals: { user: @message.sender } %>
<%= link_to p do %>
<%= ago @message.created_at %>
<% end %>
<%= link_to "edit", edit_message_path(@message), class: "editlink" if mod? || @message.sender.is?(current_user) %>
<div class="clear-right"></div>
</div>
<div class="items">
<% if @message.edited? %>
<div class="item edited">
Last edited <%= ago @message.updated_at %> by <%= link_to @message.editor.name, @message.editor %>.
</div>
<% end %>
<div class="item content">
<%= render_md(@message.text).html_safe %>
</div>
</div>
</div>
<div id="replies">
<h3><%= "#{pluralize(@message.replies.size, 'reply')}." %></h3>
<% @replies.each do |reply| %>
<%= render partial: "messagereplies/reply", locals: {reply: reply} %>
<% end %>
<%= paginate @replies %>
<%= render partial: "messagereplies/new", locals: {reply: Messagereply.new(message: @message)} %>
</div>

View File

@@ -0,0 +1,28 @@
<div style="font-family: 'Oswald','Calibri','Arial','DejaVu Sans','Open Sans','Lucida Sans','Lucida Grande','Lucida Sans Unicode',sans-serif; background: #F2F2F2">
<div style="color: #3f3f3f; width: 600px; max-width: 100%; padding: 2em 0; margin: auto;">
Hi <%= @user.name %>!
<p><%= link_to @message.user_sender.name, user_url(@message.user_sender), style: "text-decoration: none; color: #4096EE;" %> has sent you a new message!</p>
<blockquote>
<%= render_md(@message.text).html_safe %>
</blockquote>
<p><%= link_to "Click here", messages_url, style: "text-decoration: none; color: #4096EE;" %> to view your current messages.</p>
<p>If you have any questions or problems, just ask one of our <%= link_to "Staff", users_url(role: "staff"), style: "text-decoration: none; color: #4096EE;" %> in-game or on the forums!</p>
<p>Your Redstoner team</p>
</div>
<div style="background: #444; width: 100%; color: #fff; margin: auto; text-align: center; display: inline-block;">
<div style="margin: 2em;">
<p><i>Too much spam? Change <%= link_to "your notification settings", edit_notifications_user_url(@user), style: "text-decoration: none; color: #4096EE;" %>!</i></p>
<p>You can contact us via:
<%= link_to "Website", root_url, style: "text-decoration: none; color: #4096EE;" %> |
<%= link_to "Twitter", "https://twitter.com/RedstonerServer", style: "text-decoration: none; color: #4096EE;" %> |
<%= link_to "Google+", "https://google.com/+Redstoner", style: "text-decoration: none; color: #4096EE;" %> |
<%= link_to "Email", "mailto:redstonerserver+website@gmail.com", style: "text-decoration: none; color: #4096EE;" %>
</p>
</div>
</div>
</div>

View File

@@ -29,4 +29,4 @@
</p>
</div>
</div>
</div>
</div>

View File

@@ -30,4 +30,4 @@
<%= link_to "Email", "mailto:redstonerserver+website@gmail.com", style: "text-decoration: none; color: #4096EE;" %>
</p>
</div>
</div>
</div>

View File

@@ -30,4 +30,4 @@
<span>for those who just want to mine some ore</span>
<span>and we have a freebuild world for large projects.</span>
</p>
<p>Join us now!</p>
<p>Join us now!</p>

View File

@@ -1,4 +1,4 @@
<%= form_for [reply.thread, reply] do |f| %>
<%= render partial: "md_editor", locals: {name: "threadreply[content]", content: reply.content} %>
<p><%= f.submit "Reply#{ ' (Locked)' if reply.thread.locked? }", class: "btn blue" %></p>
<% end %>
<% end %>

View File

@@ -12,4 +12,4 @@
<p><%= f.submit "Reply", class: "btn blue left" %></p>
<% end %>
<p><%= button_to "Delete reply", [@reply.thread, @reply], method: "delete", data: {confirm: "Delete reply forever?"}, class: "btn red right" %></p>
<div class="clear"></div>
<div class="clear"></div>

View File

@@ -87,4 +87,4 @@
<span class='red-alert'>This user has not confirmed his email!</span>
<% end %>
<% end %>
<% end %>
<% end %>

View File

@@ -1,14 +1,19 @@
<% title @user.name %>
<div id="user-info">
<% if @user.is?(current_user) || (mod? && current_user.role >= @user.role) %>
<div class="profile-action" ><%= link_to "edit profile", edit_user_path(@user), :class => "btn blue" %></div>
<% end %>
<div class="profile-action" >
<% if !session[:original_user_id] && admin? %>
<%= link_to "become this user", become_path(user: @user), :class => "btn blue" %>
<% elsif session[:original_user_id] %>
<div class="profile-action">
<% if session[:original_user_id] %>
<%= link_to "revert", revert_path, :class => "btn blue" %>
<% elsif admin? %>
<%= link_to "become this user", become_path(user: @user), :class => "btn blue" %>
<% end %>
<% if @user.is?(current_user) || (mod? && current_user.role >= @user.role) %>
<%= link_to "edit profile", edit_user_path(@user), :class => "btn blue" %>
<% end %>
<% if @user.is?(current_user) %>
<%= link_to "private messages (#{Message.where.not(user_unread: current_user).count})", messages_path, :class => "btn blue" %>
<% elsif current_user %>
<%= link_to "Send this user a message", new_message_path(user_target: @user.ign), :class => "btn blue" %>
<% end %>
</div>

View File

@@ -41,6 +41,13 @@ Redstoner::Application.routes.draw do
end
end
resources :messages do
resources :messagereplies, path: 'replies'
collection do
post 'destroy_all'
end
end
# get '/status' => 'status#show'
get 'login' => 'sessions#new'

View File

@@ -0,0 +1,14 @@
class CreateMessages < ActiveRecord::Migration
def change
create_table :messages do |t|
t.text :message
t.references :user_sender
t.references :user_target
t.references :user_editor
t.references :user_hidden
t.references :user_unread
t.timestamps null: true
end
end
end

View File

@@ -0,0 +1,5 @@
class ChangeMessageToText < ActiveRecord::Migration
def change
rename_column :messages, :message, :text
end
end

View File

@@ -0,0 +1,5 @@
class AddSubjectToMessages < ActiveRecord::Migration
def change
add_column :messages, :subject, :string
end
end

View File

@@ -0,0 +1,13 @@
class CreateMessagereplies < ActiveRecord::Migration
def change
create_table :messagereplies do |t|
t.text :text
t.references :user_author
t.references :user_editor
t.references :message
t.timestamps null: true
end
end
end

View File

@@ -11,10 +11,10 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20160926220738) do
ActiveRecord::Schema.define(version: 20170613021450) do
create_table "blogposts", force: :cascade do |t|
t.string "title"
t.string "title", limit: 191
t.text "content", limit: 65535
t.integer "user_author_id", limit: 4
t.integer "user_editor_id", limit: 4
@@ -32,14 +32,14 @@ ActiveRecord::Schema.define(version: 20160926220738) do
end
create_table "forumgroups", force: :cascade do |t|
t.string "name"
t.string "name", limit: 191
t.integer "position", limit: 4
t.integer "role_read_id", limit: 4
t.integer "role_write_id", limit: 4
end
create_table "forums", force: :cascade do |t|
t.string "name"
t.string "name", limit: 191
t.integer "position", limit: 4
t.integer "role_read_id", limit: 4
t.integer "role_write_id", limit: 4
@@ -52,7 +52,7 @@ ActiveRecord::Schema.define(version: 20160926220738) do
end
create_table "forumthreads", force: :cascade do |t|
t.string "title"
t.string "title", limit: 191
t.text "content", limit: 65535
t.boolean "sticky", default: false
t.boolean "locked", default: false
@@ -65,33 +65,54 @@ ActiveRecord::Schema.define(version: 20160926220738) do
end
create_table "info", force: :cascade do |t|
t.string "title"
t.string "title", limit: 191
t.text "content", limit: 65535
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "labels", force: :cascade do |t|
t.string "name"
t.string "color"
t.string "name", limit: 191
t.string "color", limit: 191
end
create_table "messagereplies", force: :cascade do |t|
t.text "text", limit: 65535
t.integer "user_author_id", limit: 4
t.integer "user_editor_id", limit: 4
t.integer "message_id", limit: 4
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "messages", force: :cascade do |t|
t.text "text", limit: 65535
t.integer "user_sender_id", limit: 4
t.integer "user_target_id", limit: 4
t.integer "user_editor_id", limit: 4
t.integer "user_hidden_id", limit: 4
t.integer "user_unread_id", limit: 4
t.datetime "created_at"
t.datetime "updated_at"
t.string "subject", limit: 191
end
create_table "register_tokens", force: :cascade do |t|
t.string "uuid", null: false
t.string "token", null: false
t.string "email", null: false
t.string "uuid", limit: 32, null: false
t.string "token", limit: 6, null: false
t.string "email", limit: 191, null: false
end
add_index "register_tokens", ["uuid"], name: "index_register_tokens_on_uuid", unique: true, using: :btree
create_table "roles", force: :cascade do |t|
t.string "name"
t.string "name", limit: 191
t.integer "value", limit: 4
t.string "color"
t.string "color", limit: 191
end
create_table "sessions", force: :cascade do |t|
t.string "session_id", null: false
t.string "session_id", limit: 191, null: false
t.text "data", limit: 65535
t.datetime "created_at"
t.datetime "updated_at"
@@ -110,20 +131,20 @@ ActiveRecord::Schema.define(version: 20160926220738) do
end
create_table "users", force: :cascade do |t|
t.string "uuid", null: false
t.string "name", null: false
t.string "password_digest", null: false
t.string "ign", null: false
t.string "email", null: false
t.string "uuid", limit: 191, null: false
t.string "name", limit: 191, null: false
t.string "password_digest", limit: 191, null: false
t.string "ign", limit: 191, null: false
t.string "email", limit: 191, null: false
t.text "about", limit: 65535
t.string "last_ip"
t.string "skype"
t.string "last_ip", limit: 191
t.string "skype", limit: 191
t.boolean "skype_public", default: false
t.string "youtube"
t.string "youtube_channelname"
t.string "twitter"
t.string "youtube", limit: 191
t.string "youtube_channelname", limit: 191
t.string "twitter", limit: 191
t.boolean "donor", default: false
t.string "email_token"
t.string "email_token", limit: 191
t.boolean "confirmed", default: false
t.datetime "last_seen"
t.integer "role_id", limit: 4, null: false

View File

@@ -38,4 +38,29 @@ User.create!(
password: "123456789", # high seructity!
password_confirmation: "123456789",
role: Role.get(:superadmin)
)
)
User.create!(
uuid: "7f52491ab5d64c11b4a43806db47a101",
ign: "Yummy_",
name: "Yummy",
email: "yummy@example.com",
password: "123456789", # high seructity!
password_confirmation: "123456789",
role: Role.get(:superadmin)
)
User.create!(
uuid: "62fe35da05ae437ea44b4deae1be1dc4",
ign: "Logal",
email: "logal@example.com",
password: "123456789", # high seructity!
password_confirmation: "123456789",
role: Role.get(:superadmin)
)
Message.create!(
user_sender_id: 2,
user_target_id: 2,
text: "This is a very long message that I will be using to test a plentitude of things. :)",
created_at: Time.utc(0).to_datetime,
subject: "Hello there!"
)