aboutsummaryrefslogtreecommitdiffstats
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
parent769456305bf8ce5e2152da5e9b80fe3894cfcddc (diff)
downloadvolse-hubzilla-851e436d04fa6dd975666369e8d746036b700d5d.tar.gz
volse-hubzilla-851e436d04fa6dd975666369e8d746036b700d5d.tar.bz2
volse-hubzilla-851e436d04fa6dd975666369e8d746036b700d5d.zip
make all private message functionality api-able
-rw-r--r--include/message.php96
-rw-r--r--mod/message.php80
2 files changed, 107 insertions, 69 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
diff --git a/mod/message.php b/mod/message.php
index 3fe7deca6..b0b4c3eff 100644
--- a/mod/message.php
+++ b/mod/message.php
@@ -365,47 +365,13 @@ function message_content(&$a) {
if( local_user() && feature_enabled(local_user(),'richtext') )
$plaintext = false;
- $r = q("SELECT parent_uri from mail WHERE channel_id = %d and id = %d limit 1",
- intval(local_user()),
- intval(argv(1))
- );
-
- if(! $r) {
- info( t('Message not found.') . EOL);
- return $o;
- }
-
- $messages = q("select * from mail where parent_uri = '%s' and channel_id = %d order by created asc",
- dbesc($r[0]['parent_uri']),
- intval(local_user())
- );
+ $messages = private_messages_fetch_conversation(local_user(), argv(1), true);
if(! $messages) {
info( t('Message not found.') . EOL);
return $o;
}
- $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) . ")");
-
- $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(local_user())
- );
-
require_once("include/bbcode.php");
$tpl = get_markup_template('msg-header.tpl');
@@ -423,39 +389,22 @@ function message_content(&$a) {
$unknown = false;
foreach($messages as $message) {
- $message['from'] = find_xchan_in_array($message['from_xchan'],$c);
- $message['to'] = find_xchan_in_array($message['to_xchan'],$c);
-
-
-logger('message: ' . print_r($message,true));
+// FIXME
// $extracted = item_extract_images($message['body']);
// if($extracted['images'])
// $message['body'] = item_redir_and_replace_images($extracted['body'], $extracted['images'], $message['contact-id']);
- if($a->get_template_engine() === 'internal') {
- $from_name_e = template_escape($message['from']['xchan_name']);
- $subject_e = template_escape($message['title']);
- $body_e = template_escape(smilies(bbcode($message['body'])));
- $to_name_e = template_escape($message['to']['xchan_name']);
- }
- else {
- $from_name_e = $message['from']['xchan_name'];
- $subject_e = $message['title'];
- $body_e = smilies(bbcode($message['body']));
- $to_name_e = $message['to']['xchan_name'];
- }
-
$mails[] = array(
'id' => $message['id'],
- 'from_name' => $from_name_e,
- 'from_url' => z_root() . '/chanview/?f=&hash=' . $message['from_xchan'],
+ 'from_name' => $message['from']['xchan_name'],
+ 'from_url' => chanlink_hash($message['from_xchan']),
'from_photo' => $message['from']['xchan_photo_m'],
- 'to_name' => $to_name_e,
- 'to_url' => z_root() . '/chanview/?f=&hash=' . $message['to_xchan'],
+ 'to_name' => $message['to']['xchan_name'],
+ 'to_url' => chanlink_hash($message['to_xchan']),
'to_photo' => $message['to']['xchan_photo_m'],
- 'subject' => $subject_e,
- 'body' => $body_e,
+ 'subject' => $message['title'],
+ 'body' => smilies(bbcode($message['body'])),
'delete' => t('Delete message'),
'date' => datetime_convert('UTC',date_default_timezone_get(),$message['created'],'D, d M Y - g:i A'),
);
@@ -464,20 +413,15 @@ logger('message: ' . print_r($message,true));
}
- logger('mails: ' . print_r($mails,true));
+ logger('mails: ' . print_r($mails,true), LOGGER_DATA);
$recp = (($message['from_xchan'] === $channel['channel_hash']) ? 'to' : 'from');
+// FIXME - move this HTML to template
+
$select = $message[$recp]['xchan_name'] . '<input type="hidden" name="messageto" value="' . $message[$recp]['xchan_hash'] . '" />';
$parent = '<input type="hidden" name="replyto" value="' . $message['parent_uri'] . '" />';
- if($a->get_template_engine() === 'internal') {
- $subjtxt_e = template_escape($message['title']);
- }
- else {
- $subjtxt_e = $message['title'];
- }
-
$tpl = get_markup_template('mail_display.tpl');
$o = replace_macros($tpl, array(
'$thread_id' => $a->argv[1],
@@ -493,7 +437,7 @@ logger('message: ' . print_r($message,true));
'$to' => t('To:'),
'$showinputs' => '',
'$subject' => t('Subject:'),
- '$subjtxt' => $subjtxt_e,
+ '$subjtxt' => $message['title'],
'$readonly' => ' readonly="readonly" style="background: #BBBBBB;" ',
'$yourmessage' => t('Your message:'),
'$text' => '',