DB: do the mail table again. Mail almost working onsite, still needs to zot though

This commit is contained in:
friendica 2012-12-04 18:24:46 -08:00
parent 707397580c
commit e17ba14696
12 changed files with 173 additions and 284 deletions

View File

@ -194,6 +194,13 @@ define ( 'ABOOK_FLAG_PENDING' , 0x0010);
define ( 'ABOOK_FLAG_SELF' , 0x0080); define ( 'ABOOK_FLAG_SELF' , 0x0080);
define ( 'MAIL_DELETED', 0x0001);
define ( 'MAIL_REPLIED', 0x0002);
define ( 'MAIL_ISREPLY', 0x0004);
define ( 'MAIL_SEEN', 0x0008);
/** /**
* Maximum number of "people who like (or don't like) this" that we will list by name * Maximum number of "people who like (or don't like) this" that we will list by name
*/ */

View File

@ -1,11 +1,10 @@
<?php <?php
// send a private message
// send a private message
function send_message($uid = 0, $recipient='', $body='', $subject='', $replyto=''){
function send_message($recipient=0, $body='', $subject='', $replyto=''){
$a = get_app(); $a = get_app();
@ -14,107 +13,60 @@ function send_message($recipient=0, $body='', $subject='', $replyto=''){
if(! strlen($subject)) if(! strlen($subject))
$subject = t('[no subject]'); $subject = t('[no subject]');
$me = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1",
intval(local_user())
);
$contact = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
intval($recipient),
intval(local_user())
);
if(! (count($me) && (count($contact)))) { if($uid) {
return -2; $r = q("select * from channel where channel_id = %d limit 1",
intval($uid)
);
if($r)
$channel = $r[0];
}
else {
$channel = get_app()->get_channel();
} }
$hash = random_string();
$uri = 'urn:X-dfrn:' . $a->get_baseurl() . ':' . local_user() . ':' . $hash ;
$convid = 0; do {
$reply = false; $dups = false;
$hash = random_string();
// look for any existing conversation structure $uri = $hash . '@' . get_app()->get_hostname();
if(strlen($replyto)) { $r = q("SELECT `id` FROM mail WHERE `uri` = '%s' LIMIT 1",
$reply = true; dbesc($uri));
$r = q("select convid from mail where uid = %d and ( uri = '%s' or `parent_uri` = '%s' ) limit 1",
intval(local_user()),
dbesc($replyto),
dbesc($replyto)
);
if(count($r)) if(count($r))
$convid = $r[0]['convid']; $dups = true;
} } while($dups == true);
if(! $convid) {
// create a new conversation
$conv_guid = get_guid();
$recip_host = substr($contact[0]['url'],strpos($contact[0]['url'],'://')+3);
$recip_host = substr($recip_host,0,strpos($recip_host,'/'));
$recip_handle = (($contact[0]['addr']) ? $contact[0]['addr'] : $contact[0]['nick'] . '@' . $recip_host);
$sender_handle = $a->user['nickname'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(),'://') + 3);
$handles = $recip_handle . ';' . $sender_handle;
$r = q("insert into conv (uid,guid,creator,created,updated,subject,recips) values(%d, '%s', '%s', '%s', '%s', '%s', '%s') ",
intval(local_user()),
dbesc($conv_guid),
dbesc($sender_handle),
dbesc(datetime_convert()),
dbesc(datetime_convert()),
dbesc($subject),
dbesc($handles)
);
$r = q("select * from conv where guid = '%s' and uid = %d limit 1",
dbesc($conv_guid),
intval(local_user())
);
if(count($r))
$convid = $r[0]['id'];
}
if(! $convid) {
logger('send message: conversation not found.');
return -4;
}
if(! strlen($replyto)) { if(! strlen($replyto)) {
$replyto = $uri; $replyto = $uri;
} }
$r = q("INSERT INTO `mail` ( `uid`, `guid`, `convid`, `from-name`, `from-photo`, `from-url`, $r = q("INSERT INTO `mail` ( account_id, channel_id, from_xchan, to_xchan, title, body, uri, parent_uri, created )
`contact-id`, `title`, `body`, `seen`, `reply`, `replied`, `uri`, `parent_uri`, `created`) VALUES ( %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s' )",
VALUES ( %d, '%s', %d, '%s', '%s', '%s', %d, '%s', '%s', %d, %d, %d, '%s', '%s', '%s' )", intval($channel['channel_account_id']),
intval(local_user()), intval(local_user()),
dbesc(get_guid()), dbesc($channel['channel_hash']),
intval($convid), dbesc($recipient),
dbesc($me[0]['name']),
dbesc($me[0]['thumb']),
dbesc($me[0]['url']),
intval($recipient),
dbesc($subject), dbesc($subject),
dbesc($body), dbesc($body),
1,
intval($reply),
0,
dbesc($uri), dbesc($uri),
dbesc($replyto), dbesc($replyto),
datetime_convert() dbesc(datetime_convert())
); );
$r = q("SELECT * FROM `mail` WHERE `uri` = '%s' and `uid` = %d LIMIT 1", $r = q("SELECT * FROM `mail` WHERE uri = '%s' and channel_id = %d LIMIT 1",
dbesc($uri), dbesc($uri),
intval(local_user()) intval(local_user())
); );
if(count($r)) if(count($r))
$post_id = $r[0]['id']; $post_id = $r[0]['id'];
/** /**
* *
* When a photo was uploaded into the message using the (profile wall) ajax * When a photo was uploaded into the message using the (profile wall) ajax
@ -158,85 +110,3 @@ function send_message($recipient=0, $body='', $subject='', $replyto=''){
} }
function send_wallmessage($recipient='', $body='', $subject='', $replyto=''){
$a = get_app();
if(! $recipient) return -1;
if(! strlen($subject))
$subject = t('[no subject]');
$hash = random_string();
$uri = 'urn:X-dfrn:' . $a->get_baseurl() . ':' . local_user() . ':' . $hash ;
$convid = 0;
$reply = false;
require_once('include/Scrape.php');
$me = probe_url($replyto);
if(! $me['name'])
return -2;
$conv_guid = get_guid();
$recip_handle = $recipient['nickname'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(),'://') + 3);
$sender_nick = basename($replyto);
$sender_host = substr($replyto,strpos($replyto,'://')+3);
$sender_host = substr($sender_host,0,strpos($sender_host,'/'));
$sender_handle = $sender_nick . '@' . $sender_host;
$handles = $recip_handle . ';' . $sender_handle;
$r = q("insert into conv (uid,guid,creator,created,updated,subject,recips) values(%d, '%s', '%s', '%s', '%s', '%s', '%s') ",
intval(local_user()),
dbesc($conv_guid),
dbesc($sender_handle),
dbesc(datetime_convert()),
dbesc(datetime_convert()),
dbesc($subject),
dbesc($handles)
);
$r = q("select * from conv where guid = '%s' and uid = %d limit 1",
dbesc($conv_guid),
intval($recipient['uid'])
);
if(count($r))
$convid = $r[0]['id'];
if(! $convid) {
logger('send message: conversation not found.');
return -4;
}
$r = q("INSERT INTO `mail` ( `uid`, `guid`, `convid`, `from-name`, `from-photo`, `from-url`,
`contact-id`, `title`, `body`, `seen`, `reply`, `replied`, `uri`, `parent_uri`, `created`, `unknown`)
VALUES ( %d, '%s', %d, '%s', '%s', '%s', %d, '%s', '%s', %d, %d, %d, '%s', '%s', '%s', %d )",
intval($recipient['uid']),
dbesc(get_guid()),
intval($convid),
dbesc($me['name']),
dbesc($me['photo']),
dbesc($me['url']),
0,
dbesc($subject),
dbesc($body),
0,
0,
0,
dbesc($uri),
dbesc($replyto),
datetime_convert(),
1
);
return 0;
}

View File

@ -23,7 +23,7 @@ function nav(&$a) {
minChars: 2, minChars: 2,
width: 250, width: 250,
}); });
a.setOptions({ params: { type: 'x' }}); a.setOptions({ params: { autoSubmit: true, type: 'x' }});
}); });

View File

@ -594,7 +594,8 @@ CREATE TABLE IF NOT EXISTS `item_id` (
CREATE TABLE IF NOT EXISTS `mail` ( CREATE TABLE IF NOT EXISTS `mail` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT, `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`mail_flags` int(10) unsigned NOT NULL DEFAULT '0', `mail_flags` int(10) unsigned NOT NULL DEFAULT '0',
`author_xchan` char(255) NOT NULL DEFAULT '', `from_xchan` char(255) NOT NULL DEFAULT '',
`to_xchan` char(255) NOT NULL DEFAULT '',
`account_id` int(10) unsigned NOT NULL DEFAULT '0', `account_id` int(10) unsigned NOT NULL DEFAULT '0',
`channel_id` int(10) unsigned NOT NULL, `channel_id` int(10) unsigned NOT NULL,
`title` char(255) NOT NULL, `title` char(255) NOT NULL,
@ -606,11 +607,12 @@ CREATE TABLE IF NOT EXISTS `mail` (
KEY `uri` (`uri`), KEY `uri` (`uri`),
KEY `created` (`created`), KEY `created` (`created`),
KEY `mail_flags` (`mail_flags`), KEY `mail_flags` (`mail_flags`),
KEY `author_xchan` (`author_xchan`),
KEY `account_id` (`account_id`), KEY `account_id` (`account_id`),
KEY `channel_id` (`channel_id`), KEY `channel_id` (`channel_id`),
KEY `parent_uri` (`parent_uri`) KEY `parent_uri` (`parent_uri`),
) ENGINE=MyISAM DEFAULT CHARSET=utf8; KEY `from_xchan` (`from_xchan`),
KEY `to_xchan` (`to_xchan`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `manage` ( CREATE TABLE IF NOT EXISTS `manage` (
`id` int(11) NOT NULL AUTO_INCREMENT, `id` int(11) NOT NULL AUTO_INCREMENT,

View File

@ -167,10 +167,10 @@
default: default:
return; return;
} }
if(e.keyCode != 13) { // if(e.keyCode != 13) {
e.stopImmediatePropagation(); e.stopImmediatePropagation();
e.preventDefault(); e.preventDefault();
} //}
}, },
onKeyUp: function(e) { onKeyUp: function(e) {

View File

@ -127,15 +127,11 @@ function acl_init(&$a){
); );
} }
elseif($type == 'm') { elseif($type == 'm') {
$r = q("SELECT `id`, `name`, `nick`, `micro`, `network`, `url`, `attag` FROM `contact` $r = q("SELECT xchan_hash as id, xchan_name as name, xchan_photo_s as micro, xchan_url as url from xchan
WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 AND `pending` = 0 AND `archive` = 0 where 1
AND `network` IN ('%s','%s','%s') $sql_extra3
$sql_extra2 ORDER BY `xchan_name` ASC ",
ORDER BY `name` ASC ", intval(local_user())
intval(local_user()),
dbesc(NETWORK_DFRN),
dbesc(NETWORK_ZOT),
dbesc(NETWORK_DIASPORA)
); );
} }
elseif($type == 'a') { elseif($type == 'a') {
@ -170,7 +166,7 @@ function acl_init(&$a){
$x['photos'][] = $g['micro']; $x['photos'][] = $g['micro'];
$x['links'][] = $g['url']; $x['links'][] = $g['url'];
$x['suggestions'][] = (($type === 'x') ? '@' : '') . $g['name']; $x['suggestions'][] = (($type === 'x') ? '@' : '') . $g['name'];
$x['data'][] = intval($g['id']); $x['data'][] = $g['id'];
} }
} }
echo json_encode($x); echo json_encode($x);

View File

@ -8,7 +8,7 @@ function message_init(&$a) {
$new = array( $new = array(
'label' => t('New Message'), 'label' => t('New Message'),
'url' => $a->get_baseurl(true) . '/message/new', 'url' => $a->get_baseurl(true) . '/message/new',
'sel'=> ($a->argv[1] == 'new'), 'sel'=> (argv(1) == 'new'),
); );
$tpl = get_markup_template('message_side.tpl'); $tpl = get_markup_template('message_side.tpl');
@ -48,13 +48,13 @@ function message_post(&$a) {
$replyto = ((x($_REQUEST,'replyto')) ? notags(trim($_REQUEST['replyto'])) : ''); $replyto = ((x($_REQUEST,'replyto')) ? notags(trim($_REQUEST['replyto'])) : '');
$subject = ((x($_REQUEST,'subject')) ? notags(trim($_REQUEST['subject'])) : ''); $subject = ((x($_REQUEST,'subject')) ? notags(trim($_REQUEST['subject'])) : '');
$body = ((x($_REQUEST,'body')) ? escape_tags(trim($_REQUEST['body'])) : ''); $body = ((x($_REQUEST,'body')) ? escape_tags(trim($_REQUEST['body'])) : '');
$recipient = ((x($_REQUEST,'messageto')) ? intval($_REQUEST['messageto']) : 0 ); $recipient = ((x($_REQUEST,'messageto')) ? notags(trim($_REQUEST['messageto'])) : '');
if(feature_enabled(local_user(),'richtext')) { if(feature_enabled(local_user(),'richtext')) {
$body = fix_mce_lf($body); $body = fix_mce_lf($body);
} }
$ret = send_message($recipient, $body, $subject, $replyto); $ret = send_message(local_user(), $recipient, $body, $subject, $replyto);
$norecip = false; $norecip = false;
switch($ret){ switch($ret){
@ -181,13 +181,13 @@ function message_content(&$a) {
)); ));
if(($a->argc == 3) && ($a->argv[1] === 'drop' || $a->argv[1] === 'dropconv')) { if((argc() == 3) && (argv(1) === 'drop' || argv(1) === 'dropconv')) {
if(! intval($a->argv[2])) if(! intval(argv(2)))
return; return;
$cmd = $a->argv[1]; $cmd = argv(1);
if($cmd === 'drop') { if($cmd === 'drop') {
$r = q("DELETE FROM `mail` WHERE `id` = %d AND `uid` = %d LIMIT 1", $r = q("DELETE FROM `mail` WHERE `id` = %d AND channel_id = %d LIMIT 1",
intval($a->argv[2]), intval(argv(2)),
intval(local_user()) intval(local_user())
); );
if($r) { if($r) {
@ -196,15 +196,15 @@ function message_content(&$a) {
goaway($a->get_baseurl(true) . '/message' ); goaway($a->get_baseurl(true) . '/message' );
} }
else { else {
$r = q("SELECT `parent_uri`,`convid` FROM `mail` WHERE `id` = %d AND `uid` = %d LIMIT 1", $r = q("SELECT `parent_uri` FROM `mail` WHERE `id` = %d AND channel_id = %d LIMIT 1",
intval($a->argv[2]), intval(argv(2)),
intval(local_user()) intval(local_user())
); );
if(count($r)) { if(count($r)) {
$parent = $r[0]['parent_uri']; $parent = $r[0]['parent_uri'];
$convid = $r[0]['convid'];
$r = q("DELETE FROM `mail` WHERE `parent_uri` = '%s' AND `uid` = %d ",
$r = q("DELETE FROM `mail` WHERE `parent_uri` = '%s' AND channel_id = %d ",
dbesc($parent), dbesc($parent),
intval(local_user()) intval(local_user())
); );
@ -217,21 +217,24 @@ function message_content(&$a) {
} }
if(($a->argc > 1) && ($a->argv[1] === 'new')) { $channel = $a->get_channel();
if((argc() > 1) && ($a->argv[1] === 'new')) {
$o .= $header; $o .= $header;
$plaintext = false; $plaintext = false;
if(intval(get_pconfig(local_user(),'system','plaintext'))) if(intval(get_pconfig(local_user(),'system','plaintext')))
$plaintext = true; $plaintext = true;
if(! feature_enabled(local_user(),'richtext'))
$plaintext = true;
$tpl = get_markup_template('msg-header.tpl'); $tpl = get_markup_template('msg-header.tpl');
$a->page['htmlhead'] .= replace_macros($tpl, array( $a->page['htmlhead'] .= replace_macros($tpl, array(
'$baseurl' => $a->get_baseurl(true), '$baseurl' => $a->get_baseurl(true),
'$editselect' => (($plaintext) ? 'none' : '/(profile-jot-text|prvmail-text)/'), '$editselect' => (($plaintext) ? 'none' : '/(profile-jot-text|prvmail-text)/'),
'$nickname' => $a->user['nickname'], '$nickname' => $channel['channel_addr'],
'$linkurl' => t('Please enter a link URL:') '$linkurl' => t('Please enter a link URL:')
)); ));
@ -241,14 +244,15 @@ function message_content(&$a) {
$prename = $preurl = $preid = ''; $prename = $preurl = $preid = '';
if($preselect) { if($preselect) {
$r = q("select name, url, id from contact where uid = %d and id = %d limit 1", $r = q("select abook.*, xchan.* from abook left join xchan on abook_xchan = xchan_hash
where abook_channel = %d and abook_id = %d limit 1",
intval(local_user()), intval(local_user()),
intval($a->argv[2]) intval(argv(2))
); );
if(count($r)) { if($r) {
$prename = $r[0]['name']; $prename = $r[0]['xchan_name'];
$preurl = $r[0]['url']; $preurl = $r[0]['xchan_url'];
$preid = $r[0]['id']; $preid = $r[0]['abook_id'];
} }
} }
@ -282,7 +286,7 @@ function message_content(&$a) {
return $o; return $o;
} }
if($a->argc == 1) { if(argc() == 1) {
// list messages // list messages
@ -290,103 +294,110 @@ function message_content(&$a) {
$r = q("SELECT count(*) AS `total` FROM `mail` $r = q("SELECT count(*) AS `total` FROM `mail`
WHERE `mail`.`uid` = %d GROUP BY `parent_uri` ORDER BY `created` DESC", WHERE channel_id = %d",
intval(local_user()), intval(local_user())
dbesc($myprofile)
); );
if(count($r)) if($r)
$a->set_pager_total($r[0]['total']); $a->set_pager_total($r[0]['total']);
$r = q("SELECT max(`mail`.`created`) AS `mailcreated`, min(`mail`.`seen`) AS `mailseen`, $r = q("SELECT * from mail WHERE channel_id = %d order by created desc limit %d, %d",
`mail`.* , `contact`.`name`, `contact`.`url`, `contact`.`thumb` , `contact`.`network`,
count( * ) as count
FROM `mail` LEFT JOIN `contact` ON `mail`.`contact-id` = `contact`.`id`
WHERE `mail`.`uid` = %d GROUP BY `parent_uri` ORDER BY `mailcreated` DESC LIMIT %d , %d ",
intval(local_user()), intval(local_user()),
//
intval($a->pager['start']), intval($a->pager['start']),
intval($a->pager['itemspage']) intval($a->pager['itemspage'])
); );
if(! $r) {
if(! count($r)) {
info( t('No messages.') . EOL); info( t('No messages.') . EOL);
return $o; return $o;
} }
$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) . ")");
$tpl = get_markup_template('mail_list.tpl'); $tpl = get_markup_template('mail_list.tpl');
foreach($r as $rr) { foreach($r as $rr) {
if($rr['unknown']) { $rr['from'] = find_xchan_in_array($rr['from_xchan'],$c);
$partecipants = sprintf( t("Unknown sender - %s"),$rr['from-name']); $rr['to'] = find_xchan_in_array($rr['to_xchan'],$c);
} $rr['seen'] = (($rr['mail_flags'] & MAIL_SEEN) ? 1 : "");
elseif (link_compare($rr['from-url'],$myprofile)){
$partecipants = sprintf( t("You and %s"), $rr['name']);
}
else {
$partecipants = sprintf( t("%s and You"), $rr['from-name']);
}
$o .= replace_macros($tpl, array( $o .= replace_macros($tpl, array(
'$id' => $rr['id'], '$id' => $rr['id'],
'$from_name' => $partecipants, '$from_name' => template_escape($rr['from']['xchan_name']),
'$from_url' => (($rr['network'] === NETWORK_DFRN) ? $a->get_baseurl(true) . '/redir/' . $rr['contact-id'] : $rr['url']), '$from_url' => z_root() . '/chanview/?f=&hash=' . $rr['from_xchan'],
'$sparkle' => ' sparkle', '$from_photo' => $rr['from']['xchan_photo_s'],
'$from_photo' => (($rr['thumb']) ? $rr['thumb'] : $rr['from-photo']), '$to_name' => template_escape($rr['to']['xchan_name']),
'$subject' => template_escape((($rr['mailseen']) ? $rr['title'] : '<strong>' . $rr['title'] . '</strong>')), '$to_url' => z_root() . '/chanview/?f=&hash=' . $rr['to_xchan'],
'$delete' => t('Delete conversation'), '$to_photo' => $rr['to']['xchan_photo_s'],
'$subject' => template_escape((($rr['seen']) ? $rr['title'] : '<strong>' . $rr['title'] . '</strong>')),
'$delete' => t('Delete message'),
'$body' => template_escape($rr['body']), '$body' => template_escape($rr['body']),
'$to_name' => template_escape($rr['name']), '$date' => datetime_convert('UTC',date_default_timezone_get(),$rr['created'], t('D, d M Y - g:i A')),
'$date' => datetime_convert('UTC',date_default_timezone_get(),$rr['mailcreated'], t('D, d M Y - g:i A')), '$seen' => $rr['seen']
'$seen' => $rr['mailseen'],
'$count' => sprintf( tt('%d message', '%d messages', $rr['count']), $rr['count']),
)); ));
} }
$o .= paginate($a); $o .= paginate($a);
return $o; return $o;
} }
if(($a->argc > 1) && (intval($a->argv[1]))) { if((argc() > 1) && (intval(argv(1)))) {
$o .= $header; $o .= $header;
$r = q("SELECT `mail`.*, `contact`.`name`, `contact`.`url`, `contact`.`thumb` $r = q("SELECT parent_uri from mail WHERE channel_id = %d and id = %d limit 1",
FROM `mail` LEFT JOIN `contact` ON `mail`.`contact-id` = `contact`.`id`
WHERE `mail`.`uid` = %d AND `mail`.`id` = %d LIMIT 1",
intval(local_user()), intval(local_user()),
intval($a->argv[1]) intval(argv(1))
); );
if(count($r)) {
$contact_id = $r[0]['contact-id'];
$convid = $r[0]['convid'];
$sql_extra = sprintf(" and `mail`.`parent_uri` = '%s' ", dbesc($r[0]['parent_uri'])); if(! $r) {
if($convid) info( t('Message not found.') . EOL);
$sql_extra = sprintf(" and ( `mail`.`parent_uri` = '%s' OR `mail`.`convid` = '%d' ) ",
dbesc($r[0]['parent_uri']),
intval($convid)
);
$messages = q("SELECT `mail`.*, `contact`.`name`, `contact`.`url`, `contact`.`thumb`
FROM `mail` LEFT JOIN `contact` ON `mail`.`contact-id` = `contact`.`id`
WHERE `mail`.`uid` = %d $sql_extra ORDER BY `mail`.`created` ASC",
intval(local_user())
);
}
if(! count($messages)) {
notice( t('Message not available.') . EOL );
return $o; return $o;
} }
$r = q("UPDATE `mail` SET `seen` = 1 WHERE `parent_uri` = '%s' AND `uid` = %d", $messages = q("select * from mail where parent_uri = '%s' and channel_id = %d order by created asc",
dbesc($r[0]['parent_uri']), dbesc($r[0]['parent_uri']),
intval(local_user()) intval(local_user())
); );
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;
}
dbg(1);
$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())
);
dbg(0);
require_once("include/bbcode.php"); require_once("include/bbcode.php");
$tpl = get_markup_template('msg-header.tpl'); $tpl = get_markup_template('msg-header.tpl');
$a->page['htmlhead'] .= replace_macros($tpl, array( $a->page['htmlhead'] .= replace_macros($tpl, array(
'$nickname' => $a->user['nickname'], '$nickname' => $channel['channel_addr'],
'$baseurl' => $a->get_baseurl(true) '$baseurl' => $a->get_baseurl(true)
)); ));
@ -396,40 +407,39 @@ function message_content(&$a) {
$unknown = false; $unknown = false;
foreach($messages as $message) { foreach($messages as $message) {
if($message['unknown']) $message['from'] = find_xchan_in_array($message['from_xchan'],$c);
$unknown = true; $message['to'] = find_xchan_in_array($message['to_xchan'],$c);
if($message['from-url'] == $myprofile) {
$from_url = $myprofile;
$sparkle = '';
}
else {
$from_url = $a->get_baseurl(true) . '/redir/' . $message['contact-id'];
$sparkle = ' sparkle';
}
$extracted = item_extract_images($message['body']); logger('message: ' . print_r($message,true));
if($extracted['images'])
$message['body'] = item_redir_and_replace_images($extracted['body'], $extracted['images'], $message['contact-id']); // $extracted = item_extract_images($message['body']);
// if($extracted['images'])
// $message['body'] = item_redir_and_replace_images($extracted['body'], $extracted['images'], $message['contact-id']);
$mails[] = array( $mails[] = array(
'id' => $message['id'], 'id' => $message['id'],
'from_name' => template_escape($message['from-name']), 'from_name' => template_escape($message['from']['xchan_name']),
'from_url' => $from_url, 'from_url' => z_root() . '/chanview/?f=&hash=' . $message['from_xchan'],
'sparkle' => $sparkle, 'from_photo' => $message['from']['xchan_photo_m'],
'from_photo' => $message['from-photo'], 'to_name' => template_escape($message['to']['xchan_name']),
'to_url' => z_root() . '/chanview/?f=&hash=' . $message['to_xchan'],
'to_photo' => $message['to']['xchan_photo_m'],
'subject' => template_escape($message['title']), 'subject' => template_escape($message['title']),
'body' => template_escape(smilies(bbcode($message['body']))), 'body' => template_escape(smilies(bbcode($message['body']))),
'delete' => t('Delete message'), 'delete' => t('Delete message'),
'to_name' => template_escape($message['name']),
'date' => datetime_convert('UTC',date_default_timezone_get(),$message['created'],'D, d M Y - g:i A'), 'date' => datetime_convert('UTC',date_default_timezone_get(),$message['created'],'D, d M Y - g:i A'),
); );
$seen = $message['seen']; $seen = $message['seen'];
} }
logger('mails: ' . print_r($mails,true));
$select = $message['name'] . '<input type="hidden" name="messageto" value="' . $contact_id . '" />'; $recp = (($message['from_xchan'] === $channel['channel_hash']) ? 'to_xchan' : 'from_xchan');
$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'] . '" />'; $parent = '<input type="hidden" name="replyto" value="' . $message['parent_uri'] . '" />';
$tpl = get_markup_template('mail_display.tpl'); $tpl = get_markup_template('mail_display.tpl');

View File

@ -200,12 +200,13 @@ function ping_init(&$a) {
$result['intros'] = intval($intros); $result['intros'] = intval($intros);
$t4 = dba_timer(); $t4 = dba_timer();
$channel = get_app()->get_channel();
$myurl = $a->get_baseurl() . '/channel/' . $a->user['nickname'] ; $mails = q("SELECT count(id) as total from mail
$mails = q("SELECT *, COUNT(*) AS `total` FROM `mail` WHERE channel_id = %d AND not (mail_flags & %d) and from_xchan != '%s' ",
WHERE `uid` = %d AND `seen` = 0 AND `from-url` != '%s' ",
intval(local_user()), intval(local_user()),
dbesc($myurl) intval(MAIL_SEEN),
dbesc($channel['channel_hash'])
); );
if($mails) if($mails)
$result['mail'] = intval($mails[0]['total']); $result['mail'] = intval($mails[0]['total']);

View File

@ -1 +1 @@
2012-12-03.158 2012-12-04.159

View File

@ -5,7 +5,7 @@ $(document).ready(function() {
minChars: 2, minChars: 2,
width: 350, width: 350,
}); });
a.setOptions({ params: { type: 'a' }}); a.setOptions({ params: { autoSubmit: true, type: 'a' }});
}); });

View File

@ -1,9 +1,9 @@
<div class="mail-conv-outside-wrapper"> <div class="mail-conv-outside-wrapper">
<div class="mail-conv-sender" > <div class="mail-conv-sender" >
<a href="$mail.from_url" class="mail-conv-sender-url" ><img class="mframe mail-conv-sender-photo$mail.sparkle" src="$mail.from_photo" heigth="80" width="80" alt="$mail.from_name" /></a> <a href="$mail.from_url" class="mail-conv-sender-url" ><img class="mframe mail-conv-sender-photo$mail.sparkle" src="$mail.from_photo" heigth="80" width="80" alt="$mail.from_name" /></a>
<div class="mail-conv-sender-name" >$mail.from_name</div>
</div> </div>
<div class="mail-conv-detail" > <div class="mail-conv-detail" >
<div class="mail-conv-sender-name" >$mail.from_name</div>
<div class="mail-conv-date">$mail.date</div> <div class="mail-conv-date">$mail.date</div>
<div class="mail-conv-subject">$mail.subject</div> <div class="mail-conv-subject">$mail.subject</div>
<div class="mail-conv-body">$mail.body</div> <div class="mail-conv-body">$mail.body</div>

View File

@ -1,9 +1,12 @@
<div class="mail-list-outside-wrapper"> <div class="mail-list-outside-wrapper">
<div class="mail-list-sender" > <div class="mail-list-sender" >
<a href="$from_url" class="mail-list-sender-url" ><img class="mail-list-sender-photo$sparkle" src="$from_photo" height="80" width="80" alt="$from_name" /></a> <a href="$from_url" class="mail-list-sender-url" ><img class="mail-list-sender-photo" src="$from_photo" height="32" width="32" alt="$from_name" /></a>
</div>
<div class="mail-list-detail">
<div class="mail-list-sender-name" >$from_name</div> <div class="mail-list-sender-name" >$from_name</div>
</div>
<div class="mail-list-recip" >
<a href="$to_url" class="mail-list-recip-url" ><img class="mail-list-recip-photo" src="$to_photo" height="32" width="32" alt="$to_name" /></a>
<div class="mail-list-recip-name" >$to_name</div>
</div>
<div class="mail-list-date">$date</div> <div class="mail-list-date">$date</div>
<div class="mail-list-subject"><a href="message/$id" class="mail-list-link">$subject</a></div> <div class="mail-list-subject"><a href="message/$id" class="mail-list-link">$subject</a></div>
<div class="mail-list-delete-wrapper" id="mail-list-delete-wrapper-$id" > <div class="mail-list-delete-wrapper" id="mail-list-delete-wrapper-$id" >