aboutsummaryrefslogtreecommitdiffstats
path: root/include/message.php
diff options
context:
space:
mode:
authorfriendica <info@friendica.com>2013-01-24 23:45:15 -0800
committerfriendica <info@friendica.com>2013-01-24 23:45:15 -0800
commit851e436d04fa6dd975666369e8d746036b700d5d (patch)
treea0abc2dc0c6d94bf9d962795f232aa0b74447965 /include/message.php
parent769456305bf8ce5e2152da5e9b80fe3894cfcddc (diff)
downloadvolse-hubzilla-851e436d04fa6dd975666369e8d746036b700d5d.tar.gz
volse-hubzilla-851e436d04fa6dd975666369e8d746036b700d5d.tar.bz2
volse-hubzilla-851e436d04fa6dd975666369e8d746036b700d5d.zip
make all private message functionality api-able
Diffstat (limited to 'include/message.php')
-rw-r--r--include/message.php96
1 files changed, 95 insertions, 1 deletions
diff --git a/include/message.php b/include/message.php
index 71d0c13bd..5e7b49e35 100644
--- a/include/message.php
+++ b/include/message.php
@@ -44,7 +44,6 @@ function send_message($uid = 0, $recipient='', $body='', $subject='', $replyto='
}
-
$r = q("INSERT INTO `mail` ( account_id, channel_id, from_xchan, to_xchan, title, body, uri, parent_uri, created )
VALUES ( %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s' )",
intval($channel['channel_account_id']),
@@ -155,4 +154,99 @@ function private_messages_list($uid, $mailbox = '', $order = 'desc', $start = 0,
$r[$k]['seen'] = (($rr['mail_flags'] & MAIL_SEEN) ? 1 : 0);
}
return $r;
+}
+
+
+
+function private_messages_fetch_message($channel_id, $messageitem_id, $updateseen = false) {
+
+ $messages = q("select * from mail where id = %d and channel_id = %d order by created asc",
+ dbesc($messageitem_id),
+ intval($channel_id)
+ );
+
+ if(! $messages)
+ return array();
+
+ $chans = array();
+ foreach($messages as $rr) {
+ $s = "'" . dbesc(trim($rr['from_xchan'])) . "'";
+ if(! in_array($s,$chans))
+ $chans[] = $s;
+ $s = "'" . dbesc(trim($rr['to_xchan'])) . "'";
+ if(! in_array($s,$chans))
+ $chans[] = $s;
+ }
+
+ $c = q("select * from xchan where xchan_hash in (" . implode(',',$chans) . ")");
+
+ foreach($messages as $k => $message) {
+ $messages[$k]['from'] = find_xchan_in_array($message['from_xchan'],$c);
+ $messages[$k]['to'] = find_xchan_in_array($message['to_xchan'],$c);
+ }
+
+ if($updateseen) {
+ $r = q("UPDATE `mail` SET mail_flags = (mail_flags ^ %d) where not (mail_flags & %d) and id = %d AND channel_id = %d",
+ intval(MAIL_SEEN),
+ intval(MAIL_SEEN),
+ dbesc($messageitem_id),
+ intval($channel_id)
+ );
+ }
+
+ return $messages;
+
+}
+
+
+function private_messages_fetch_conversation($channel_id, $messageitem_id, $updateseen = false) {
+
+ // find the parent_uri of the message being requested
+
+ $r = q("SELECT parent_uri from mail WHERE channel_id = %d and id = %d limit 1",
+ intval($channel_id),
+ intval($messageitem_id)
+ );
+
+ if(! $r)
+ return array();
+
+ $messages = q("select * from mail where parent_uri = '%s' and channel_id = %d order by created asc",
+ dbesc($r[0]['parent_uri']),
+ intval($channel_id)
+ );
+
+ if(! $messages)
+ return array();
+
+ $chans = array();
+ foreach($messages as $rr) {
+ $s = "'" . dbesc(trim($rr['from_xchan'])) . "'";
+ if(! in_array($s,$chans))
+ $chans[] = $s;
+ $s = "'" . dbesc(trim($rr['to_xchan'])) . "'";
+ if(! in_array($s,$chans))
+ $chans[] = $s;
+ }
+
+
+ $c = q("select * from xchan where xchan_hash in (" . implode(',',$chans) . ")");
+
+ foreach($messages as $k => $message) {
+ $messages[$k]['from'] = find_xchan_in_array($message['from_xchan'],$c);
+ $messages[$k]['to'] = find_xchan_in_array($message['to_xchan'],$c);
+ }
+
+
+ if($updateseen) {
+ $r = q("UPDATE `mail` SET mail_flags = (mail_flags ^ %d) where not (mail_flags & %d) and parent_uri = '%s' AND channel_id = %d",
+ intval(MAIL_SEEN),
+ intval(MAIL_SEEN),
+ dbesc($r[0]['parent_uri']),
+ intval($channel_id)
+ );
+ }
+
+ return $messages;
+
} \ No newline at end of file