# דיון פרטי מיובא לא מופיע בתיבת הדואר הנכנס של המחבר

**URL:** https://meta.discourse.org/t/imported-private-discussion-doesnt-appear-in-the-author-inbox/163252
**Category:** Migration
**Tags:** vbulletin5
**Created:** [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:** 5
**Page:** 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: [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

```

---

<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: [7 בספטמבר,‏ 2020,‏ 8:16pm UTC](https://meta.discourse.org/t/imported-private-discussion-doesnt-appear-in-the-author-inbox/163252/2 "2020-09-07T20:16:19Z")

</div>

From [data explorer](https://meta.discourse.org/t/32566?silent=true), I noticed that the **participant\_count** value is wrong:  
 ![image](https://global.discourse-cdn.com/meta/original/3X/3/d/3d1ef527898b5b2bf938d6857803bd31c15318f6.png)

It’s written 1, but there are two people in the conversation.  
If I update the topic’s field **participant\_count** to 2 like this:

```ruby
Topic.find_by(id: 218613).update(participant_count: 2)

```

the topic now appears in the author’s inbox:

 ![image](https://global.discourse-cdn.com/meta/original/3X/5/1/51e437d1861fb68a7684a76e04a76b98d2e0843b.png)

I didn’t notice this behavior by updating other fields like **reply\_count** for example, so it seems specific to **participant\_count** and maybe other fields.

In my import script, I tried adding this:

```ruby
p[:participant_count] = target_usernames.count

```

But it didn’t work, I guess we can’t set this field in the importers’ methods.

So I’m a bit stuck here. I’d like my users to have all their PMs with replies in their inbox, not only those that they didn’t start themselves.

Any idea?

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [9 בספטמבר,‏ 2020,‏ 12:47am UTC](https://meta.discourse.org/t/imported-private-discussion-doesnt-appear-in-the-author-inbox/163252/3 "2020-09-09T00:47:43Z")

</div>

Any thoughts on this @kris.kotlarek?

---

<div class="post-metadata">

### Author: ![kris.kotlarek](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kris.kotlarek/32/176919_2.png) [@kris.kotlarek](https://meta.discourse.org/u/kris.kotlarek)
#### Post date: [9 בספטמבר,‏ 2020,‏ 5:13am UTC](https://meta.discourse.org/t/imported-private-discussion-doesnt-appear-in-the-author-inbox/163252/6 "2020-09-09T05:13:00Z")

</div>

Thank you for mentioning that bug. I checked it myself and you are right - when `participant_count` is incorrect, then message is not visible in message’s author inbox.

Also, you are right that even if you explicitly add that param to create\_posts - it is not set correctly.

This is because TopicCreate has explicit list of allowed params:

> <https://github.com/discourse/discourse/blob/main/lib/topic_creator.rb#L91:L131>

Today I will create a PR to Discourse to accept that attribute in import mode.

In the meantime, to not wait for latest version of Discourse, you can run at the very end of your script

`Topic.private_messages.map(&:update_statistics)` - this should correct all numbers

---

<div class="post-metadata">

### Author: ![kris.kotlarek](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kris.kotlarek/32/176919_2.png) [@kris.kotlarek](https://meta.discourse.org/u/kris.kotlarek)
#### Post date: [9 בספטמבר,‏ 2020,‏ 6:07am UTC](https://meta.discourse.org/t/imported-private-discussion-doesnt-appear-in-the-author-inbox/163252/7 "2020-09-09T06:07:35Z")

</div>

PR is ready - [FIX: topic\_creator accepts participant\_count in import mode by KrisKotlarek · Pull Request #10632 · discourse/discourse · GitHub](https://github.com/discourse/discourse/pull/10632)

Once merged and deployed you will be able to use it like:

```ruby
create_posts(pms, total: pms_count, offset: 0) do |pm|
...
  p[:topic_opts][:participant_count] = target_usernames.count 
...
end

```

It has to be under `[:topic_opts]` because `create_posts` method is evaluating `post_creator` which triggers `topic_creator`

> <https://github.com/discourse/discourse/blob/main/lib/post_creator.rb#L56>
