v0.31.3 Significant update of private message code - field population, threading of replies, visibility to sender

This commit is contained in:
David Sainty 2024-07-13 01:10:44 +10:00
parent 8e0466ac8f
commit 78f779fb76

View File

@ -1,5 +1,5 @@
# gossamer threads migration-import code # gossamer threads migration-import code
# v0.31.2 # v0.31.3
require 'mysql2' require 'mysql2'
require 'open-uri' require 'open-uri'
@ -1229,11 +1229,15 @@ class GossamerForumsImporter < ImportScripts::Base
# .where("title = ? OR title = ?", sanitized_title, "Re: #{sanitized_title}") # .where("title = ? OR title = ?", sanitized_title, "Re: #{sanitized_title}")
# .where(topic_custom_fields: { name: 'original_gossamer_msg_id' }) # .where(topic_custom_fields: { name: 'original_gossamer_msg_id' })
# .first # .first
topic = Topic.where(archetype: Archetype.private_message) 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("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("topic_allowed_users.user_id IN (?)", [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) .group("topics.id")
.having("COUNT(topic_allowed_users.user_id) = 2")
.first .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? if topic.nil?
puts "IMPORTING new message topic sanitized: #{sanitized_title} user_id #{from_user_id} to_user_id #{to_user_id}" puts "IMPORTING new message topic sanitized: #{sanitized_title} user_id #{from_user_id} to_user_id #{to_user_id}"