Skip to content

Commit cca9d30

Browse files
authored
Wip/encrypted rich text messages (#735)
Configure encrypted secrets and attributes. Improves interface and performance of messaging/conversations. Allows for rich text messages that are encrypted-at-rest in the db. Moves notifications list to dropdown menu.
2 parents 89077f4 + 9be40ea commit cca9d30

32 files changed

+248
-101
lines changed

.github/workflows/rubyonrails.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99
push:
1010
branches: [ "main" ]
1111
pull_request:
12-
branches: [ "main" ]
12+
branches: [ "main", "wip/new-to-nl-2" ]
1313
jobs:
1414
rspec:
1515
runs-on: ubuntu-latest

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ GEM
471471
pundit (2.4.0)
472472
activesupport (>= 3.0.0)
473473
racc (1.8.1)
474-
rack (3.1.9)
474+
rack (3.1.10)
475475
rack-cors (2.0.2)
476476
rack (>= 2.0.0)
477477
rack-mini-profiler (3.3.1)

app/assets/stylesheets/better_together/conversations.scss

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,34 +43,35 @@
4343
display: flex;
4444
align-items: center;
4545
}
46-
46+
4747
.message-container {
4848
max-width: 75%;
4949
}
50-
50+
5151
.message-header {
5252
margin-bottom: 0.25rem;
5353
}
54-
54+
5555
.message-bubble {
5656
background-color: #f1f1f1;
5757
border-radius: 15px;
5858
}
59-
60-
.justify-content-end .message-bubble {
59+
60+
.me .message-bubble {
6161
background-color: #007bff;
6262
color: white;
63+
min-width: 40vw;
6364
}
64-
65+
6566
.card-body {
6667
background-color: #e9ecef;
6768
}
68-
69+
6970
.input-group textarea.form-control {
7071
resize: none;
7172
border-radius: 15px 0 0 15px;
7273
}
73-
74+
7475
.input-group button {
7576
border-radius: 0 15px 15px 0;
7677
}

app/assets/stylesheets/better_together/profiles.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@
3939
margin-right: 1%;
4040
box-shadow: 0px 1px 1px rgba(0, 0, 0, 0.15);
4141
}
42+
43+
&.mention {
44+
width: 2rem;
45+
height: 2rem;
46+
}
4247
}
4348

4449
.profile-header img.cover-image {

app/controllers/better_together/conversations_controller.rb

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module BetterTogether
44
# Handles managing conversations
55
class ConversationsController < ApplicationController
66
before_action :authenticate_user!
7-
before_action :set_conversations
7+
before_action :set_conversations, only: %i[index new]
88
before_action :set_conversation, only: %i[show]
99

1010
helper_method :available_participants
@@ -30,7 +30,7 @@ def create
3030
end
3131

3232
def show # rubocop:todo Metrics/MethodLength
33-
@messages = @conversation.messages.order(:created_at)
33+
@messages = @conversation.messages.with_all_rich_text.includes(sender: [:string_translations]).order(:created_at)
3434
@message = @conversation.messages.build
3535

3636
respond_to do |format|
@@ -48,8 +48,7 @@ def show # rubocop:todo Metrics/MethodLength
4848
private
4949

5050
def available_participants
51-
participants = Person
52-
.where.not(id: helpers.current_person.id)
51+
participants = Person.all
5352

5453
unless helpers.current_person.permitted_to?('manage_platform')
5554
# only allow messaging platform mangers unless you are a platform_manager
@@ -64,11 +63,16 @@ def conversation_params
6463
end
6564

6665
def set_conversation
67-
@conversation = Conversation.find(params[:id])
66+
@conversation = helpers.current_person.conversations.includes(:participants).find(params[:id])
6867
end
6968

7069
def set_conversations
71-
@conversations = helpers.current_person.conversations.order(updated_at: :desc)
70+
@conversations = helpers.current_person.conversations.includes(messages: [:sender],
71+
participants: [
72+
:string_translations,
73+
:contact_detail,
74+
{ profile_image_attachment: :blob }
75+
]).order(updated_at: :desc).distinct(:id)
7276
end
7377

7478
def platform_manager_ids

app/controllers/better_together/navigation_items_controller.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
module BetterTogether
66
# Responds to requests for navigation items
77
class NavigationItemsController < FriendlyResourceController # rubocop:todo Metrics/ClassLength
8-
before_action :set_navigation_area
8+
before_action :navigation_area
99
before_action :set_pages, only: %i[new edit create update]
10-
before_action :set_navigation_item, only: %i[show edit update destroy]
10+
before_action :navigation_item, only: %i[show edit update destroy]
1111

1212
helper_method :available_parent_items
1313

@@ -103,14 +103,14 @@ def set_pages
103103
)
104104
end
105105

106-
def set_navigation_area
106+
def navigation_area
107107
@navigation_area ||= find_by_translatable(
108108
translatable_type: ::BetterTogether::NavigationArea.name,
109109
friendly_id: params[:navigation_area_id]
110110
)
111111
end
112112

113-
def set_navigation_item
113+
def navigation_item
114114
@navigation_item = set_resource_instance
115115
end
116116

app/helpers/better_together/notifications_helper.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,9 @@ def unread_notification_count
99

1010
content_tag(:span, count, class: 'badge bg-primary rounded-pill position-absolute notification-badge')
1111
end
12+
13+
def recent_notifications
14+
current_person.notifications.joins(:event).order(created_at: :desc).limit(5)
15+
end
1216
end
1317
end

app/models/better_together/community.rb

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,14 @@ def optimized_profile_image
7171
if profile_image.content_type == 'image/svg+xml'
7272
# If SVG, return the original without transformation
7373
profile_image
74+
75+
# For other formats, analyze to determine transparency
76+
elsif profile_image.content_type == 'image/png'
77+
# If PNG with transparency, return the optimized PNG variant
78+
profile_image.variant(:optimized_png).processed
7479
else
75-
# For other formats, analyze to determine transparency
76-
metadata = profile_image.metadata
77-
if profile_image.content_type == 'image/png'
78-
# If PNG with transparency, return the optimized PNG variant
79-
profile_image.variant(:optimized_png).processed
80-
else
81-
# Otherwise, use the optimized JPG variant
82-
profile_image.variant(:optimized_jpeg).processed
83-
end
80+
# Otherwise, use the optimized JPG variant
81+
profile_image.variant(:optimized_jpeg).processed
8482
end
8583
end
8684

app/models/better_together/message.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ class Message < ApplicationRecord
66
belongs_to :conversation, touch: true
77
belongs_to :sender, class_name: 'BetterTogether::Person'
88

9+
has_rich_text :content, encrypted: true
10+
911
validates :content, presence: true
1012

1113
after_create_commit do
@@ -16,5 +18,9 @@ class Message < ApplicationRecord
1618
created_at: created_at.strftime('%H:%M %d-%m-%Y')
1719
})
1820
end
21+
22+
# def content
23+
# super || self[:content]
24+
# end
1925
end
2026
end

app/models/better_together/person.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@ def cover_image_variant(width, height)
7272
cover_image.variant(resize_to_fill: [width, height]).processed
7373
end
7474

75+
def handle
76+
slug
77+
end
78+
79+
def select_option_title
80+
"#{name} - @#{handle}"
81+
end
82+
7583
def to_s
7684
name
7785
end

0 commit comments

Comments
 (0)