aboutsummaryrefslogtreecommitdiffstats
path: root/include/message.php
diff options
context:
space:
mode:
authortuscanhobbit <tuscanhobbit@users.noreply.github.com>2014-09-28 23:17:47 +0200
committertuscanhobbit <tuscanhobbit@users.noreply.github.com>2014-09-28 23:17:47 +0200
commitf104dc840c79f4ea666a85033bffbf4a33d06f4e (patch)
treef1fce3898b757e3a29e928cc1afe724edb620471 /include/message.php
parent6e141a8a53ba6cb7d91b989985744fdcd3d6f13d (diff)
parenteaf96f987a5f22a54fdbb4cedef52b0159a37ad0 (diff)
downloadvolse-hubzilla-f104dc840c79f4ea666a85033bffbf4a33d06f4e.tar.gz
volse-hubzilla-f104dc840c79f4ea666a85033bffbf4a33d06f4e.tar.bz2
volse-hubzilla-f104dc840c79f4ea666a85033bffbf4a33d06f4e.zip
Merge from origin
Diffstat (limited to 'include/message.php')
-rw-r--r--include/message.php63
1 files changed, 59 insertions, 4 deletions
diff --git a/include/message.php b/include/message.php
index 96c3532c1..88cfb7ba2 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']),
@@ -227,9 +284,7 @@ function private_messages_list($uid, $mailbox = '', $start = 0, $numitems = 0) {
$r[$k]['to'] = find_xchan_in_array($rr['to_xchan'],$c);
$r[$k]['seen'] = (($rr['mail_flags'] & MAIL_SEEN) ? 1 : 0);
if($r[$k]['mail_flags'] & MAIL_OBSCURED) {
- logger('unencrypting');
$key = get_config('system','prvkey');
-
if($r[$k]['title'])
$r[$k]['title'] = crypto_unencapsulate(json_decode_plus($r[$k]['title']),$key);
if($r[$k]['body'])