# Imported private discussion doesn't appear in the author inbox

**URL:** <https://meta.discourse.org/t/imported-private-discussion-doesnt-appear-in-the-author-inbox/163252>\
**Category:** Migration\
**Tags:** vbulletin5\
**Created:** [September 7, 2020, 1:17pm UTC](https://meta.discourse.org/t/imported-private-discussion-doesnt-appear-in-the-author-inbox/163252 "2020-09-07T13:17:14Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![Canapin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/canapin/32/119591_2.png) [@Canapin](https://meta.discourse.org/u/Canapin)\
**Post date:** [September 7, 2020, 1:17pm UTC](https://meta.discourse.org/t/imported-private-discussion-doesnt-appear-in-the-author-inbox/163252/1 "2020-09-07T13:17:14Z")

</div>

Hi, I’m trying to import private messages from a vBulletin5 database.

It works, but in the author profile the discussion only appears in “sent”, not in “inbox”.

On the other participant profile, the discussion correctly appears in “inbox” as well as in “sent”.

**Author profile:**  
Appears in “sent”

 ![image](https://global.discourse-cdn.com/meta/original/3X/2/a/2aedab68db476eb4b8cb825e18ff96a644e38110.png)

But not in “inbox”

 ![image](https://global.discourse-cdn.com/meta/original/3X/8/d/8d0de842c4ae68a1374e48f8cd121e91090f4837.png)

**Other participant profile:**  
Appears in both:

 ![image](https://global.discourse-cdn.com/meta/original/3X/f/8/f87157b87556c0c8350e795cb9f9c3b342a58c51.png)

 ![image](https://global.discourse-cdn.com/meta/original/3X/e/3/e3b779843cccf94d4b5971cc95a7d569b48e6698.png)

How can I make the discussion appears in the inbox of the author?

My current messy code if necessary

```ruby
  def import_pm
    puts "", "importing topics PMs..."

    pms_count = mysql_query("SELECT COUNT(nodeid) cnt, starter
        FROM #{DB_PREFIX}node
        WHERE (unpublishdate = 0 OR unpublishdate IS NULL)
        AND (approved = 1 AND showapproved = 1)    
          AND starter = 2676436
        AND contenttypeid=#{@pm};"
    ).first["cnt"]

    batches(BATCH_SIZE) do |offset|
      pms = mysql_query <<-SQL
        SELECT pm.nodeid AS pmid, pm.starter, pm.title, pm.parentid AS parentid,pm.open,pm.userid AS postuserid,pm.publishdate AS dateline,
            nv.count views, 1 AS visible, pm.sticky,
            CONVERT(CAST(rawtext AS BINARY)USING utf8) AS raw
        FROM #{DB_PREFIX}node pm
        LEFT JOIN #{DB_PREFIX}nodeview nv ON nv.nodeid=pm.nodeid
        LEFT JOIN #{DB_PREFIX}text txt ON txt.nodeid=pm.nodeid
        WHERE
          pm.contenttypeid = #{@pm}
          AND (pm.unpublishdate = 0 OR pm.unpublishdate IS NULL)
          AND pm.approved = 1 AND pm.showapproved = 1
          AND pm.starter = 2676436
        ORDER BY pm.nodeid
          LIMIT #{BATCH_SIZE}
          OFFSET #{offset}
      SQL

      break if pms.size < 1

      create_posts(pms, total: pms_count, offset: 0) do |pm|
        p = {}

        p[:id] = "pm-#{pm['pmid']}"
        p[:user_id] = user_id_from_imported_user_id(pm['postuserid']) || Discourse::SYSTEM_USER_ID
        p[:raw] = preprocess_post_raw(pm['raw']) rescue nil
        p[:created_at] = parse_timestamp(pm["dateline"]),

        topic_id = nil

        next if p[:raw].blank?

        # if first post
        if pm['parentid'] == 8 
          #next unless post = topic_lookup_from_imported_post_id("pm-#{pm["pmid"]}")

          target_usernames = []
          target_userids = []
          # get user list
          userlist = mysql_query("select distinct userid from sentto where nodeid = #{pm["starter"]}")
          userlist.each do |user|
            userid = user_id_from_imported_user_id(user["userid"]) || Discourse::SYSTEM_USER_ID;
            target_userids << userid || Discourse::SYSTEM_USER_ID
            target_usernames << User.find_by(id: userid).try(:username) || "system"
          end

          participants = target_userids
          begin
            participants.sort!
          rescue
            puts "one of the participant's id is nil -- #{participants.inspect}"
          end

          p[:title] = @htmlentities.decode(pm['title']).strip[0...255]
          p[:archetype] = Archetype.private_message
          p[:target_usernames] = target_usernames.join(',')

          if p[:target_usernames].size < 1 # pm with yourself?
            # skip = true
            p[:target_usernames] = "system"
            puts "pm-#{pm['nodeid']} has no target"
          end
        # if not first post
        else
          next unless topic = topic_lookup_from_imported_post_id("pm-#{pm["starter"]}")
          p[:topic_id] = topic[:topic_id]

        end
        puts "post : #{p}\n"
        p
      end
    end
    exit
  end

```

---

_[View the full topic](https://meta.discourse.org/t/imported-private-discussion-doesnt-appear-in-the-author-inbox/163252)._
