mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
This reverts commits7426764af4andf5b18e2a31
This commit is contained in:
committed by
GitHub
parent
7426764af4
commit
a696cc07d2
@@ -182,11 +182,17 @@ const TopicTrackingState = EmberObject.extend({
|
||||
},
|
||||
|
||||
dismissNewTopic(data) {
|
||||
data.payload.topic_ids.forEach((k) => {
|
||||
const topic = this.states[`t${k}`];
|
||||
this.states[`t${k}`] = Object.assign({}, topic, {
|
||||
is_seen: true,
|
||||
});
|
||||
Object.keys(this.states).forEach((k) => {
|
||||
const topic = this.states[k];
|
||||
if (
|
||||
(!data.payload.category_id ||
|
||||
topic.category_id === parseInt(data.payload.category_id, 10)) &&
|
||||
(!data.payload.tag_id || topic.tags.includes(data.payload.tag_id))
|
||||
) {
|
||||
this.states[k] = Object.assign({}, topic, {
|
||||
is_seen: true,
|
||||
});
|
||||
}
|
||||
});
|
||||
this.notifyPropertyChange("states");
|
||||
this.incrementMessageCount();
|
||||
|
||||
@@ -346,7 +346,36 @@ module("Unit | Model | topic-tracking-state", function (hooks) {
|
||||
|
||||
state.dismissNewTopic({
|
||||
message_type: "dismiss_new",
|
||||
payload: { topic_ids: [112] },
|
||||
topic_id: 112,
|
||||
payload: { category_id: 2 },
|
||||
});
|
||||
assert.equal(state.states["t112"].is_seen, false);
|
||||
state.dismissNewTopic({
|
||||
message_type: "dismiss_new",
|
||||
topic_id: 112,
|
||||
payload: { category_id: 1 },
|
||||
});
|
||||
assert.equal(state.states["t112"].is_seen, true);
|
||||
|
||||
state.states["t112"].is_seen = false;
|
||||
state.dismissNewTopic({
|
||||
message_type: "dismiss_new",
|
||||
topic_id: 112,
|
||||
payload: { tag_id: "bar" },
|
||||
});
|
||||
assert.equal(state.states["t112"].is_seen, false);
|
||||
state.dismissNewTopic({
|
||||
message_type: "dismiss_new",
|
||||
topic_id: 112,
|
||||
payload: { tag_id: "foo" },
|
||||
});
|
||||
assert.equal(state.states["t112"].is_seen, true);
|
||||
|
||||
state.states["t112"].is_seen = false;
|
||||
state.dismissNewTopic({
|
||||
message_type: "dismiss_new",
|
||||
topic_id: 112,
|
||||
payload: {},
|
||||
});
|
||||
assert.equal(state.states["t112"].is_seen, true);
|
||||
});
|
||||
|
||||
@@ -910,30 +910,36 @@ class TopicsController < ApplicationController
|
||||
end
|
||||
|
||||
def reset_new
|
||||
topic_scope =
|
||||
if params[:category_id].present?
|
||||
category_ids = [params[:category_id]]
|
||||
if params[:include_subcategories] == 'true'
|
||||
category_ids = category_ids.concat(Category.where(parent_category_id: params[:category_id]).pluck(:id))
|
||||
end
|
||||
|
||||
scope = Topic.where(category_id: category_ids)
|
||||
scope = scope.joins(:tags).where(tags: { name: params[:tag_id] }) if params[:tag_id]
|
||||
scope
|
||||
elsif params[:tag_id].present?
|
||||
Topic.joins(:tags).where(tags: { name: params[:tag_id] })
|
||||
else
|
||||
if params[:tracked].to_s == "true"
|
||||
TopicQuery.tracked_filter(TopicQuery.new(current_user).new_results, current_user.id)
|
||||
else
|
||||
current_user.user_stat.update_column(:new_since, Time.zone.now)
|
||||
Topic
|
||||
end
|
||||
if params[:category_id].present?
|
||||
category_ids = [params[:category_id]]
|
||||
if params[:include_subcategories] == 'true'
|
||||
category_ids = category_ids.concat(Category.where(parent_category_id: params[:category_id]).pluck(:id))
|
||||
end
|
||||
|
||||
dismissed_topic_ids = DismissTopics.new(current_user, topic_scope).perform!
|
||||
TopicTrackingState.publish_dismiss_new(current_user.id, topic_ids: dismissed_topic_ids)
|
||||
topic_scope =
|
||||
if params[:tag_id]
|
||||
Topic.where(category_id: category_ids).joins(:tags).where(tags: { name: params[:tag_id] })
|
||||
else
|
||||
Topic.where(category_id: category_ids)
|
||||
end
|
||||
|
||||
DismissTopics.new(current_user, topic_scope).perform!
|
||||
category_ids.each do |category_id|
|
||||
TopicTrackingState.publish_dismiss_new(current_user.id, category_id: category_id, tag_id: params[:tag_id])
|
||||
end
|
||||
elsif params[:tag_id].present?
|
||||
DismissTopics.new(current_user, Topic.joins(:tags).where(tags: { name: params[:tag_id] })).perform!
|
||||
TopicTrackingState.publish_dismiss_new(current_user.id, tag_id: params[:tag_id])
|
||||
else
|
||||
if params[:tracked].to_s == "true"
|
||||
topics = TopicQuery.tracked_filter(TopicQuery.new(current_user).new_results, current_user.id)
|
||||
topic_users = topics.map { |topic| { topic_id: topic.id, user_id: current_user.id, last_read_post_number: 0 } }
|
||||
TopicUser.insert_all(topic_users) if !topic_users.empty?
|
||||
else
|
||||
current_user.user_stat.update_column(:new_since, Time.zone.now)
|
||||
TopicTrackingState.publish_dismiss_new(current_user.id)
|
||||
end
|
||||
end
|
||||
render body: nil
|
||||
end
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ module Jobs
|
||||
WHEN COALESCE(user_options.new_topic_duration_minutes, :default_duration) = :always THEN users.created_at
|
||||
WHEN COALESCE(user_options.new_topic_duration_minutes, :default_duration) = :last_visit THEN COALESCE(users.previous_visit_at,users.created_at)
|
||||
ELSE (:now::timestamp - INTERVAL '1 MINUTE' * COALESCE(user_options.new_topic_duration_minutes, :default_duration))
|
||||
END, users.created_at, :min_date)
|
||||
END, user_stats.new_since, :min_date)
|
||||
AND dtu1.id = dtu2.id
|
||||
SQL
|
||||
sql = DB.sql_fragment(sql,
|
||||
|
||||
@@ -215,12 +215,13 @@ class TopicTrackingState
|
||||
MessageBus.publish(self.unread_channel_key(user_id), message.as_json, user_ids: [user_id])
|
||||
end
|
||||
|
||||
def self.publish_dismiss_new(user_id, topic_ids: [])
|
||||
def self.publish_dismiss_new(user_id, category_id: nil, tag_id: nil)
|
||||
payload = {}
|
||||
payload[:category_id] = category_id if category_id
|
||||
payload[:tag_id] = tag_id if tag_id
|
||||
message = {
|
||||
message_type: "dismiss_new",
|
||||
payload: {
|
||||
topic_ids: topic_ids
|
||||
}
|
||||
payload: payload
|
||||
}
|
||||
MessageBus.publish(self.unread_channel_key(user_id), message.as_json, user_ids: [user_id])
|
||||
end
|
||||
@@ -230,7 +231,7 @@ class TopicTrackingState
|
||||
WHEN COALESCE(uo.new_topic_duration_minutes, :default_duration) = :always THEN u.created_at
|
||||
WHEN COALESCE(uo.new_topic_duration_minutes, :default_duration) = :last_visit THEN COALESCE(u.previous_visit_at,u.created_at)
|
||||
ELSE (:now::timestamp - INTERVAL '1 MINUTE' * COALESCE(uo.new_topic_duration_minutes, :default_duration))
|
||||
END, u.created_at, :min_date)",
|
||||
END, us.new_since, :min_date)",
|
||||
now: DateTime.now,
|
||||
last_visit: User::NewTopicDuration::LAST_VISIT,
|
||||
always: User::NewTopicDuration::ALWAYS,
|
||||
|
||||
@@ -149,7 +149,7 @@ class UserOption < ActiveRecord::Base
|
||||
else
|
||||
duration.minutes.ago
|
||||
end,
|
||||
user.created_at,
|
||||
user.user_stat.new_since,
|
||||
Time.at(SiteSetting.min_new_topics_time).to_datetime
|
||||
]
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@ class DismissTopics
|
||||
|
||||
def perform!
|
||||
DismissedTopicUser.insert_all(rows) if rows.present?
|
||||
@rows.map { |row| row[:topic_id] }
|
||||
end
|
||||
|
||||
private
|
||||
@@ -18,7 +17,6 @@ class DismissTopics
|
||||
.joins("LEFT JOIN topic_users ON topic_users.topic_id = topics.id AND topic_users.user_id = #{@user.id}")
|
||||
.where("topics.created_at >= ?", since_date)
|
||||
.where("topic_users.id IS NULL")
|
||||
.where("topics.archetype <> ?", Archetype.private_message)
|
||||
.order("topics.created_at DESC")
|
||||
.limit(SiteSetting.max_new_topics).map do |topic|
|
||||
{
|
||||
@@ -40,6 +38,6 @@ class DismissTopics
|
||||
else
|
||||
new_topic_duration_minutes.minutes.ago
|
||||
end
|
||||
[setting_date, @user.created_at, Time.at(SiteSetting.min_new_topics_time).to_datetime].max
|
||||
[setting_date, @user.user_stat.new_since, Time.at(SiteSetting.min_new_topics_time).to_datetime].max
|
||||
end
|
||||
end
|
||||
|
||||
@@ -266,8 +266,6 @@ class UserMerger
|
||||
update_user_id(:draft_sequences, conditions: "x.draft_key = y.draft_key")
|
||||
update_user_id(:drafts, conditions: "x.draft_key = y.draft_key")
|
||||
|
||||
update_user_id(:dismissed_topic_users, conditions: "x.topic_id = y.topic_id")
|
||||
|
||||
EmailLog.where(user_id: @source_user.id).update_all(user_id: @target_user.id)
|
||||
|
||||
GroupHistory.where(acting_user_id: @source_user.id).update_all(acting_user_id: @target_user.id)
|
||||
|
||||
Reference in New Issue
Block a user