Skip to content

Commit

Permalink
#1206 group by message id
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Jan 31, 2024
1 parent 54a2850 commit f7fb816
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -301,4 +301,4 @@ DEPENDENCIES
xcop (= 0.7.1)

BUNDLED WITH
2.5.3
2.4.22
1 change: 1 addition & 0 deletions objects/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def each
'LEFT JOIN flag ON flag.message = message.id',
'WHERE (bout.owner = $1 OR guest.human = $1)',
pred,
'GROUP BY message.id',
'ORDER BY message.created DESC',
"OFFSET #{@offset}",
"LIMIT #{@limit}"
Expand Down
2 changes: 1 addition & 1 deletion test/test__helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def test_pgsql
end

def test_name
"jeff#{SecureRandom.hex(4)}"
"jeff#{SecureRandom.hex(8)}"
end
end
end
20 changes: 17 additions & 3 deletions test/test_search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def test_finds_messages
bout = bouts.start(test_name)
msg = bout.post('Hey, you!')
found = []
human.search(Nb::Query.new('(text=~you)'), 0, 1).each do |m|
human.search(Nb::Query.new('(text=~you)'), 0, 10).each do |m|
found << m
end
assert_equal(1, found.size)
Expand All @@ -54,7 +54,7 @@ def test_finds_only_my_messages
bout.post(test_name)
friend = Nb::Humans.new(test_pgsql).take(test_name).create
found = []
friend.search(Nb::Query.new(''), 0, 1).each do |m|
friend.search(Nb::Query.new(''), 0, 10).each do |m|
found << m
end
assert_equal(0, found.size)
Expand All @@ -71,7 +71,21 @@ def test_finds_by_tags_and_flags
bout.post(test_name).flags.attach('small')
bout.post(test_name).flags.attach('medium')
found = []
human.search(Nb::Query.new('(#color=blue and $small+)'), 0, 1).each do |m|
human.search(Nb::Query.new('(#color=blue and $small+)'), 0, 10).each do |m|
found << m
end
assert_equal(1, found.size)
end

def test_group_by_message
human = Nb::Humans.new(test_pgsql).take(test_name).create
bouts = human.bouts
bout = bouts.start(test_name)
msg = bout.post(test_name)
msg.flags.attach('one')
msg.flags.attach('two')
found = []
human.search(Nb::Query.new(''), 0, 10).each do |m|
found << m
end
assert_equal(1, found.size)
Expand Down
12 changes: 6 additions & 6 deletions views/inbox.haml
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@
- unless the_bout.nil?
%p
Tags:
%span.click{onclick: '$("#tags").toggle();'}
%span.click{onclick: '$("#tags").toggle(); $("#tags-name").focus();'}
= '+'
%br
- bout.tags.each do |tag|
%code= "#{tag.name}=#{tag.value}"
%form{action: iri.cut('/b').append(the_bout).append('/tag'), method: 'post', id: 'tags', style: 'display: none;'}
%fieldset
%input{name: 'name', type: 'text', required: true, size: 8, placeholder: 'Tag', tabindex: 3}
%input{name: 'name', type: 'text', required: true, size: 8, placeholder: 'Tag', tabindex: 3, id: 'tags-name'}
%input{name: 'value', type: 'text', size: 20, placeholder: 'Value', tabindex: 4}
%button{type: 'submit', tabindex: 5}
Put
Expand All @@ -43,11 +43,11 @@
Guests:
- bout.guests.each do |guest|
%code= "#{guest}"
%span.click{onclick: '$("#invite").toggle();'}
%span.click{onclick: '$("#invite").toggle(); $("#invite-human").focus();'}
= '+'
%form{action: iri.cut('/b').append(the_bout).append('/invite'), method: 'post', id: 'invite', style: 'display: none;'}
%fieldset
%input{name: 'human', type: 'text', required: true, size: 12, placeholder: 'Identity', tabindex: 6}
%input{name: 'human', type: 'text', required: true, size: 12, placeholder: 'Identity', tabindex: 6, id: 'invite-human'}
%button{type: 'submit', tabindex: 7}
Invite
Expand All @@ -62,7 +62,7 @@
%code= msg.author.identity
on
= msg.created
%span.click{onclick: "$('#flags-#{msg.id}').toggle();"}
%span.click{onclick: "$('#flags-#{msg.id}').toggle(); $('#flags-#{msg.id}-name').focus();"}
+
%br
= msg.text
Expand All @@ -74,7 +74,7 @@
%a.click{href: iri.cut('/m').append(msg.id).append('detach').add(name: flag.name)}= 'x'
%form{action: iri.cut('/m').append(msg.id).append('/attach'), method: 'post', id: "flags-#{msg.id}", style: 'display: none;'}
%fieldset
%input{name: 'name', type: 'text', required: true, size: 12, placeholder: 'Flag'}
%input{name: 'name', type: 'text', required: true, size: 12, placeholder: 'Flag', id: "flags-#{msg.id}-name"}
%button{type: 'submit'}
Flag
- total += 1
Expand Down

0 comments on commit f7fb816

Please sign in to comment.