|
@ -2,6 +2,7 @@ package Messages |
|
|
|
|
|
|
|
|
import ( |
|
|
import ( |
|
|
"encoding/json" |
|
|
"encoding/json" |
|
|
|
|
|
"fmt" |
|
|
"net/http" |
|
|
"net/http" |
|
|
"net/url" |
|
|
"net/url" |
|
|
"strings" |
|
|
"strings" |
|
@ -14,10 +15,10 @@ import ( |
|
|
// EncryptedConversationList returns an encrypted list of all Conversations
|
|
|
// EncryptedConversationList returns an encrypted list of all Conversations
|
|
|
func EncryptedConversationList(w http.ResponseWriter, r *http.Request) { |
|
|
func EncryptedConversationList(w http.ResponseWriter, r *http.Request) { |
|
|
var ( |
|
|
var ( |
|
|
userConversations []Models.UserConversation |
|
|
|
|
|
userSession Models.Session |
|
|
|
|
|
returnJSON []byte |
|
|
|
|
|
err error |
|
|
|
|
|
|
|
|
conversationDetails []Models.UserConversation |
|
|
|
|
|
userSession Models.Session |
|
|
|
|
|
returnJSON []byte |
|
|
|
|
|
err error |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
userSession, err = Auth.CheckCookie(r) |
|
|
userSession, err = Auth.CheckCookie(r) |
|
@ -26,7 +27,7 @@ func EncryptedConversationList(w http.ResponseWriter, r *http.Request) { |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
userConversations, err = Database.GetUserConversationsByUserId( |
|
|
|
|
|
|
|
|
conversationDetails, err = Database.GetUserConversationsByUserId( |
|
|
userSession.UserID.String(), |
|
|
userSession.UserID.String(), |
|
|
) |
|
|
) |
|
|
if err != nil { |
|
|
if err != nil { |
|
@ -34,7 +35,7 @@ func EncryptedConversationList(w http.ResponseWriter, r *http.Request) { |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
returnJSON, err = json.MarshalIndent(userConversations, "", " ") |
|
|
|
|
|
|
|
|
returnJSON, err = json.MarshalIndent(conversationDetails, "", " ") |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
http.Error(w, "Error", http.StatusInternalServerError) |
|
|
http.Error(w, "Error", http.StatusInternalServerError) |
|
|
return |
|
|
return |
|
@ -47,12 +48,14 @@ func EncryptedConversationList(w http.ResponseWriter, r *http.Request) { |
|
|
// EncryptedConversationDetailsList returns an encrypted list of all ConversationDetails
|
|
|
// EncryptedConversationDetailsList returns an encrypted list of all ConversationDetails
|
|
|
func EncryptedConversationDetailsList(w http.ResponseWriter, r *http.Request) { |
|
|
func EncryptedConversationDetailsList(w http.ResponseWriter, r *http.Request) { |
|
|
var ( |
|
|
var ( |
|
|
userConversations []Models.ConversationDetail |
|
|
|
|
|
query url.Values |
|
|
|
|
|
conversationIds []string |
|
|
|
|
|
returnJSON []byte |
|
|
|
|
|
ok bool |
|
|
|
|
|
err error |
|
|
|
|
|
|
|
|
conversationDetails []Models.ConversationDetail |
|
|
|
|
|
detail Models.ConversationDetail |
|
|
|
|
|
query url.Values |
|
|
|
|
|
conversationIds []string |
|
|
|
|
|
returnJSON []byte |
|
|
|
|
|
i int |
|
|
|
|
|
ok bool |
|
|
|
|
|
err error |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
query = r.URL.Query() |
|
|
query = r.URL.Query() |
|
@ -65,7 +68,7 @@ func EncryptedConversationDetailsList(w http.ResponseWriter, r *http.Request) { |
|
|
// TODO: Fix error handling here
|
|
|
// TODO: Fix error handling here
|
|
|
conversationIds = strings.Split(conversationIds[0], ",") |
|
|
conversationIds = strings.Split(conversationIds[0], ",") |
|
|
|
|
|
|
|
|
userConversations, err = Database.GetConversationDetailsByIds( |
|
|
|
|
|
|
|
|
conversationDetails, err = Database.GetConversationDetailsByIds( |
|
|
conversationIds, |
|
|
conversationIds, |
|
|
) |
|
|
) |
|
|
if err != nil { |
|
|
if err != nil { |
|
@ -73,7 +76,18 @@ func EncryptedConversationDetailsList(w http.ResponseWriter, r *http.Request) { |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
returnJSON, err = json.MarshalIndent(userConversations, "", " ") |
|
|
|
|
|
|
|
|
for i, detail = range conversationDetails { |
|
|
|
|
|
if detail.AttachmentID == nil { |
|
|
|
|
|
continue |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
conversationDetails[i].Attachment.ImageLink = fmt.Sprintf( |
|
|
|
|
|
"http://192.168.1.5:8080/files/%s", |
|
|
|
|
|
detail.Attachment.FilePath, |
|
|
|
|
|
) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
returnJSON, err = json.MarshalIndent(conversationDetails, "", " ") |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
http.Error(w, "Error", http.StatusInternalServerError) |
|
|
http.Error(w, "Error", http.StatusInternalServerError) |
|
|
return |
|
|
return |
|
|