aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rwxr-xr-xinclude/diaspora.php24
-rw-r--r--include/message.php61
2 files changed, 77 insertions, 8 deletions
diff --git a/include/diaspora.php b/include/diaspora.php
index 6f504b460..74dad177a 100755
--- a/include/diaspora.php
+++ b/include/diaspora.php
@@ -1532,6 +1532,12 @@ function diaspora_conversation($importer,$xml,$msg) {
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')",
intval($importer['channel_id']),
intval($conversation['id']),
@@ -1539,7 +1545,7 @@ function diaspora_conversation($importer,$xml,$msg) {
dbesc($importer['channel_hash']),
dbesc($subject),
dbesc($body),
- 0,
+ intval(MAIL_OBSCURED),
dbesc($msg_guid),
dbesc($parent_uri),
dbesc($msg_created_at)
@@ -1588,7 +1594,7 @@ function diaspora_message($importer,$xml,$msg) {
$msg_diaspora_handle = notags(unxmlify($xml->diaspora_handle));
$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);
if(! $contact) {
@@ -1607,7 +1613,7 @@ function diaspora_message($importer,$xml,$msg) {
intval($importer['channel_id']),
dbesc($msg_conversation_guid)
);
- if(count($c))
+ if($c)
$conversation = $c[0];
else {
logger('diaspora_message: conversation not available.');
@@ -1637,15 +1643,21 @@ function diaspora_message($importer,$xml,$msg) {
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),
intval($importer['channel_id'])
);
- if(count($r)) {
+ if($r) {
logger('diaspora_message: duplicate message already delivered.', LOGGER_DEBUG);
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')",
intval($importer['channel_id']),
intval($conversation['id']),
@@ -1653,7 +1665,7 @@ function diaspora_message($importer,$xml,$msg) {
dbesc($importer['xchan_hash']),
dbesc($conversation['subject']),
dbesc($body),
- 0,
+ intval(MAIL_OBSCURED),
dbesc($msg_guid),
dbesc($parent_uri),
dbesc($msg_created_at)
diff --git a/include/message.php b/include/message.php
index 96c3532c1..6aba899f7 100644
--- a/include/message.php
+++ b/include/message.php
@@ -27,6 +27,9 @@ function send_message($uid = 0, $recipient='', $body='', $subject='', $replyto='
// else
// $expires = datetime_convert(date_default_timezone_get(),'UTC',$expires);
+
+
+
if($uid) {
$r = q("select * from channel where channel_id = %d limit 1",
intval($uid)
@@ -43,6 +46,59 @@ function send_message($uid = 0, $recipient='', $body='', $subject='', $replyto='
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
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 )
- VALUES ( %d, %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' )",
+ $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, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' )",
intval($channel['channel_account_id']),
+ intval($convid),
intval(MAIL_OBSCURED),
intval($channel['channel_id']),
dbesc($channel['channel_hash']),