basic chatterbot support - though these would still require additional functionality in the API to maintain presence as they'll get kicked out of the room if they don't ping it regularly.
This commit is contained in:
parent
d44b7d11a8
commit
e40d226252
@ -182,3 +182,44 @@ function chatroom_list($uid) {
|
||||
|
||||
return $r;
|
||||
}
|
||||
|
||||
/**
|
||||
* create a chat message via API.
|
||||
* It is the caller's responsibility to enter the room.
|
||||
*/
|
||||
|
||||
function chat_message($uid,$room_id,$xchan,$text) {
|
||||
|
||||
$ret = array('success' => false);
|
||||
|
||||
if(! $text)
|
||||
return;
|
||||
|
||||
$sql_extra = permissions_sql($uid);
|
||||
|
||||
$r = q("select * from chatroom where cr_uid = %d and cr_id = %d $sql_extra",
|
||||
intval($uid),
|
||||
intval($room_id)
|
||||
);
|
||||
if(! $r)
|
||||
return $ret;
|
||||
|
||||
$arr = array(
|
||||
'chat_room' => $room_id,
|
||||
'chat_xchan' => $xchan,
|
||||
'chat_text' => $text
|
||||
);
|
||||
|
||||
call_hooks('chat_message',$arr);
|
||||
|
||||
$x = q("insert into chat ( chat_room, chat_xchan, created, chat_text )
|
||||
values( %d, '%s', '%s', '%s' )",
|
||||
intval($room_id),
|
||||
dbesc($xchan),
|
||||
dbesc(datetime_convert()),
|
||||
dbesc($arr['chat_text'])
|
||||
);
|
||||
|
||||
$ret['success'] = true;
|
||||
return $ret;
|
||||
}
|
||||
|
@ -41,13 +41,22 @@ function chatsvc_post(&$a) {
|
||||
if(! $r)
|
||||
json_return_and_die($ret);
|
||||
|
||||
$arr = array(
|
||||
'chat_room' => $a->data['chat']['room_id'],
|
||||
'chat_xchan' => get_observer_hash(),
|
||||
'chat_text' => $text
|
||||
);
|
||||
|
||||
call_hooks('chat_post',$arr);
|
||||
|
||||
$x = q("insert into chat ( chat_room, chat_xchan, created, chat_text )
|
||||
values( %d, '%s', '%s', '%s' )",
|
||||
intval($a->data['chat']['room_id']),
|
||||
dbesc(get_observer_hash()),
|
||||
dbesc(datetime_convert()),
|
||||
dbesc($text)
|
||||
dbesc($arr['chat_text'])
|
||||
);
|
||||
|
||||
$ret['success'] = true;
|
||||
json_return_and_die($ret);
|
||||
}
|
||||
|
Reference in New Issue
Block a user