more work on d* private messages
This commit is contained in:
parent
72ec78d027
commit
509a85cb12
@ -1532,6 +1532,12 @@ function diaspora_conversation($importer,$xml,$msg) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$key = get_config('system','pubkey');
|
||||||
|
if($subject)
|
||||||
|
$subject = json_encode(crypto_encapsulate($subject,$key));
|
||||||
|
if($body)
|
||||||
|
$body = json_encode(crypto_encapsulate($body,$key));
|
||||||
|
|
||||||
q("insert into mail ( `channel_id`, `convid`, `from_xchan`,`to_xchan`,`title`,`body`,`mail_flags`,`mid`,`parent_mid`,`created`) values ( %d, %d, '%s', '%s', '%s', '%s', %d, '%s', '%s', '%s')",
|
q("insert into mail ( `channel_id`, `convid`, `from_xchan`,`to_xchan`,`title`,`body`,`mail_flags`,`mid`,`parent_mid`,`created`) values ( %d, %d, '%s', '%s', '%s', '%s', %d, '%s', '%s', '%s')",
|
||||||
intval($importer['channel_id']),
|
intval($importer['channel_id']),
|
||||||
intval($conversation['id']),
|
intval($conversation['id']),
|
||||||
@ -1539,7 +1545,7 @@ function diaspora_conversation($importer,$xml,$msg) {
|
|||||||
dbesc($importer['channel_hash']),
|
dbesc($importer['channel_hash']),
|
||||||
dbesc($subject),
|
dbesc($subject),
|
||||||
dbesc($body),
|
dbesc($body),
|
||||||
0,
|
intval(MAIL_OBSCURED),
|
||||||
dbesc($msg_guid),
|
dbesc($msg_guid),
|
||||||
dbesc($parent_uri),
|
dbesc($parent_uri),
|
||||||
dbesc($msg_created_at)
|
dbesc($msg_created_at)
|
||||||
@ -1588,7 +1594,7 @@ function diaspora_message($importer,$xml,$msg) {
|
|||||||
$msg_diaspora_handle = notags(unxmlify($xml->diaspora_handle));
|
$msg_diaspora_handle = notags(unxmlify($xml->diaspora_handle));
|
||||||
$msg_conversation_guid = notags(unxmlify($xml->conversation_guid));
|
$msg_conversation_guid = notags(unxmlify($xml->conversation_guid));
|
||||||
|
|
||||||
$parent_uri = $diaspora_handle . ':' . $msg_parent_guid;
|
$parent_uri = $msg_parent_guid;
|
||||||
|
|
||||||
$contact = diaspora_get_contact_by_handle($importer['channel_id'],$msg_diaspora_handle);
|
$contact = diaspora_get_contact_by_handle($importer['channel_id'],$msg_diaspora_handle);
|
||||||
if(! $contact) {
|
if(! $contact) {
|
||||||
@ -1607,7 +1613,7 @@ function diaspora_message($importer,$xml,$msg) {
|
|||||||
intval($importer['channel_id']),
|
intval($importer['channel_id']),
|
||||||
dbesc($msg_conversation_guid)
|
dbesc($msg_conversation_guid)
|
||||||
);
|
);
|
||||||
if(count($c))
|
if($c)
|
||||||
$conversation = $c[0];
|
$conversation = $c[0];
|
||||||
else {
|
else {
|
||||||
logger('diaspora_message: conversation not available.');
|
logger('diaspora_message: conversation not available.');
|
||||||
@ -1637,15 +1643,21 @@ function diaspora_message($importer,$xml,$msg) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$r = q("select id from mail where `uri` = '%s' and uid = %d limit 1",
|
$r = q("select id from mail where mid = '%s' and uid = %d limit 1",
|
||||||
dbesc($message_id),
|
dbesc($message_id),
|
||||||
intval($importer['channel_id'])
|
intval($importer['channel_id'])
|
||||||
);
|
);
|
||||||
if(count($r)) {
|
if($r) {
|
||||||
logger('diaspora_message: duplicate message already delivered.', LOGGER_DEBUG);
|
logger('diaspora_message: duplicate message already delivered.', LOGGER_DEBUG);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$key = get_config('system','pubkey');
|
||||||
|
if($subject)
|
||||||
|
$subject = json_encode(crypto_encapsulate($subject,$key));
|
||||||
|
if($body)
|
||||||
|
$body = json_encode(crypto_encapsulate($body,$key));
|
||||||
|
|
||||||
q("insert into mail ( `channel_id`, `convid`, `from_xchan`,`to_xchan`,`title`,`body`,`mail_flags`,`mid`,`parent_mid`,`created`) values ( %d, %d, '%s', '%s', '%s', '%s', '%d','%s','%s','%s')",
|
q("insert into mail ( `channel_id`, `convid`, `from_xchan`,`to_xchan`,`title`,`body`,`mail_flags`,`mid`,`parent_mid`,`created`) values ( %d, %d, '%s', '%s', '%s', '%s', '%d','%s','%s','%s')",
|
||||||
intval($importer['channel_id']),
|
intval($importer['channel_id']),
|
||||||
intval($conversation['id']),
|
intval($conversation['id']),
|
||||||
@ -1653,7 +1665,7 @@ function diaspora_message($importer,$xml,$msg) {
|
|||||||
dbesc($importer['xchan_hash']),
|
dbesc($importer['xchan_hash']),
|
||||||
dbesc($conversation['subject']),
|
dbesc($conversation['subject']),
|
||||||
dbesc($body),
|
dbesc($body),
|
||||||
0,
|
intval(MAIL_OBSCURED),
|
||||||
dbesc($msg_guid),
|
dbesc($msg_guid),
|
||||||
dbesc($parent_uri),
|
dbesc($parent_uri),
|
||||||
dbesc($msg_created_at)
|
dbesc($msg_created_at)
|
||||||
|
@ -27,6 +27,9 @@ function send_message($uid = 0, $recipient='', $body='', $subject='', $replyto='
|
|||||||
// else
|
// else
|
||||||
// $expires = datetime_convert(date_default_timezone_get(),'UTC',$expires);
|
// $expires = datetime_convert(date_default_timezone_get(),'UTC',$expires);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if($uid) {
|
if($uid) {
|
||||||
$r = q("select * from channel where channel_id = %d limit 1",
|
$r = q("select * from channel where channel_id = %d limit 1",
|
||||||
intval($uid)
|
intval($uid)
|
||||||
@ -43,6 +46,59 @@ function send_message($uid = 0, $recipient='', $body='', $subject='', $replyto='
|
|||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// look for any existing conversation structure
|
||||||
|
|
||||||
|
if(strlen($replyto)) {
|
||||||
|
$r = q("select convid from mail where uid = %d and ( mid = '%s' or parent_mid = '%s' ) limit 1",
|
||||||
|
intval(local_user()),
|
||||||
|
dbesc($replyto),
|
||||||
|
dbesc($replyto)
|
||||||
|
);
|
||||||
|
if($r)
|
||||||
|
$convid = $r[0]['convid'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if(! $convid) {
|
||||||
|
|
||||||
|
// create a new conversation
|
||||||
|
|
||||||
|
$conv_guid = random_string();
|
||||||
|
|
||||||
|
$recip = q("select * from xchan where xchan_hash = '%s' limit 1",
|
||||||
|
dbesc($recipient)
|
||||||
|
);
|
||||||
|
if($recip)
|
||||||
|
$recip_handle = $recip[0]['xchan_addr'];
|
||||||
|
|
||||||
|
$sender_handle = $channel['channel_address'] . '@' . get_app()->get_hostname();
|
||||||
|
|
||||||
|
$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($r)
|
||||||
|
$convid = $r[0]['id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if(! $convid) {
|
||||||
|
$ret['message'] = 'conversation not found';
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// generate a unique message_id
|
// generate a unique message_id
|
||||||
|
|
||||||
do {
|
do {
|
||||||
@ -115,9 +171,10 @@ function send_message($uid = 0, $recipient='', $body='', $subject='', $replyto='
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
$r = q("INSERT INTO mail ( account_id, mail_flags, channel_id, from_xchan, to_xchan, title, body, attach, mid, parent_mid, created, expires )
|
$r = q("INSERT INTO mail ( account_id, convid, mail_flags, channel_id, from_xchan, to_xchan, title, body, attach, mid, parent_mid, created, expires )
|
||||||
VALUES ( %d, %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' )",
|
VALUES ( %d, %d, %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' )",
|
||||||
intval($channel['channel_account_id']),
|
intval($channel['channel_account_id']),
|
||||||
|
intval($convid),
|
||||||
intval(MAIL_OBSCURED),
|
intval(MAIL_OBSCURED),
|
||||||
intval($channel['channel_id']),
|
intval($channel['channel_id']),
|
||||||
dbesc($channel['channel_hash']),
|
dbesc($channel['channel_hash']),
|
||||||
|
@ -1 +1 @@
|
|||||||
2014-09-22.806
|
2014-09-23.807
|
||||||
|
Reference in New Issue
Block a user