+ function api_in_reply_to($item) {
+ $in_reply_to = array();
+
+ $in_reply_to['status_id'] = NULL;
+ $in_reply_to['user_id'] = NULL;
+ $in_reply_to['status_id_str'] = NULL;
+ $in_reply_to['user_id_str'] = NULL;
+ $in_reply_to['screen_name'] = NULL;
+
+ if (($item['thr-parent'] != $item['uri']) AND (intval($item['parent']) != intval($item['id']))) {
+ $r = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `uri` = '%s' LIMIT 1",
+ intval($item['uid']),
+ dbesc($item['thr-parent']));
+
+ if (dbm::is_result($r)) {
+ $in_reply_to['status_id'] = intval($r[0]['id']);
+ } else {
+ $in_reply_to['status_id'] = intval($item['parent']);
+ }
+
+ $in_reply_to['status_id_str'] = (string) intval($in_reply_to['status_id']);
+
+ $r = q("SELECT `contact`.`nick`, `contact`.`name`, `contact`.`id`, `contact`.`url` FROM item
+ STRAIGHT_JOIN `contact` ON `contact`.`id` = `item`.`author-id`
+ WHERE `item`.`id` = %d LIMIT 1",
+ intval($in_reply_to['status_id'])
+ );
+
+ if (dbm::is_result($r)) {
+ if ($r[0]['nick'] == "") {
+ $r[0]['nick'] = api_get_nick($r[0]["url"]);
+ }
+
+ $in_reply_to['screen_name'] = (($r[0]['nick']) ? $r[0]['nick'] : $r[0]['name']);
+ $in_reply_to['user_id'] = intval($r[0]['id']);
+ $in_reply_to['user_id_str'] = (string) intval($r[0]['id']);
+ }
+
+ // There seems to be situation, where both fields are identical:
+ // https://github.com/friendica/friendica/issues/1010
+ // This is a bugfix for that.
+ if (intval($in_reply_to['status_id']) == intval($item['id'])) {
+ logger('this message should never appear: id: '.$item['id'].' similar to reply-to: '.$in_reply_to['status_id'], LOGGER_DEBUG);
+ $in_reply_to['status_id'] = NULL;
+ $in_reply_to['user_id'] = NULL;
+ $in_reply_to['status_id_str'] = NULL;
+ $in_reply_to['user_id_str'] = NULL;
+ $in_reply_to['screen_name'] = NULL;
+ }
+ }
+
+ return $in_reply_to;
+ }
+