From 78f779fb76d78535ccf8985e7f11015a3b9992bc Mon Sep 17 00:00:00 2001 From: saint Date: Sat, 13 Jul 2024 01:10:44 +1000 Subject: [PATCH] v0.31.3 Significant update of private message code - field population, threading of replies, visibility to sender --- gossamer_forums.rb | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/gossamer_forums.rb b/gossamer_forums.rb index eec623d..8db1c07 100644 --- a/gossamer_forums.rb +++ b/gossamer_forums.rb @@ -1,5 +1,5 @@ # gossamer threads migration-import code -# v0.31.2 +# v0.31.3 require 'mysql2' require 'open-uri' @@ -1229,11 +1229,15 @@ class GossamerForumsImporter < ImportScripts::Base # .where("title = ? OR title = ?", sanitized_title, "Re: #{sanitized_title}") # .where(topic_custom_fields: { name: 'original_gossamer_msg_id' }) # .first - topic = Topic.where(archetype: Archetype.private_message) - .where("topics.title = ? OR topics.title = ? OR topics.title = ?", sanitized_title, "Re: #{sanitized_title}", "Re: #{sanitized_title.strip}") - .where("topics.topic_allowed_users.user_id = ? AND topics.topic_allowed_users.user_id = ?", from_user_id, to_user_id) -# .where("((topics.user_id = ? AND topics.topic_allowed_users.user_id = ?) OR (topics.user_id = ? AND topics.topic_allowed_users.user_id = ?))", from_user_id, to_user_id, to_user_id, from_user_id) - .first + topic = Topic.joins(:topic_allowed_users) + .where(archetype: Archetype.private_message) + .where("topics.title = ? OR topics.title = ? OR topics.title = ?", sanitized_title, "Re: #{sanitized_title}", "Re: #{sanitized_title.strip}") + .where("topic_allowed_users.user_id IN (?)", [from_user_id, to_user_id]) + .group("topics.id") + .having("COUNT(topic_allowed_users.user_id) = 2") + .first +# .where("topics.topic_allowed_users.user_id = ? AND topics.topic_allowed_users.user_id = ?", from_user_id, to_user_id) +# .where("((topics.user_id = ? AND topics.topic_allowed_users.user_id = ?) OR (topics.user_id = ? AND topics.topic_allowed_users.user_id = ?))", from_user_id, to_user_id, to_user_id, from_user_id) if topic.nil? puts "IMPORTING new message topic sanitized: #{sanitized_title} user_id #{from_user_id} to_user_id #{to_user_id}"