Skip to content
Snippets Groups Projects
Commit 397a290b authored by aj3g19's avatar aj3g19
Browse files

now shows chatName as well as chatID

parent b1b3fa55
No related branches found
No related tags found
No related merge requests found
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
node_modules node_modules
npm-debug.log npm-debug.log
__pycache__
# Local development # Local development
*.env *.env
*.dev *.dev
......
...@@ -65,9 +65,8 @@ function handleLogin(username,socket){ ...@@ -65,9 +65,8 @@ function handleLogin(username,socket){
memberID: un memberID: un
} }
}, function (error, response, body){ }, function (error, response, body){
chatIDs = body; //upon receiving chatIDs and names, get most recent message of each one
//upon receiving chatIDs, get most recent message of each one getMostRecentMessages(body,socket);
getMostRecentMessages(chatIDs,socket);
}); });
/* /*
...@@ -76,19 +75,21 @@ function handleLogin(username,socket){ ...@@ -76,19 +75,21 @@ function handleLogin(username,socket){
*/ */
} }
function getMostRecentMessages(chatIds,socket){ function getMostRecentMessages(chatIdsNames,socket){
//go through each chat, get most recent message and pass this information to the client //go through each chat, get most recent message and pass this information to the client
for (const chatID of chatIDs){ for (const idChatName of chatIdsNames){
request('http://localhost:7071/api/HttpGetLastChatMessage', { request('http://localhost:7071/api/HttpGetLastChatMessage', {
json: true, json: true,
body: { body: {
"ChatID": chatID "ChatID": idChatName.ChatID
} }
}, function (error, response, body){ }, function (error, response, body){
console.log(body); console.log(body);
//upon receiving it, tell the client to store the chatID //upon receiving it, tell the client to store the chatID
if(body != "error"){ if(body != "error"){
body['ChatID'] = chatID body['ChatID'] = idChatName.ChatID
body['chatName'] = idChatName.chatName
socket.emit('chatAndLastMsg',body); socket.emit('chatAndLastMsg',body);
} }
}); });
......
...@@ -13,6 +13,7 @@ var app = new Vue({ ...@@ -13,6 +13,7 @@ var app = new Vue({
lastMessage:'', lastMessage:'',
chatIDsAndLstMsgs:[], chatIDsAndLstMsgs:[],
currentChatID:-1, currentChatID:-1,
currentChatName:'',
state:{state:0} state:{state:0}
}, },
mounted: function() { mounted: function() {
...@@ -28,7 +29,9 @@ var app = new Vue({ ...@@ -28,7 +29,9 @@ var app = new Vue({
socket.emit('sendChat',userMsgChatID); socket.emit('sendChat',userMsgChatID);
this.chatMessage = ''; this.chatMessage = '';
}, },
retrieveChatMessages(ChatID){ retrieveChatMessages(ChatID,chatName){
this.currentChatName = chatName;
this.currentChatID = ChatID;
socket.emit('requestChatMessages',ChatID); socket.emit('requestChatMessages',ChatID);
}, },
back(){ back(){
...@@ -52,11 +55,11 @@ function connect() { ...@@ -52,11 +55,11 @@ function connect() {
}); });
socket.on('allChatMessages',function(ChatIDMessages){ socket.on('allChatMessages',function(ChatIDMessages){
app.currentChatID = ChatIDMessages.ChatID;
app.messages = ChatIDMessages.messages; app.messages = ChatIDMessages.messages;
app.state.state = 2; app.state.state = 2;
}); });
//list of dictionaries {username,message,date,time,ChatID,chatName}
socket.on('chatAndLastMsg',function(ChatIDMsg){ socket.on('chatAndLastMsg',function(ChatIDMsg){
app.chatIDsAndLstMsgs.push(ChatIDMsg); app.chatIDsAndLstMsgs.push(ChatIDMsg);
}); });
......
...@@ -5,7 +5,7 @@ from azure.cosmos.exceptions import CosmosHttpResponseError ...@@ -5,7 +5,7 @@ from azure.cosmos.exceptions import CosmosHttpResponseError
#takes in memberID #takes in memberID
#returns chatID of chats the member is in #returns chatID and chatName of chats the member is in
def main(req: func.HttpRequest,documents: func.DocumentList) -> func.HttpResponse: def main(req: func.HttpRequest,documents: func.DocumentList) -> func.HttpResponse:
...@@ -21,7 +21,10 @@ def main(req: func.HttpRequest,documents: func.DocumentList) -> func.HttpRespons ...@@ -21,7 +21,10 @@ def main(req: func.HttpRequest,documents: func.DocumentList) -> func.HttpRespons
#go through each chat and find memberID #go through each chat and find memberID
for document in documents: for document in documents:
if(memID in document["members"]): if(memID in document["members"]):
chatIDs.append(document["ChatID"]) new_dict = {}
new_dict["ChatID"] = document["ChatID"]
new_dict["chatName"] = document["name"]
chatIDs.append(new_dict)
return func.HttpResponse(json.dumps(chatIDs)) return func.HttpResponse(json.dumps(chatIDs))
......
<h3>{{currentChatName}}</h3>
<button class="btn btn-primary" @click='back'>Back</button> <button class="btn btn-primary" @click='back'>Back</button>
<div v-for="message in messages"> <div v-for="message in messages">
<h6>{{message.username}}: {{message.time}} {{message.message}}</h6> <h6>{{message.username}}: {{message.time}} {{message.message}}</h6>
......
<div v-for="chatIDMsg in chatIDsAndLstMsgs"> <div v-for="chatIDMsg in chatIDsAndLstMsgs">
<button class="btn btn-primary" @click='retrieveChatMessages(chatIDMsg.ChatID)'>{{chatIDMsg.ChatID}}</button> <button class="btn btn-primary" @click='retrieveChatMessages(chatIDMsg.ChatID,chatIDMsg.chatName)'>
{{chatIDMsg.ChatID}} {{chatIDMsg.chatName}} </button>
</div> </div>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment