aboutsummaryrefslogtreecommitdiffstats
path: root/include/message.php
diff options
context:
space:
mode:
authorfriendica <info@friendica.com>2013-01-24 18:51:02 -0800
committerfriendica <info@friendica.com>2013-01-24 18:51:02 -0800
commit33b22338dc7e8e3f08d8b20e94a9bce488d1f308 (patch)
tree7fe01b889a997cf22a3308e162d728b66d6487b6 /include/message.php
parentcb5a20ba2cbad131267542ff55b394a9763b4c2c (diff)
downloadvolse-hubzilla-33b22338dc7e8e3f08d8b20e94a9bce488d1f308.tar.gz
volse-hubzilla-33b22338dc7e8e3f08d8b20e94a9bce488d1f308.tar.bz2
volse-hubzilla-33b22338dc7e8e3f08d8b20e94a9bce488d1f308.zip
turn private_messages_list into backend functionality and separate it from the controller
Diffstat (limited to 'include/message.php')
-rw-r--r--include/message.php46
1 files changed, 46 insertions, 0 deletions
diff --git a/include/message.php b/include/message.php
index fd9698381..71d0c13bd 100644
--- a/include/message.php
+++ b/include/message.php
@@ -109,4 +109,50 @@ function send_message($uid = 0, $recipient='', $body='', $subject='', $replyto='
}
+function private_messages_list($uid, $mailbox = '', $order = 'desc', $start = 0, $numitems = 0) {
+ $where = '';
+ $limit = '';
+
+ if($numitems)
+ $limit = " LIMIT " . intval($start) . ", " . intval($numitems);
+
+ if($mailbox !== '') {
+ $x = q("select channel_hash from channel where channel_id = %d limit 1",
+ intval($uid)
+ );
+ if(! $x)
+ return array();
+ if($mailbox === 'inbox')
+ $where = " and sender_xchan != '" . dbesc($x[0]['channel_hash']) . "' ";
+ elseif($mailbox === 'outbox')
+ $where = " and sender_xchan = '" . dbesc($x[0]['channel_hash']) . "' ";
+ }
+
+
+ $r = q("SELECT * from mail WHERE channel_id = %d $where order by created $order $limit",
+ intval(local_user())
+ );
+ if(! $r) {
+ return array();
+ }
+
+ $chans = array();
+ foreach($r 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($r as $k => $rr) {
+ $r[$k]['from'] = find_xchan_in_array($rr['from_xchan'],$c);
+ $r[$k]['to'] = find_xchan_in_array($rr['to_xchan'],$c);
+ $r[$k]['seen'] = (($rr['mail_flags'] & MAIL_SEEN) ? 1 : 0);
+ }
+ return $r;
+} \ No newline at end of file