diff --git a/app/assets/javascripts/discourse/app/components/scrolling-post-stream.js b/app/assets/javascripts/discourse/app/components/scrolling-post-stream.js index 612766c807..da490bb0b3 100644 --- a/app/assets/javascripts/discourse/app/components/scrolling-post-stream.js +++ b/app/assets/javascripts/discourse/app/components/scrolling-post-stream.js @@ -49,7 +49,9 @@ export default MountWidget.extend({ "selectedPostsCount", "searchService", "showReadIndicator", - "streamFilters" + "streamFilters", + "lastReadPostNumber", + "highestPostNumber" ); }, diff --git a/app/assets/javascripts/discourse/app/components/topic-list-item.js b/app/assets/javascripts/discourse/app/components/topic-list-item.js index b02993354e..9933e98880 100644 --- a/app/assets/javascripts/discourse/app/components/topic-list-item.js +++ b/app/assets/javascripts/discourse/app/components/topic-list-item.js @@ -142,8 +142,8 @@ export default Component.extend({ classes.push("unseen-topic"); } - if (topic.get("displayNewPosts")) { - classes.push("new-posts"); + if (topic.unread_posts) { + classes.push("unread-posts"); } ["liked", "archived", "bookmarked", "pinned", "closed"].forEach((name) => { diff --git a/app/assets/javascripts/discourse/app/components/topic-post-badges.js b/app/assets/javascripts/discourse/app/components/topic-post-badges.js index 78600182a1..aced410bbd 100644 --- a/app/assets/javascripts/discourse/app/components/topic-post-badges.js +++ b/app/assets/javascripts/discourse/app/components/topic-post-badges.js @@ -1,13 +1,16 @@ import Component from "@ember/component"; import I18n from "I18n"; +import { or } from "@ember/object/computed"; export default Component.extend({ tagName: "span", classNameBindings: [":topic-post-badges"], - rerenderTriggers: ["url", "unread", "newPosts", "unseen"], + rerenderTriggers: ["url", "unread", "newPosts", "unreadPosts", "unseen"], newDotText: null, + init() { this._super(...arguments); + this.set( "newDotText", this.currentUser && this.currentUser.trust_level > 0 @@ -15,4 +18,6 @@ export default Component.extend({ : I18n.t("filters.new.lower_title") ); }, + + displayUnreadPosts: or("newPosts", "unreadPosts"), }); diff --git a/app/assets/javascripts/discourse/app/controllers/topic.js b/app/assets/javascripts/discourse/app/controllers/topic.js index b86f9e5570..ae881ebfaf 100644 --- a/app/assets/javascripts/discourse/app/controllers/topic.js +++ b/app/assets/javascripts/discourse/app/controllers/topic.js @@ -68,6 +68,8 @@ export default Controller.extend(bufferedProperty("model"), { filter: null, quoteState: null, currentPostId: null, + userLastReadPostNumber: null, + highestPostNumber: null, init() { this._super(...arguments); diff --git a/app/assets/javascripts/discourse/app/models/topic-tracking-state.js b/app/assets/javascripts/discourse/app/models/topic-tracking-state.js index a36bc2d878..3fcbe2d9e1 100644 --- a/app/assets/javascripts/discourse/app/models/topic-tracking-state.js +++ b/app/assets/javascripts/discourse/app/models/topic-tracking-state.js @@ -352,15 +352,14 @@ const TopicTrackingState = EmberObject.extend({ isSeen !== state.is_seen ) { const postsCount = topic.get("posts_count"); - let newPosts = postsCount - state.highest_post_number, - unread = postsCount - state.last_read_post_number; + let unread; - if (newPosts < 0) { - newPosts = 0; - } - if (!state.last_read_post_number) { + if (state.last_read_post_number) { + unread = postsCount - state.last_read_post_number; + } else { unread = 0; } + if (unread < 0) { unread = 0; } @@ -368,8 +367,7 @@ const TopicTrackingState = EmberObject.extend({ topic.setProperties({ highest_post_number: state.highest_post_number, last_read_post_number: state.last_read_post_number, - new_posts: newPosts, - unread: unread, + unread_posts: unread, is_seen: state.is_seen, unseen: !state.last_read_post_number && isUnseen(state), }); @@ -654,14 +652,13 @@ const TopicTrackingState = EmberObject.extend({ newState.topic_id = topic.id; newState.notification_level = topic.notification_level; - // see ListableTopicSerializer for unread/unseen/new_posts and other + // see ListableTopicSerializer for unread_posts/unseen and other // topic property logic if (topic.unseen) { newState.last_read_post_number = null; - } else if (topic.unread || topic.new_posts) { + } else if (topic.unread_posts) { newState.last_read_post_number = - topic.highest_post_number - - ((topic.unread || 0) + (topic.new_posts || 0)); + topic.highest_post_number - (topic.unread_posts || 0); } else { // remove the topic if it is no longer unread/new (it has been seen) // and if there are too many topics in memory diff --git a/app/assets/javascripts/discourse/app/models/topic.js b/app/assets/javascripts/discourse/app/models/topic.js index 0720289df8..a603aeec26 100644 --- a/app/assets/javascripts/discourse/app/models/topic.js +++ b/app/assets/javascripts/discourse/app/models/topic.js @@ -7,7 +7,6 @@ import I18n from "I18n"; import PreloadStore from "discourse/lib/preload-store"; import { Promise } from "rsvp"; import RestModel from "discourse/models/rest"; -import Session from "discourse/models/session"; import Site from "discourse/models/site"; import User from "discourse/models/user"; import { ajax } from "discourse/lib/ajax"; @@ -21,6 +20,7 @@ import { longDate } from "discourse/lib/formatter"; import { popupAjaxError } from "discourse/lib/ajax-error"; import { resolveShareUrl } from "discourse/helpers/share-url"; import DiscourseURL, { userPath } from "discourse/lib/url"; +import deprecated from "discourse-common/lib/deprecated"; export function loadTopicView(topic, args) { const data = deepMerge({}, args); @@ -239,10 +239,16 @@ const Topic = RestModel.extend({ return url; }, - @discourseComputed("new_posts", "unread") - totalUnread(newPosts, unread) { - const count = (unread || 0) + (newPosts || 0); - return count > 0 ? count : null; + @discourseComputed("unread_posts", "new_posts") + totalUnread(unreadPosts, newPosts) { + deprecated("The totalUnread property of the topic model is deprecated"); + return unreadPosts || newPosts; + }, + + @discourseComputed("unread_posts", "new_posts") + displayNewPosts(unreadPosts, newPosts) { + deprecated("The displayNewPosts property of the topic model is deprecated"); + return unreadPosts || newPosts; }, @discourseComputed("last_read_post_number", "url") @@ -284,25 +290,6 @@ const Topic = RestModel.extend({ return userPath(username); }, - // The amount of new posts to display. It might be different than what the server - // tells us if we are still asynchronously flushing our "recently read" data. - // So take what the browser has seen into consideration. - @discourseComputed("new_posts", "id") - displayNewPosts(newPosts, id) { - const highestSeen = Session.currentProp("highestSeenByTopic")[id]; - if (highestSeen) { - const delta = highestSeen - this.last_read_post_number; - if (delta > 0) { - let result = newPosts - delta; - if (result < 0) { - result = 0; - } - return result; - } - } - return newPosts; - }, - @discourseComputed("views") viewsHeat(v) { if (v >= this.siteSettings.topic_views_heat_high) { diff --git a/app/assets/javascripts/discourse/app/raw-views/list/post-count-or-badges.js b/app/assets/javascripts/discourse/app/raw-views/list/post-count-or-badges.js index 5a9573090b..9b1283377b 100644 --- a/app/assets/javascripts/discourse/app/raw-views/list/post-count-or-badges.js +++ b/app/assets/javascripts/discourse/app/raw-views/list/post-count-or-badges.js @@ -1,11 +1,10 @@ -import { and, or } from "@ember/object/computed"; +import { and } from "@ember/object/computed"; import EmberObject from "@ember/object"; import I18n from "I18n"; import discourseComputed from "discourse-common/utils/decorators"; export default EmberObject.extend({ - postCountsPresent: or("topic.unread", "topic.displayNewPosts"), - showBadges: and("postBadgesEnabled", "postCountsPresent"), + showBadges: and("postBadgesEnabled", "topic.unread_posts"), @discourseComputed newDotText() { diff --git a/app/assets/javascripts/discourse/app/routes/topic-from-params.js b/app/assets/javascripts/discourse/app/routes/topic-from-params.js index 35fd8b40dc..f97c7c882e 100644 --- a/app/assets/javascripts/discourse/app/routes/topic-from-params.js +++ b/app/assets/javascripts/discourse/app/routes/topic-from-params.js @@ -69,6 +69,8 @@ export default DiscourseRoute.extend({ "model.currentPost": closest, enteredIndex: topic.postStream.progressIndexOfPost(closestPost), enteredAt: Date.now().toString(), + userLastReadPostNumber: topic.last_read_post_number, + highestPostNumber: topic.highest_post_number, }); this.appEvents.trigger("page:topic-loaded", topic); diff --git a/app/assets/javascripts/discourse/app/templates/components/featured-topic.hbs b/app/assets/javascripts/discourse/app/templates/components/featured-topic.hbs index c6a04a2d69..39b208a305 100644 --- a/app/assets/javascripts/discourse/app/templates/components/featured-topic.hbs +++ b/app/assets/javascripts/discourse/app/templates/components/featured-topic.hbs @@ -1,5 +1,5 @@ {{raw "topic-status" topic=topic}} {{html-safe topic.fancyTitle}} -{{topic-post-badges newPosts=topic.totalUnread unseen=topic.unseen url=topic.lastUnreadUrl}} +{{topic-post-badges unreadPosts=topic.unread_posts unseen=topic.unseen url=topic.lastUnreadUrl}} {{format-age topic.last_posted_at}} diff --git a/app/assets/javascripts/discourse/app/templates/components/latest-topic-list-item.hbs b/app/assets/javascripts/discourse/app/templates/components/latest-topic-list-item.hbs index 6d117176b1..d9b8522daf 100644 --- a/app/assets/javascripts/discourse/app/templates/components/latest-topic-list-item.hbs +++ b/app/assets/javascripts/discourse/app/templates/components/latest-topic-list-item.hbs @@ -11,7 +11,7 @@ {{#if topic.featured_link}} {{topic-featured-link topic}} {{/if}} - {{topic-post-badges newPosts=topic.totalUnread unseen=topic.unseen url=topic.lastUnreadUrl}} + {{topic-post-badges unreadPosts=topic.unread_posts unseen=topic.unseen url=topic.lastUnreadUrl}}
Your new topics will appear here. By default, topics are considered new and will show a indicator if they were created in the last 2 days.
Visit your preferences to change this.
' - unread: 'Your unread topics appear here.
By default, topics are considered unread and will show unread counts 1 if you:
Or if you have explicitly set the topic to Tracked or Watched via the 🔔 in each topic.
Visit your preferences to change this.
' + unread: 'Your unread topics appear here.
By default, topics are considered unread and will show unread counts 1 if you:
Or if you have explicitly set the topic to Tracked or Watched via the 🔔 in each topic.
Visit your preferences to change this.
' bottom: latest: "There are no more latest topics." posted: "There are no more posted topics." @@ -2457,15 +2457,9 @@ en: not_found: title: "Topic not found" description: "Sorry, we couldn't find that topic. Perhaps it was removed by a moderator?" - total_unread_posts: + unread_posts: one: "you have %{count} unread post in this topic" other: "you have %{count} unread posts in this topic" - unread_posts: - one: "you have %{count} unread old post in this topic" - other: "you have %{count} unread old posts in this topic" - new_posts: - one: "there is %{count} new post in this topic since you last read it" - other: "there are %{count} new posts in this topic since you last read it" likes: one: "there is %{count} like in this topic" other: "there are %{count} likes in this topic" diff --git a/db/post_migrate/20210624023831_remove_highest_seen_post_number_from_topic_users.rb b/db/post_migrate/20210624023831_remove_highest_seen_post_number_from_topic_users.rb new file mode 100644 index 0000000000..dbf2cdc3e2 --- /dev/null +++ b/db/post_migrate/20210624023831_remove_highest_seen_post_number_from_topic_users.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +require 'migration/column_dropper' + +class RemoveHighestSeenPostNumberFromTopicUsers < ActiveRecord::Migration[6.1] + DROPPED_COLUMNS = { + topic_users: %i{highest_seen_post_number} + } + + def up + DROPPED_COLUMNS.each do |table, columns| + Migration::ColumnDropper.execute_drop(table, columns) + end + end + + def down + raise ActiveRecord::IrreversibleMigration + end +end diff --git a/lib/post_creator.rb b/lib/post_creator.rb index abc8dc445b..a4f2490a16 100644 --- a/lib/post_creator.rb +++ b/lib/post_creator.rb @@ -646,7 +646,6 @@ class PostCreator @topic.id, posted: true, last_read_post_number: @post.post_number, - highest_seen_post_number: @post.post_number, last_posted_at: Time.zone.now) # assume it took us 5 seconds of reading time to make a post diff --git a/lib/tasks/import.rake b/lib/tasks/import.rake index a4552c70c5..861b6d998a 100644 --- a/lib/tasks/import.rake +++ b/lib/tasks/import.rake @@ -57,8 +57,8 @@ def insert_topic_users log "Inserting topic users..." DB.exec <<-SQL - INSERT INTO topic_users (user_id, topic_id, posted, last_read_post_number, highest_seen_post_number, first_visited_at, last_visited_at, total_msecs_viewed) - SELECT user_id, topic_id, 't' , MAX(post_number), MAX(post_number), MIN(created_at), MAX(created_at), COUNT(id) * #{MS_SPEND_CREATING_POST} + INSERT INTO topic_users (user_id, topic_id, posted, last_read_post_number, first_visited_at, last_visited_at, total_msecs_viewed) + SELECT user_id, topic_id, 't' , MAX(post_number), MIN(created_at), MAX(created_at), COUNT(id) * #{MS_SPEND_CREATING_POST} FROM posts WHERE user_id > 0 GROUP BY user_id, topic_id diff --git a/lib/tasks/posts.rake b/lib/tasks/posts.rake index 51aed6c96e..4abfaf01a6 100644 --- a/lib/tasks/posts.rake +++ b/lib/tasks/posts.rake @@ -346,7 +346,6 @@ task 'posts:reorder_posts', [:topic_id] => [:environment] do |_, args| ["post_timings", "post_number"], ["posts", "reply_to_post_number"], ["topic_users", "last_read_post_number"], - ["topic_users", "highest_seen_post_number"], ["topic_users", "last_emailed_post_number"], ].each do |table, column| builder = DB.build <<~SQL diff --git a/lib/topics_bulk_action.rb b/lib/topics_bulk_action.rb index 4a9418853f..ad19ac1bcf 100644 --- a/lib/topics_bulk_action.rb +++ b/lib/topics_bulk_action.rb @@ -72,7 +72,7 @@ class TopicsBulkAction highest_number_source_column = @user.staff? ? 'highest_staff_post_number' : 'highest_post_number' sql = <<~SQL UPDATE topic_users tu - SET highest_seen_post_number = t.#{highest_number_source_column} , last_read_post_number = t.#{highest_number_source_column} + SET last_read_post_number = t.#{highest_number_source_column} FROM topics t WHERE t.id = tu.topic_id AND tu.user_id = :user_id AND t.id IN (:topic_ids) SQL diff --git a/lib/unread.rb b/lib/unread.rb index 917c2e396d..27c8d046e2 100644 --- a/lib/unread.rb +++ b/lib/unread.rb @@ -2,7 +2,7 @@ class Unread - # This module helps us calculate unread and new post counts + # This module helps us calculate unread post counts def initialize(topic, topic_user, guardian) @guardian = guardian @@ -11,29 +11,27 @@ class Unread end def unread_posts - return 0 if do_not_notify?(@topic_user.notification_level) - result = ((@topic_user.highest_seen_post_number || 0) - (@topic_user.last_read_post_number || 0)) - result = 0 if result < 0 - result - end - - def new_posts - return 0 if @topic_user.highest_seen_post_number.blank? + return 0 if @topic_user.last_read_post_number.blank? return 0 if do_not_notify?(@topic_user.notification_level) highest_post_number = @guardian.is_staff? ? @topic.highest_staff_post_number : @topic.highest_post_number - return 0 if (@topic_user.last_read_post_number || 0) > highest_post_number + return 0 if @topic_user.last_read_post_number > highest_post_number - new_posts = (highest_post_number - @topic_user.highest_seen_post_number) - new_posts = 0 if new_posts < 0 - new_posts + unread = (highest_post_number - @topic_user.last_read_post_number) + unread = 0 if unread < 0 + unread end protected + DO_NOT_NOTIFY_LEVELS = [ + TopicUser.notification_levels[:muted], + TopicUser.notification_levels[:regular] + ] + def do_not_notify?(notification_level) - [TopicUser.notification_levels[:muted], TopicUser.notification_levels[:regular]].include?(notification_level) + DO_NOT_NOTIFY_LEVELS.include?(notification_level) end end diff --git a/plugins/discourse-narrative-bot/plugin.rb b/plugins/discourse-narrative-bot/plugin.rb index 7f3fde2436..d2b790a893 100644 --- a/plugins/discourse-narrative-bot/plugin.rb +++ b/plugins/discourse-narrative-bot/plugin.rb @@ -192,7 +192,7 @@ after_initialize do return if topic_id.blank? || data[:track] != DiscourseNarrativeBot::NewUserNarrative.to_s topic_user = topic_users.find_by(topic_id: topic_id) - return if topic_user.present? && (topic_user.last_read_post_number.present? || topic_user.highest_seen_post_number.present?) + return if topic_user.present? && topic_user.last_read_post_number.present? topic = Topic.find_by(id: topic_id) return if topic.blank? diff --git a/plugins/poll/test/javascripts/acceptance/poll-in-reply-history-test.js.es6 b/plugins/poll/test/javascripts/acceptance/poll-in-reply-history-test.js.es6 index 12c507d1d5..f2e08b0b46 100644 --- a/plugins/poll/test/javascripts/acceptance/poll-in-reply-history-test.js.es6 +++ b/plugins/poll/test/javascripts/acceptance/poll-in-reply-history-test.js.es6 @@ -150,8 +150,7 @@ acceptance("Poll in a post reply history", function (needs) { archetype: "regular", unseen: false, last_read_post_number: 3, - unread: 0, - new_posts: 0, + unread_posts: 0, pinned: false, unpinned: null, visible: true, @@ -205,8 +204,7 @@ acceptance("Poll in a post reply history", function (needs) { archetype: "regular", unseen: false, last_read_post_number: 12, - unread: 0, - new_posts: 0, + unread_posts: 0, pinned: false, unpinned: null, visible: true, diff --git a/plugins/poll/test/javascripts/acceptance/poll-quote-test.js.es6 b/plugins/poll/test/javascripts/acceptance/poll-quote-test.js.es6 index 3b5bb2ddac..f000d468e0 100644 --- a/plugins/poll/test/javascripts/acceptance/poll-quote-test.js.es6 +++ b/plugins/poll/test/javascripts/acceptance/poll-quote-test.js.es6 @@ -230,8 +230,7 @@ acceptance("Poll quote", function (needs) { archetype: "regular", unseen: false, last_read_post_number: 1, - unread: 0, - new_posts: 0, + unread_posts: 0, pinned: false, unpinned: true, visible: true, @@ -275,8 +274,7 @@ acceptance("Poll quote", function (needs) { archetype: "regular", unseen: false, last_read_post_number: 1, - unread: 0, - new_posts: 0, + unread_posts: 0, pinned: false, unpinned: null, visible: true, diff --git a/plugins/poll/test/javascripts/acceptance/poll-results-test.js.es6 b/plugins/poll/test/javascripts/acceptance/poll-results-test.js.es6 index 30a7889d43..4a029002ed 100644 --- a/plugins/poll/test/javascripts/acceptance/poll-results-test.js.es6 +++ b/plugins/poll/test/javascripts/acceptance/poll-results-test.js.es6 @@ -239,8 +239,7 @@ acceptance("Poll results", function (needs) { archetype: "regular", unseen: false, last_read_post_number: 9, - unread: 0, - new_posts: 0, + unread_posts: 0, pinned: false, unpinned: true, visible: true, @@ -295,8 +294,7 @@ acceptance("Poll results", function (needs) { archetype: "regular", unseen: false, last_read_post_number: 1, - unread: 0, - new_posts: 0, + unread_posts: 0, pinned: false, unpinned: null, visible: true, @@ -343,8 +341,7 @@ acceptance("Poll results", function (needs) { archetype: "regular", unseen: false, last_read_post_number: 1, - unread: 0, - new_posts: 0, + unread_posts: 0, pinned: false, unpinned: null, visible: true, @@ -389,8 +386,7 @@ acceptance("Poll results", function (needs) { archetype: "regular", unseen: false, last_read_post_number: 12, - unread: 0, - new_posts: 0, + unread_posts: 0, pinned: false, unpinned: null, visible: true, diff --git a/script/import_scripts/base.rb b/script/import_scripts/base.rb index a88360941a..7cd7961cfc 100644 --- a/script/import_scripts/base.rb +++ b/script/import_scripts/base.rb @@ -762,8 +762,8 @@ class ImportScripts::Base puts "", "Updating topic users" DB.exec <<~SQL - INSERT INTO topic_users (user_id, topic_id, posted, last_read_post_number, highest_seen_post_number, first_visited_at, last_visited_at, total_msecs_viewed) - SELECT user_id, topic_id, 't' , MAX(post_number), MAX(post_number), MIN(created_at), MAX(created_at), COUNT(id) * 5000 + INSERT INTO topic_users (user_id, topic_id, posted, last_read_post_number, first_visited_at, last_visited_at, total_msecs_viewed) + SELECT user_id, topic_id, 't' , MAX(post_number), MIN(created_at), MAX(created_at), COUNT(id) * 5000 FROM posts WHERE user_id > 0 GROUP BY user_id, topic_id diff --git a/script/import_scripts/telligent.rb b/script/import_scripts/telligent.rb index a6b1218e41..32ffda8acb 100644 --- a/script/import_scripts/telligent.rb +++ b/script/import_scripts/telligent.rb @@ -598,8 +598,7 @@ class ImportScripts::Telligent < ImportScripts::Base # Mark all imported messages as read DB.exec(<<~SQL) UPDATE topic_users tu - SET last_read_post_number = t.highest_post_number, - highest_seen_post_number = t.highest_post_number + SET last_read_post_number = t.highest_post_number FROM topics t JOIN topic_custom_fields tcf ON t.id = tcf.topic_id WHERE tu.topic_id = t.id diff --git a/spec/components/post_destroyer_spec.rb b/spec/components/post_destroyer_spec.rb index 66ae44a83f..e9a005d6f0 100644 --- a/spec/components/post_destroyer_spec.rb +++ b/spec/components/post_destroyer_spec.rb @@ -652,10 +652,6 @@ describe PostDestroyer do it "sets the second user's last_read_post_number back to 1" do expect(topic_user.last_read_post_number).to eq(1) end - - it "sets the second user's last_read_post_number back to 1" do - expect(topic_user.highest_seen_post_number).to eq(1) - end end end diff --git a/spec/components/topics_bulk_action_spec.rb b/spec/components/topics_bulk_action_spec.rb index c096a5a19f..169af2603d 100644 --- a/spec/components/topics_bulk_action_spec.rb +++ b/spec/components/topics_bulk_action_spec.rb @@ -82,7 +82,6 @@ describe TopicsBulkAction do tu = TopicUser.find_by(user_id: post1.user_id, topic_id: post1.topic_id) expect(tu.last_read_post_number).to eq(3) - expect(tu.highest_seen_post_number).to eq(3) end context "when the user is staff" do @@ -106,7 +105,6 @@ describe TopicsBulkAction do tu = TopicUser.find_by(user_id: user.id, topic_id: post1.topic_id) expect(tu.last_read_post_number).to eq(4) - expect(tu.highest_seen_post_number).to eq(4) end end end diff --git a/spec/components/unread_spec.rb b/spec/components/unread_spec.rb index a7d4d4a65e..cf112df130 100644 --- a/spec/components/unread_spec.rb +++ b/spec/components/unread_spec.rb @@ -27,62 +27,45 @@ describe Unread do describe 'staff counts' do it 'should correctly return based on staff post number' do - user.admin = true topic_user.last_read_post_number = 13 - topic_user.highest_seen_post_number = 13 - expect(unread.unread_posts).to eq(0) - expect(unread.new_posts).to eq(2) + expect(unread.unread_posts).to eq(2) end end describe 'unread_posts' do - it 'should have 0 unread posts if the user has seen all posts' do + it 'should have 0 unread posts if the user has read all posts' do topic_user.last_read_post_number = 13 - topic_user.highest_seen_post_number = 13 expect(unread.unread_posts).to eq(0) end - it 'should have 6 unread posts if the user has seen all but 6 posts' do - topic_user.last_read_post_number = 5 - topic_user.highest_seen_post_number = 11 - expect(unread.unread_posts).to eq(6) + it 'returns the right unread posts for a user' do + topic_user.last_read_post_number = 10 + expect(unread.unread_posts).to eq(3) end - it 'should have 0 unread posts if the user has seen more posts than exist (deleted)' do - topic_user.last_read_post_number = 100 - topic_user.highest_seen_post_number = 13 + it 'returns the right unread posts for a staff user' do + user.admin = true + topic_user.last_read_post_number = 10 + expect(unread.unread_posts).to eq(5) + end + + it 'should have 0 unread posts if the user has read more posts than exist (deleted)' do + topic_user.last_read_post_number = 14 expect(unread.unread_posts).to eq(0) end - end - describe 'new_posts' do - it 'should have 0 new posts if the user has read all posts' do - topic_user.last_read_post_number = 13 - expect(unread.new_posts).to eq(0) - end - - it 'returns 0 when the topic is the same length as when you last saw it' do - topic_user.highest_seen_post_number = 13 - expect(unread.new_posts).to eq(0) - end - - it 'has 3 new posts if the user has read 10 posts' do - topic_user.highest_seen_post_number = 10 - expect(unread.new_posts).to eq(3) - end - - it 'has 0 new posts if the user has read 10 posts but is not tracking' do - topic_user.highest_seen_post_number = 10 + it 'has 0 unread posts if the user has read 10 posts but is not tracking' do + topic_user.last_read_post_number = 10 topic_user.notification_level = TopicUser.notification_levels[:regular] - expect(unread.new_posts).to eq(0) + expect(unread.unread_posts).to eq(0) end - it 'has 0 new posts if the user read more posts than exist (deleted)' do - topic_user.highest_seen_post_number = 16 - expect(unread.new_posts).to eq(0) + it 'has 0 unread psots if the user has not seen the topic' do + topic_user.last_read_post_number = nil + expect(unread.unread_posts).to eq(0) end end diff --git a/spec/fixtures/json/sam-s-simple-theme.dcstyle.json b/spec/fixtures/json/sam-s-simple-theme.dcstyle.json index e942c38689..103fae676f 100644 --- a/spec/fixtures/json/sam-s-simple-theme.dcstyle.json +++ b/spec/fixtures/json/sam-s-simple-theme.dcstyle.json @@ -1 +1 @@ -{"theme":{"id":2,"name":"Sam's Simple Theme","key":"6a390523-b662-4966-97d6-e731d292cd9d","created_at":"2017-05-08T06:17:14.510Z","updated_at":"2017-05-08T06:17:14.510Z","color_scheme":null,"color_scheme_id":null,"user_selectable":false,"remote_theme_id":1,"theme_fields":[{"name":"scss","target":"desktop","value":".topic-list \u003e tbody \u003e tr:nth-child(odd) {\n background-color: white;\n}\n\n\n.topic-list \u003e tbody tr:not(.last-visit):not(.topic-list-item-separator) td {\n border-bottom: 1px solid #eee;\n}\n\n.topic-list a.title:not(.badge-notification) {\n color: #3b5998;\n font-weight: normal;\n font-family: 'Helvetica Neue', Helvetica, Arial, Utkal, sans-serif;\n font-size: 18px;\n}\n\n.topic-list a.title:not(.badge-notification):hover {\n text-decoration: underline;\n}\n\n.topic-list .creator, .topic-list .editor {\n font-size: 13px;\n display: block;\n margin-top: 3px;\n}\n\n.topic-list .main-link {\n width: auto;\n}\n\n.topic-list {\n td, .creator a, .editor a {\n color: #888;\n }\n}\n\n.topic-list td {\n padding-bottom: 10px;\n}\n\n.topic-list th {\n color: black;\n background-color: #fafafa;\n}\n.topic-list {\n border-top: none;\n}\n\n.topic-list td:first-of-type {\n padding-bottom: 10px;\n padding-left: 10px;\n padding-top: 10px;\n}\n\n.topic-list tr.topic-list-item-separator td:first-of-type {\n padding: 0;\n}\n\n \n.topic-list {\n .fa-tag {\n opacity: 0.7;\n font-size: 10px;\n margin-right: -2px;\n }\n .num.posts-map {\n position: relative;\n font-size: 17px;\n a {\n color: #888 !important;\n font-weight: normal;\n }\n a.heatmap-high {\n color: #c66 !important; \n }\n width: 100px;\n }\n}\n\n.topic-list td.last-post, .topic-list th.activity {\n width: 160px;\n .relative-date {\n color: #666;\n }\n}\n\n.topic-list .creator .relative-date {\n margin-left: 8px;\n}\n\n.badge-category-bg {\n opacity: 0.8;\n}\n\n.topic-list .badge-wrapper.bar {\n .badge-category {\n color: #9a9a9a !important;\n font-weight: 600;\n font-size: 12px;\n padding: 2px 6px;\n }\n .badge-category-bg {\n top: -1px;\n }\n}\n\n.last-post {\n .poster-avatar {\n margin-right: 10px;\n }\n .poster-avatar, .poster-info {\n float: left;\n }\n}\n\n.topic-list .posts {\n width: auto;\n}\n\n/* topic page */\n#topic-progress {\n background-color: #f1f1f1;\n color: #666;\n font-weight: normal;\n .bg {\n background-color: #bee9e9;\n }\n}\n\nnav.post-controls button.has-like {\n color: #08c;\n}\n\n.title-wrapper .discourse-tag {\n border-radius: 5px !important;\n border: 0px solid #D0D0D0 !important;\n padding: 1px 6px !important;\n color: #1D1D1D !important;\n background-color: #F1F1F1 !important;\n}\n\n.badge-wrapper.bullet span.badge-category {\n color: #333 !important;\n}\n\n.creator .badge-wrapper.bullet span.badge-category {\n color: #888 !important;\n margin-top: -2px;\n}\n\nimg.avatar {\n border-radius: 3px;\n}\n\n#suggested-topics td.main-link {\n width: 500px;\n}\n\n.topic-list a.title.visited:not(.badge-notification) {\n color: #6644aa;\n}\n"},{"name":"header","target":"desktop","value":"\u003cscript type='text/x-handlebars' data-template-name='list/topic-list-item.raw'\u003e\n\n\u003ctd class='main-link clearfix'\u003e\n\n {{raw \"topic-status\" topic=topic}}\n {{topic-link topic}}\n {{#if controller.showTopicPostBadges}}\n {{raw \"topic-post-badges\" unread=topic.unread newPosts=topic.displayNewPosts unseen=topic.unseen url=topic.lastUnreadUrl}}\n {{/if}}\n\n\n {{raw \"list/topic-excerpt\" topic=model}}\n \u003cdiv class='creator'\u003e\n {{#if showCategory}}\n {{category-link topic.category}}\n {{/if}}\n {{~#if topic.creator ~}}\n \u003ca href=\"/users/{{topic.creator.username}}\" data-auto-route=\"true\" data-user-card=\"{{topic.creator.username}}\"\u003e{{topic.creator.username}}\u003c/a\u003e \u003ca href={{topic.url}}\u003e{{format-date topic.createdAt format=\"tiny\"}}\u003c/a\u003e\n {{~/if ~}}\n {{raw \"list/action-list\" topic=topic postNumbers=topic.liked_post_numbers className=\"likes\" icon=\"heart\"}}\n \u003c/div\u003e\n\u003c/td\u003e\n\n\n\n{{#if controller.showLikes}}\n\u003ctd class=\"num likes\"\u003e\n {{number topic.like_count}} \u003ci class='fa fa-heart'\u003e\u003c/i\u003e\n\u003c/td\u003e\n{{/if}}\n \n{{#if controller.showOpLikes}}\n\u003ctd class=\"num likes\"\u003e\n {{number topic.op_like_count}} \u003ci class='fa fa-heart'\u003e\u003c/i\u003e\n\u003c/td\u003e\n{{/if}}\n\n{{raw \"list/posts-count-column\" topic=topic}}\n\n\u003ctd class=\"last-post\"\u003e\n\u003cdiv class='poster-avatar'\u003e\n\u003ca href=\"{{topic.lastPostUr}}\" data-user-card=\"{{topic.last_poster_username}}\"\u003e{{avatar topic.lastPoster usernamePath=\"username\" imageSize=\"medium\"}}\u003c/a\u003e\n\u003c/div\u003e\n\u003cdiv class='poster-info'\u003e\n\u003ca href=\"{{topic.lastPostUrl}}\"\u003e\n{{format-date topic.bumpedAt format=\"tiny\"}}\n\u003c/a\u003e\n\u003cspan class='editor'\u003e\u003ca href=\"/users/{{topic.last_poster_username}}\" data-auto-route=\"true\" data-user-card=\"{{topic.last_poster_username}}\"\u003e{{topic.last_poster_username}}\u003c/a\u003e\u003c/span\u003e\n\u003c/div\u003e\n\u003c/td\u003e\n\u003c/script\u003e\n\n\u003cscript type='text/x-handlebars' data-template-name='topic-list-header.raw'\u003e\n {{raw \"topic-list-header-column\" order='posts' name='topic.title'}}\n \n {{#if showLikes}}\n {{raw \"topic-list-header-column\" sortable='true' order='likes' number='true' forceName='Likes'}}\n {{/if}}\n {{#if showOpLikes}}\n {{raw \"topic-list-header-column\" sortable='true' order='op_likes' number='true' forceName='Likes'}}\n {{/if}}\n {{raw \"topic-list-header-column\" sortable='true' number='true' order='posts' forceName='Replies'}}\n {{raw \"topic-list-header-column\" sortable='true' order='activity' forceName='Last Post'}}\n\u003c/script\u003e\n\n\u003cscript\u003e\n\n(function(){\n\nvar TopicListItemView = require('discourse/components/topic-list-item').default;\n\n\nTopicListItemView.reopen({\n showCategory: function(){\n return !this.get('controller.hideCategory') \u0026\u0026\n this.get('topic.creator') \u0026\u0026\n this.get('topic.category.name') !== 'uncategorized';\n }.property()\n});\n \n})();\n \n\u003c/script\u003e\n"}],"child_themes":[],"remote_theme":{"id":1,"remote_url":"https://github.com/SamSaffron/discourse-simple-theme.git","remote_version":"49986016d76be1f526d5dc44704e6701021db900","local_version":"49986016d76be1f526d5dc44704e6701021db900","about_url":"https://meta.discourse.org/t/sams-personal-minimal-topic-list-design/23552","license_url":"https://github.com/SamSaffron/discourse-simple-theme/blob/master/LICENSE.txt","commits_behind":0,"remote_updated_at":"2017-05-08T06:17:14.487Z","updated_at":"2017-05-08T06:17:14.501Z"}}} +{"theme":{"id":2,"name":"Sam's Simple Theme","key":"6a390523-b662-4966-97d6-e731d292cd9d","created_at":"2017-05-08T06:17:14.510Z","updated_at":"2017-05-08T06:17:14.510Z","color_scheme":null,"color_scheme_id":null,"user_selectable":false,"remote_theme_id":1,"theme_fields":[{"name":"scss","target":"desktop","value":".topic-list \u003e tbody \u003e tr:nth-child(odd) {\n background-color: white;\n}\n\n\n.topic-list \u003e tbody tr:not(.last-visit):not(.topic-list-item-separator) td {\n border-bottom: 1px solid #eee;\n}\n\n.topic-list a.title:not(.badge-notification) {\n color: #3b5998;\n font-weight: normal;\n font-family: 'Helvetica Neue', Helvetica, Arial, Utkal, sans-serif;\n font-size: 18px;\n}\n\n.topic-list a.title:not(.badge-notification):hover {\n text-decoration: underline;\n}\n\n.topic-list .creator, .topic-list .editor {\n font-size: 13px;\n display: block;\n margin-top: 3px;\n}\n\n.topic-list .main-link {\n width: auto;\n}\n\n.topic-list {\n td, .creator a, .editor a {\n color: #888;\n }\n}\n\n.topic-list td {\n padding-bottom: 10px;\n}\n\n.topic-list th {\n color: black;\n background-color: #fafafa;\n}\n.topic-list {\n border-top: none;\n}\n\n.topic-list td:first-of-type {\n padding-bottom: 10px;\n padding-left: 10px;\n padding-top: 10px;\n}\n\n.topic-list tr.topic-list-item-separator td:first-of-type {\n padding: 0;\n}\n\n \n.topic-list {\n .fa-tag {\n opacity: 0.7;\n font-size: 10px;\n margin-right: -2px;\n }\n .num.posts-map {\n position: relative;\n font-size: 17px;\n a {\n color: #888 !important;\n font-weight: normal;\n }\n a.heatmap-high {\n color: #c66 !important; \n }\n width: 100px;\n }\n}\n\n.topic-list td.last-post, .topic-list th.activity {\n width: 160px;\n .relative-date {\n color: #666;\n }\n}\n\n.topic-list .creator .relative-date {\n margin-left: 8px;\n}\n\n.badge-category-bg {\n opacity: 0.8;\n}\n\n.topic-list .badge-wrapper.bar {\n .badge-category {\n color: #9a9a9a !important;\n font-weight: 600;\n font-size: 12px;\n padding: 2px 6px;\n }\n .badge-category-bg {\n top: -1px;\n }\n}\n\n.last-post {\n .poster-avatar {\n margin-right: 10px;\n }\n .poster-avatar, .poster-info {\n float: left;\n }\n}\n\n.topic-list .posts {\n width: auto;\n}\n\n/* topic page */\n#topic-progress {\n background-color: #f1f1f1;\n color: #666;\n font-weight: normal;\n .bg {\n background-color: #bee9e9;\n }\n}\n\nnav.post-controls button.has-like {\n color: #08c;\n}\n\n.title-wrapper .discourse-tag {\n border-radius: 5px !important;\n border: 0px solid #D0D0D0 !important;\n padding: 1px 6px !important;\n color: #1D1D1D !important;\n background-color: #F1F1F1 !important;\n}\n\n.badge-wrapper.bullet span.badge-category {\n color: #333 !important;\n}\n\n.creator .badge-wrapper.bullet span.badge-category {\n color: #888 !important;\n margin-top: -2px;\n}\n\nimg.avatar {\n border-radius: 3px;\n}\n\n#suggested-topics td.main-link {\n width: 500px;\n}\n\n.topic-list a.title.visited:not(.badge-notification) {\n color: #6644aa;\n}\n"},{"name":"header","target":"desktop","value":"\u003cscript type='text/x-handlebars' data-template-name='list/topic-list-item.raw'\u003e\n\n\u003ctd class='main-link clearfix'\u003e\n\n {{raw \"topic-status\" topic=topic}}\n {{topic-link topic}}\n {{#if controller.showTopicPostBadges}}\n {{raw \"topic-post-badges\" unreadPosts=topic.unread_posts unseen=topic.unseen url=topic.lastUnreadUrl}}\n {{/if}}\n\n\n {{raw \"list/topic-excerpt\" topic=model}}\n \u003cdiv class='creator'\u003e\n {{#if showCategory}}\n {{category-link topic.category}}\n {{/if}}\n {{~#if topic.creator ~}}\n \u003ca href=\"/users/{{topic.creator.username}}\" data-auto-route=\"true\" data-user-card=\"{{topic.creator.username}}\"\u003e{{topic.creator.username}}\u003c/a\u003e \u003ca href={{topic.url}}\u003e{{format-date topic.createdAt format=\"tiny\"}}\u003c/a\u003e\n {{~/if ~}}\n {{raw \"list/action-list\" topic=topic postNumbers=topic.liked_post_numbers className=\"likes\" icon=\"heart\"}}\n \u003c/div\u003e\n\u003c/td\u003e\n\n\n\n{{#if controller.showLikes}}\n\u003ctd class=\"num likes\"\u003e\n {{number topic.like_count}} \u003ci class='fa fa-heart'\u003e\u003c/i\u003e\n\u003c/td\u003e\n{{/if}}\n \n{{#if controller.showOpLikes}}\n\u003ctd class=\"num likes\"\u003e\n {{number topic.op_like_count}} \u003ci class='fa fa-heart'\u003e\u003c/i\u003e\n\u003c/td\u003e\n{{/if}}\n\n{{raw \"list/posts-count-column\" topic=topic}}\n\n\u003ctd class=\"last-post\"\u003e\n\u003cdiv class='poster-avatar'\u003e\n\u003ca href=\"{{topic.lastPostUr}}\" data-user-card=\"{{topic.last_poster_username}}\"\u003e{{avatar topic.lastPoster usernamePath=\"username\" imageSize=\"medium\"}}\u003c/a\u003e\n\u003c/div\u003e\n\u003cdiv class='poster-info'\u003e\n\u003ca href=\"{{topic.lastPostUrl}}\"\u003e\n{{format-date topic.bumpedAt format=\"tiny\"}}\n\u003c/a\u003e\n\u003cspan class='editor'\u003e\u003ca href=\"/users/{{topic.last_poster_username}}\" data-auto-route=\"true\" data-user-card=\"{{topic.last_poster_username}}\"\u003e{{topic.last_poster_username}}\u003c/a\u003e\u003c/span\u003e\n\u003c/div\u003e\n\u003c/td\u003e\n\u003c/script\u003e\n\n\u003cscript type='text/x-handlebars' data-template-name='topic-list-header.raw'\u003e\n {{raw \"topic-list-header-column\" order='posts' name='topic.title'}}\n \n {{#if showLikes}}\n {{raw \"topic-list-header-column\" sortable='true' order='likes' number='true' forceName='Likes'}}\n {{/if}}\n {{#if showOpLikes}}\n {{raw \"topic-list-header-column\" sortable='true' order='op_likes' number='true' forceName='Likes'}}\n {{/if}}\n {{raw \"topic-list-header-column\" sortable='true' number='true' order='posts' forceName='Replies'}}\n {{raw \"topic-list-header-column\" sortable='true' order='activity' forceName='Last Post'}}\n\u003c/script\u003e\n\n\u003cscript\u003e\n\n(function(){\n\nvar TopicListItemView = require('discourse/components/topic-list-item').default;\n\n\nTopicListItemView.reopen({\n showCategory: function(){\n return !this.get('controller.hideCategory') \u0026\u0026\n this.get('topic.creator') \u0026\u0026\n this.get('topic.category.name') !== 'uncategorized';\n }.property()\n});\n \n})();\n \n\u003c/script\u003e\n"}],"child_themes":[],"remote_theme":{"id":1,"remote_url":"https://github.com/SamSaffron/discourse-simple-theme.git","remote_version":"49986016d76be1f526d5dc44704e6701021db900","local_version":"49986016d76be1f526d5dc44704e6701021db900","about_url":"https://meta.discourse.org/t/sams-personal-minimal-topic-list-design/23552","license_url":"https://github.com/SamSaffron/discourse-simple-theme/blob/master/LICENSE.txt","commits_behind":0,"remote_updated_at":"2017-05-08T06:17:14.487Z","updated_at":"2017-05-08T06:17:14.501Z"}}} diff --git a/spec/models/post_mover_spec.rb b/spec/models/post_mover_spec.rb index 6c3e3a43ef..e5e26d2c33 100644 --- a/spec/models/post_mover_spec.rb +++ b/spec/models/post_mover_spec.rb @@ -425,7 +425,6 @@ describe PostMover do bookmarked: true, notification_level: TopicUser.notification_levels[:watching], last_read_post_number: 4, - highest_seen_post_number: 4, last_emailed_post_number: 3 ) tu2 = Fabricate( @@ -435,7 +434,6 @@ describe PostMover do bookmarked: true, notification_level: TopicUser.notification_levels[:watching], last_read_post_number: 4, - highest_seen_post_number: 4, last_emailed_post_number: 3 ) @@ -470,21 +468,18 @@ describe PostMover do create_topic_user( user1, last_read_post_number: 4, - highest_seen_post_number: 4, last_emailed_post_number: 3, notification_level: :tracking ) create_topic_user( user2, last_read_post_number: 2, - highest_seen_post_number: 2, last_emailed_post_number: 2, notification_level: :tracking ) create_topic_user( user3, last_read_post_number: 1, - highest_seen_post_number: 2, last_emailed_post_number: 4, notification_level: :watching ) @@ -496,28 +491,24 @@ describe PostMover do expect(TopicUser.find_by(topic: topic, user: user)) .to have_attributes( last_read_post_number: 4, - highest_seen_post_number: 4, last_emailed_post_number: nil, notification_level: TopicUser.notification_levels[:tracking] ) expect(TopicUser.find_by(topic: topic, user: user1)) .to have_attributes( last_read_post_number: 4, - highest_seen_post_number: 4, last_emailed_post_number: 3, notification_level: TopicUser.notification_levels[:tracking] ) expect(TopicUser.find_by(topic: topic, user: user2)) .to have_attributes( last_read_post_number: 2, - highest_seen_post_number: 2, last_emailed_post_number: 2, notification_level: TopicUser.notification_levels[:tracking] ) expect(TopicUser.find_by(topic: topic, user: user3)) .to have_attributes( last_read_post_number: 1, - highest_seen_post_number: 2, last_emailed_post_number: 4, notification_level: TopicUser.notification_levels[:watching] ) @@ -526,7 +517,6 @@ describe PostMover do expect(TopicUser.find_by(topic: new_topic, user: user)) .to have_attributes( last_read_post_number: 1, - highest_seen_post_number: 1, last_emailed_post_number: nil, notification_level: TopicUser.notification_levels[:watching], posted: true @@ -534,7 +524,6 @@ describe PostMover do expect(TopicUser.find_by(topic: new_topic, user: user1)) .to have_attributes( last_read_post_number: 2, - highest_seen_post_number: 2, last_emailed_post_number: 2, notification_level: TopicUser.notification_levels[:tracking], posted: false @@ -542,7 +531,6 @@ describe PostMover do expect(TopicUser.find_by(topic: new_topic, user: user2)) .to have_attributes( last_read_post_number: 2, - highest_seen_post_number: 2, last_emailed_post_number: 2, notification_level: TopicUser.notification_levels[:tracking], posted: true @@ -550,7 +538,6 @@ describe PostMover do expect(TopicUser.find_by(topic: new_topic, user: user3)) .to have_attributes( last_read_post_number: 1, - highest_seen_post_number: 2, last_emailed_post_number: 2, notification_level: TopicUser.notification_levels[:watching], posted: false @@ -810,52 +797,44 @@ describe PostMover do create_topic_user( user1, topic, last_read_post_number: 3, - highest_seen_post_number: 3, last_emailed_post_number: 3 ) create_topic_user( user1, destination_topic, last_read_post_number: 1, - highest_seen_post_number: 2, last_emailed_post_number: 1 ) create_topic_user( user2, topic, last_read_post_number: 3, - highest_seen_post_number: 3, last_emailed_post_number: 3 ) create_topic_user( user2, destination_topic, last_read_post_number: 2, - highest_seen_post_number: 1, last_emailed_post_number: 2 ) create_topic_user( admin1, topic, last_read_post_number: 3, - highest_seen_post_number: 3, last_emailed_post_number: 3 ) create_topic_user( admin1, destination_topic, last_read_post_number: 2, - highest_seen_post_number: 3, last_emailed_post_number: 1 ) create_topic_user( admin2, topic, last_read_post_number: 3, - highest_seen_post_number: 3, last_emailed_post_number: 3 ) create_topic_user( admin2, destination_topic, last_read_post_number: 3, - highest_seen_post_number: 2, last_emailed_post_number: 3 ) @@ -864,28 +843,24 @@ describe PostMover do expect(TopicUser.find_by(topic: moved_to_topic, user: user1)) .to have_attributes( last_read_post_number: 1, - highest_seen_post_number: 5, last_emailed_post_number: 1 ) expect(TopicUser.find_by(topic: moved_to_topic, user: user2)) .to have_attributes( last_read_post_number: 5, - highest_seen_post_number: 1, last_emailed_post_number: 5 ) expect(TopicUser.find_by(topic: moved_to_topic, user: admin1)) .to have_attributes( last_read_post_number: 2, - highest_seen_post_number: 5, last_emailed_post_number: 1 ) expect(TopicUser.find_by(topic: moved_to_topic, user: admin2)) .to have_attributes( last_read_post_number: 5, - highest_seen_post_number: 2, last_emailed_post_number: 5 ) end @@ -895,14 +870,14 @@ describe PostMover do original_topic_user1 = create_topic_user( user1, topic, - highest_seen_post_number: 5, + last_read_post_number: 5, first_visited_at: 5.hours.ago, last_visited_at: 30.minutes.ago, notification_level: :tracking ).reload destination_topic_user1 = create_topic_user( user1, destination_topic, - highest_seen_post_number: 5, + last_read_post_number: 5, first_visited_at: 7.hours.ago, last_visited_at: 2.hours.ago, notification_level: :watching @@ -910,14 +885,14 @@ describe PostMover do original_topic_user2 = create_topic_user( user2, topic, - highest_seen_post_number: 5, + last_read_post_number: 5, first_visited_at: 3.hours.ago, last_visited_at: 1.hour.ago, notification_level: :watching ).reload destination_topic_user2 = create_topic_user( user2, destination_topic, - highest_seen_post_number: 5, + last_read_post_number: 5, first_visited_at: 2.hours.ago, last_visited_at: 1.hour.ago, notification_level: :tracking diff --git a/spec/models/post_timing_spec.rb b/spec/models/post_timing_spec.rb index fbcb8cf3a6..f00c0f65b1 100644 --- a/spec/models/post_timing_spec.rb +++ b/spec/models/post_timing_spec.rb @@ -20,12 +20,11 @@ describe PostTiming do PostTiming.create!(topic_id: topic_id, user_id: user_id, post_number: post_number, msecs: 0) end - def topic_user(user_id, last_read_post_number, highest_seen_post_number) + def topic_user(user_id, last_read_post_number) TopicUser.create!( topic_id: topic_id, user_id: user_id, last_read_post_number: last_read_post_number, - highest_seen_post_number: highest_seen_post_number ) end @@ -37,9 +36,9 @@ describe PostTiming do timing(3, 2) timing(3, 3) - _tu_one = topic_user(1, 1, 1) - _tu_two = topic_user(2, 2, 2) - _tu_three = topic_user(3, 3, 3) + _tu_one = topic_user(1, 1) + _tu_two = topic_user(2, 2) + _tu_three = topic_user(3, 3) PostTiming.pretend_read(topic_id, 2, 3) @@ -49,15 +48,12 @@ describe PostTiming do tu = TopicUser.find_by(topic_id: topic_id, user_id: 1) expect(tu.last_read_post_number).to eq(1) - expect(tu.highest_seen_post_number).to eq(1) tu = TopicUser.find_by(topic_id: topic_id, user_id: 2) expect(tu.last_read_post_number).to eq(3) - expect(tu.highest_seen_post_number).to eq(3) tu = TopicUser.find_by(topic_id: topic_id, user_id: 3) expect(tu.last_read_post_number).to eq(3) - expect(tu.highest_seen_post_number).to eq(3) end end diff --git a/spec/models/topic_spec.rb b/spec/models/topic_spec.rb index efd5a6026c..9798b931a3 100644 --- a/spec/models/topic_spec.rb +++ b/spec/models/topic_spec.rb @@ -1615,7 +1615,12 @@ describe Topic do end it 'should generate the modified notification for the topic if already seen' do - TopicUser.create!(topic_id: topic.id, highest_seen_post_number: topic.posts.first.post_number, user_id: user.id) + TopicUser.create!( + topic_id: topic.id, + last_read_post_number: topic.posts.first.post_number, + user_id: user.id + ) + expect do topic.change_category_to_id(new_category.id) end.to change { Notification.count }.by(2) diff --git a/spec/models/topic_tracking_state_spec.rb b/spec/models/topic_tracking_state_spec.rb index f87eb2cbff..26e3d2c266 100644 --- a/spec/models/topic_tracking_state_spec.rb +++ b/spec/models/topic_tracking_state_spec.rb @@ -597,7 +597,6 @@ describe TopicTrackingState do tracking = { notification_level: TopicUser.notification_levels[:tracking], last_read_post_number: 1, - highest_seen_post_number: 1 } TopicUser.change(user.id, post1.topic_id, tracking) diff --git a/spec/models/topic_user_spec.rb b/spec/models/topic_user_spec.rb index cba1710533..e0b770ada3 100644 --- a/spec/models/topic_user_spec.rb +++ b/spec/models/topic_user_spec.rb @@ -434,7 +434,7 @@ describe TopicUser do p2 = Fabricate(:post, user: p1.user, topic: p1.topic, post_number: 2) p1.topic.notifier.watch_topic!(p1.user_id) - DB.exec("UPDATE topic_users set highest_seen_post_number=1, last_read_post_number=0 + DB.exec("UPDATE topic_users set last_read_post_number=0 WHERE topic_id = :topic_id AND user_id = :user_id", topic_id: p1.topic_id, user_id: p1.user_id) [p1, p2].each do |p| @@ -445,7 +445,6 @@ describe TopicUser do tu = TopicUser.find_by(user_id: p1.user_id, topic_id: p1.topic_id) expect(tu.last_read_post_number).to eq(p2.post_number) - expect(tu.highest_seen_post_number).to eq(2) end diff --git a/spec/requests/api/private_messages_spec.rb b/spec/requests/api/private_messages_spec.rb index 11d1974472..9bb3f6bef3 100644 --- a/spec/requests/api/private_messages_spec.rb +++ b/spec/requests/api/private_messages_spec.rb @@ -64,8 +64,7 @@ describe 'private messages' do archetype: { type: :string }, unseen: { type: :boolean }, last_read_post_number: { type: :integer }, - unread: { type: :integer }, - new_posts: { type: :integer }, + unread_posts: { type: :integer }, pinned: { type: :boolean }, unpinned: { type: :string, nullable: true }, visible: { type: :boolean }, @@ -174,8 +173,7 @@ describe 'private messages' do archetype: { type: :string }, unseen: { type: :boolean }, last_read_post_number: { type: :integer }, - unread: { type: :integer }, - new_posts: { type: :integer }, + unread_posts: { type: :integer }, pinned: { type: :boolean }, unpinned: { type: :string, nullable: true }, visible: { type: :boolean }, diff --git a/spec/requests/api/tags_spec.rb b/spec/requests/api/tags_spec.rb index 160100865d..47ec2cfbcd 100644 --- a/spec/requests/api/tags_spec.rb +++ b/spec/requests/api/tags_spec.rb @@ -277,8 +277,7 @@ describe 'tags' do archetype: { type: :string }, unseen: { type: :boolean }, last_read_post_number: { type: :integer }, - unread: { type: :integer }, - new_posts: { type: :integer }, + unread_posts: { type: :integer }, pinned: { type: :boolean }, unpinned: { type: :string, nullable: true }, visible: { type: :boolean }, diff --git a/spec/requests/api/topics_spec.rb b/spec/requests/api/topics_spec.rb index a2592cae03..ba67bc376f 100644 --- a/spec/requests/api/topics_spec.rb +++ b/spec/requests/api/topics_spec.rb @@ -225,8 +225,7 @@ describe 'topics' do archetype: { type: :string }, unseen: { type: :boolean }, last_read_post_number: { type: :integer }, - unread: { type: :integer }, - new_posts: { type: :integer }, + unread_posts: { type: :integer }, pinned: { type: :boolean }, unpinned: { type: :boolean }, visible: { type: :boolean }, @@ -603,8 +602,7 @@ describe 'topics' do archetype: { type: :string }, unseen: { type: :boolean }, last_read_post_number: { type: :integer }, - unread: { type: :integer }, - new_posts: { type: :integer }, + unread_posts: { type: :integer }, pinned: { type: :boolean }, unpinned: { type: :string, nullable: true }, visible: { type: :boolean }, @@ -704,8 +702,7 @@ describe 'topics' do archetype: { type: :string }, unseen: { type: :boolean }, last_read_post_number: { type: :integer }, - unread: { type: :integer }, - new_posts: { type: :integer }, + unread_posts: { type: :integer }, pinned: { type: :boolean }, unpinned: { type: :boolean }, visible: { type: :boolean }, @@ -807,8 +804,7 @@ describe 'topics' do archetype: { type: :string }, unseen: { type: :boolean }, last_read_post_number: { type: :integer }, - unread: { type: :integer }, - new_posts: { type: :integer }, + unread_posts: { type: :integer }, pinned: { type: :boolean }, unpinned: { type: :boolean }, visible: { type: :boolean }, diff --git a/spec/requests/topics_controller_spec.rb b/spec/requests/topics_controller_spec.rb index 444fc31afc..ccc4bf121c 100644 --- a/spec/requests/topics_controller_spec.rb +++ b/spec/requests/topics_controller_spec.rb @@ -1010,7 +1010,6 @@ RSpec.describe TopicsController do topic_user.update!( last_read_post_number: 2, - highest_seen_post_number: 2 ) # ensure we have 2 notifications @@ -1036,7 +1035,7 @@ RSpec.describe TopicsController do expect(PostTiming.where(topic: topic, user: user, post_number: 2).exists?).to eq(false) expect(PostTiming.where(topic: topic, user: user, post_number: 1).exists?).to eq(true) - expect(TopicUser.where(topic: topic, user: user, last_read_post_number: 1, highest_seen_post_number: 1).exists?).to eq(true) + expect(TopicUser.where(topic: topic, user: user, last_read_post_number: 1).exists?).to eq(true) user.user_stat.reload expect(user.user_stat.first_unread_at).to eq_time(topic.updated_at) @@ -1051,7 +1050,7 @@ RSpec.describe TopicsController do delete "/t/#{topic.id}/timings.json?last=1" expect(PostTiming.where(topic: topic, user: user, post_number: 1).exists?).to eq(false) - expect(TopicUser.where(topic: topic, user: user, last_read_post_number: nil, highest_seen_post_number: nil).exists?).to eq(true) + expect(TopicUser.where(topic: topic, user: user, last_read_post_number: nil).exists?).to eq(true) end end diff --git a/spec/services/post_alerter_spec.rb b/spec/services/post_alerter_spec.rb index 53c61f6b5c..a0969fab93 100644 --- a/spec/services/post_alerter_spec.rb +++ b/spec/services/post_alerter_spec.rb @@ -1259,7 +1259,13 @@ describe PostAlerter do fab!(:category) { Fabricate(:category) } it 'creates single edit notification when post is modified' do - TopicUser.create!(user_id: user.id, topic_id: topic.id, notification_level: TopicUser.notification_levels[:watching], highest_seen_post_number: post.post_number) + TopicUser.create!( + user_id: user.id, + topic_id: topic.id, + notification_level: TopicUser.notification_levels[:watching], + last_read_post_number: post.post_number + ) + PostRevisor.new(post).revise!(last_editor, tags: [tag.name]) PostAlerter.new.notify_post_users(post, []) expect(Notification.count).to eq(1) @@ -1280,7 +1286,7 @@ describe PostAlerter do category: category.id ) - TopicUser.change(user, post.topic_id, highest_seen_post_number: post.post_number) + TopicUser.change(user, post.topic_id, last_read_post_number: post.post_number) # Manually run job after the user read the topic to simulate a slow # Sidekiq.