Created
June 9, 2015 17:10
-
-
Save korrio/c40bda45b290e5fb047c to your computer and use it in GitHub Desktop.
getLastChatHistory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getLastChatHistory($user_id, $friend_id, $message_size, $message_page, $conversation_id,$sort) | |
{ | |
//DB Connection | |
$db2 = dbConnect(); | |
$output = array(); | |
//Header | |
$user_info = getUserDetails($user_id); | |
$friend_info = getUserDetails($friend_id); | |
if(true) | |
{ | |
$output2["FRIENDID"] = $friend_info['UserID']; | |
$output2["FRIENDNAME"] = $friend_info['UserName']; | |
$output2["USERFIRSTNAME"] = $friend_info['UserFirstName']; | |
$output2["USERLASTNAME"] = $friend_info['UserLastName']; | |
$output2["FRIENDIMAGE"] = $friend_info['UserAvatarPath']; | |
$output2["USERTOKEN"] = $friend_info['UserToken']; | |
$output2["USERTOKENMOBILE"] = $friend_info['UserTokenMobile']; | |
$output2["STATUS"] = ""; | |
$output1["USERID"] = $user_info['UserID']; | |
$output1["USERNAME"] = $user_info['UserName']; | |
$output1["USERFIRSTNAME"] = $user_info['UserFirstName']; | |
$output1["USERLASTNAME"] = $user_info['UserLastName']; | |
$output1["USERIMAGE"] = $user_info['UserAvatarPath']; | |
$output1["USERTOKEN"] = $user_info['UserToken']; | |
$output1["USERTOKENMOBILE"] = $user_info['UserTokenMobile']; | |
$output1["STATUS"] = ""; | |
} | |
$sorter = "DESC"; | |
$sql = "SELECT | |
id as RID, | |
conversation_id as CONVERSATION_ID, | |
user_id as SENDERID, | |
UserName as SENDERUSERNAME, | |
UserAvatarPath as SENDERIMAGE, | |
0 as RECEIVERID, | |
messagetype as MESSAGETYPE, | |
messagechat as MESSAGECHAT, | |
tattoocode as TATTOOCODE, | |
tattoourl as TATTOOURL, | |
imageurl as IMAGEURL, | |
imagetype as IMAGETYPE, | |
imagename as IMAGENAME, | |
videourl as VIDEOURL, | |
videoimage as VIDEOIMAGE, | |
location_latitude as LOCATION_LATITUDE, | |
location_longtitude as LOCATION_LONGTITUDE, | |
locationdetail as LOCATIONDETAIL, | |
contactname as CONTACTNAME, | |
contactdetails as CONTACTDETAILS, | |
ip as IP, | |
timestamp as TIMESTAMP, | |
UNIX_TIMESTAMP(Now()) as TIMESTAMPMS, | |
status as STATUS | |
from ".CHAT_DB.".conversation_reply cr | |
INNER JOIN ".USER_TABLE." u | |
ON u.UserID = cr.user_id | |
where cr.conversation_id = ". $conversation_id; | |
$sql .= " ORDER BY TIMESTAMP " . $sorter; | |
$sql .= _LIMIT_BY_PAGE($message_page, $message_size); | |
//print $sql; | |
$res = $db2->query($sql); | |
if($res->num_rows>0) | |
$res = fetchAll($res); | |
else | |
$res = array(); | |
$output["TIMESTAMPMS"] = $res[0]["TIMESTAMPMS"]; | |
$output["MYPROFILE"] = $output1; | |
$output["USERFRIENDPROFILE"] = $output2; | |
$output["LASTMESSAGE"] = $res[0]; | |
$datarecent = array("TIMESTAMPMS"=>strtotime($res[0]["TIMESTAMP"]),"CID"=>$conversation_id,"DATARECENTCHAT"=>$output); | |
/* | |
if(isset($_GET['jsonp'])) | |
return $_GET['callback'] . ' (' . json_encode($datarecent) . ')'; | |
else | |
return json_encode($datarecent); | |
*/ | |
return $datarecent; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment