aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/chat.php2
-rw-r--r--include/identity.php7
-rw-r--r--include/import.php99
-rw-r--r--include/zot.php3
-rw-r--r--mod/chat.php4
-rw-r--r--mod/import.php3
6 files changed, 114 insertions, 4 deletions
diff --git a/include/chat.php b/include/chat.php
index 05bb02bb9..a0646265a 100644
--- a/include/chat.php
+++ b/include/chat.php
@@ -91,6 +91,8 @@ function chatroom_destroy($channel,$arr) {
return $ret;
}
+ create_sync_packet($channel['channel_id'],array('chatroom' => $r));
+
q("delete from chatroom where cr_id = %d",
intval($r[0]['cr_id'])
);
diff --git a/include/identity.php b/include/identity.php
index c3f59b371..393378cc4 100644
--- a/include/identity.php
+++ b/include/identity.php
@@ -566,13 +566,18 @@ function identity_basic_export($channel_id, $items = false) {
if($r)
$ret['obj'] = $r;
-
$r = q("select * from app where app_channel = %d",
intval($channel_id)
);
if($r)
$ret['app'] = $r;
+ $r = q("select * from chatroom where cr_uid = %d",
+ intval($channel_id)
+ );
+ if($r)
+ $ret['chatroom'] = $r;
+
if(! $items)
return $ret;
diff --git a/include/import.php b/include/import.php
index 6ce572ea2..261219ce0 100644
--- a/include/import.php
+++ b/include/import.php
@@ -349,7 +349,7 @@ function sync_apps($channel,$apps) {
intval($channel['channel_id'])
);
if($x) {
- if($x[0]['app_edited'] >= $obj['app_edited'])
+ if($x[0]['app_edited'] >= $app['app_edited'])
continue;
$exists = true;
}
@@ -377,4 +377,99 @@ function sync_apps($channel,$apps) {
}
}
}
-} \ No newline at end of file
+}
+
+
+
+function import_chatrooms($channel,$chatrooms) {
+
+ if($channel && $chatrooms) {
+ foreach($chatrooms as $chatroom) {
+
+ if(! $chatroom['cr_name'])
+ continue;
+
+ unset($chatroom['cr_id']);
+ unset($chatroom['cr_aid']);
+ unset($chatroom['cr_uid']);
+
+ $chatroom['cr_aid'] = $channel['channel_account_id'];
+ $chatroom['cr_uid'] = $channel['channel_id'];
+
+ dbesc_array($chatroom);
+ $r = dbq("INSERT INTO chatroom (`"
+ . implode("`, `", array_keys($chatroom))
+ . "`) VALUES ('"
+ . implode("', '", array_values($chatroom))
+ . "')"
+ );
+ }
+ }
+}
+
+
+
+function sync_chatrooms($channel,$chatrooms) {
+
+ if($channel && $chatrooms) {
+ foreach($chatrooms as $chatroom) {
+
+ if(! $chatroom['cr_name'])
+ continue;
+
+ if(array_key_exists('cr_deleted',$chatroom) && $chatroom['cr_deleted']) {
+ q("delete from chatroom where cr_name = '%s' and cr_uid = %d limit 1",
+ dbesc($chatroom['cr_name']),
+ intval($channel['channel_id'])
+ );
+ continue;
+ }
+
+
+ unset($chatroom['cr_id']);
+ unset($chatroom['cr_aid']);
+ unset($chatroom['cr_uid']);
+
+ if(! $chatroom['cr_created'] || $chatroom['cr_created'] === NULL_DATE)
+ $chatroom['cr_created'] = datetime_convert();
+ if(! $chatroom['cr_edited'] || $chatroom['cr_edited'] === NULL_DATE)
+ $chatroom['cr_edited'] = datetime_convert();
+
+ $chatroom['cr_aid'] = $channel['channel_account_id'];
+ $chatroom['cr_uid'] = $channel['channel_id'];
+
+ $exists = false;
+
+ $x = q("select * from chatroom where cr_name = '%s' and cr_uid = %d limit 1",
+ dbesc($chatroom['cr_name']),
+ intval($channel['channel_id'])
+ );
+ if($x) {
+ if($x[0]['cr_edited'] >= $chatroom['cr_edited'])
+ continue;
+ $exists = true;
+ }
+ $name = $chatroom['cr_name'];
+
+ if($exists) {
+ foreach($chatroom as $k => $v) {
+ $r = q("UPDATE chatroom SET `%s` = '%s' WHERE cr_name = '%s' AND cr_uid = %d",
+ dbesc($k),
+ dbesc($v),
+ dbesc($name),
+ intval($channel['channel_id'])
+ );
+ }
+ }
+ else {
+ dbesc_array($chatroom);
+ $r = dbq("INSERT INTO chatroom (`"
+ . implode("`, `", array_keys($chatroom))
+ . "`) VALUES ('"
+ . implode("', '", array_values($chatroom))
+ . "')"
+ );
+ }
+ }
+ }
+}
diff --git a/include/zot.php b/include/zot.php
index fecaa7ad2..9610df894 100644
--- a/include/zot.php
+++ b/include/zot.php
@@ -2881,6 +2881,9 @@ function process_channel_sync_delivery($sender, $arr, $deliveries) {
if(array_key_exists('app',$arr) && $arr['app'])
sync_apps($channel,$arr['app']);
+ if(array_key_exists('chatroom',$arr) && $arr['chatroom'])
+ sync_apps($channel,$arr['chatroom']);
+
if(array_key_exists('channel',$arr) && is_array($arr['channel']) && count($arr['channel'])) {
if(array_key_exists('channel_page_flags',$arr['channel']) && intval($arr['channel']['channel_pageflags'])) {
$arr['channel']['channel_removed'] = (($arr['channel']['channel_pageflags'] & 0x8000) ? 1 : 0);
diff --git a/mod/chat.php b/mod/chat.php
index c2c11d0ab..633ecae22 100644
--- a/mod/chat.php
+++ b/mod/chat.php
@@ -62,11 +62,13 @@ function chat_post(&$a) {
chatroom_create($channel,$arr);
- $x = q("select cr_id from chatroom where cr_name = '%s' and cr_uid = %d limit 1",
+ $x = q("select * from chatroom where cr_name = '%s' and cr_uid = %d limit 1",
dbesc($room),
intval(local_channel())
);
+ create_sync_packet(0, array['chatroom'] => $x);
+
if($x)
goaway(z_root() . '/chat/' . $channel['channel_address'] . '/' . $x[0]['cr_id']);
diff --git a/mod/import.php b/mod/import.php
index 391461687..1d1799e00 100644
--- a/mod/import.php
+++ b/mod/import.php
@@ -435,6 +435,9 @@ function import_post(&$a) {
if(is_array($data['app']))
import_apps($channel,$data['app']);
+ if(is_array($data['chatroom']))
+ import_chatrooms($channel,$data['chatroom']);
+
$saved_notification_flags = notifications_off($channel['channel_id']);
if($import_posts && array_key_exists('item',$data) && $data['item']) {