+
+ private function import_conversation($importer, $msg, $data) {
+ $guid = notags(unxmlify($data->guid));
+ $subject = notags(unxmlify($data->subject));
+ $created_at = datetime_convert("UTC", "UTC", notags(unxmlify($data->created_at)));
+ $author = notags(unxmlify($data->author));
+ $participants = notags(unxmlify($data->participants));
+
+ $messages = $data->message;
+
+ if (!count($messages)) {
+ logger("empty conversation");
+ return false;
+ }
+
+ $contact = self::get_allowed_contact_by_handle($importer, $msg["author"], true);
+ if (!$contact)
+ return false;
+
+ $conversation = null;
+
+ $c = q("SELECT * FROM `conv` WHERE `uid` = %d AND `guid` = '%s' LIMIT 1",
+ intval($importer["uid"]),
+ dbesc($guid)
+ );
+ if($c)
+ $conversation = $c[0];
+ else {
+ $r = q("INSERT INTO `conv` (`uid`, `guid`, `creator`, `created`, `updated`, `subject`, `recips`)
+ VALUES (%d, '%s', '%s', '%s', '%s', '%s', '%s')",
+ intval($importer["uid"]),
+ dbesc($guid),
+ dbesc($author),
+ dbesc(datetime_convert("UTC", "UTC", $created_at)),
+ dbesc(datetime_convert()),
+ dbesc($subject),
+ dbesc($participants)
+ );
+ if($r)
+ $c = q("SELECT * FROM `conv` WHERE `uid` = %d AND `guid` = '%s' LIMIT 1",
+ intval($importer["uid"]),
+ dbesc($guid)
+ );
+
+ if($c)
+ $conversation = $c[0];
+ }
+ if (!$conversation) {
+ logger("unable to create conversation.");
+ return;
+ }
+
+ foreach($messages as $mesg)
+ self::import_conversation_message($importer, $contact, $data, $msg, $mesg);
+