This commit is contained in:
		@@ -110,19 +110,20 @@ func SaveCheckJobs() (string, error) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// ReadMessage
 | 
					// ReadMessage
 | 
				
			||||||
func ReadMessage(messageFilename string, detachFilesStoragePath string) (string, string, error) {
 | 
					func ReadMessage(messageFilename string, detachFilesStoragePath string) ([]string, []string, string, error) {
 | 
				
			||||||
	result := map[string]interface{}{}
 | 
						result := map[string]interface{}{}
 | 
				
			||||||
 | 
						messagesOverview := []string{}
 | 
				
			||||||
 | 
						filenames := []string{}
 | 
				
			||||||
	// read message file
 | 
						// read message file
 | 
				
			||||||
	msg, err := os.ReadFile(messageFilename)
 | 
						msg, err := os.ReadFile(messageFilename)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return "", "ReadMessage: ReadFile", err
 | 
							return nil, nil, "ReadMessage: ReadFile", err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	// protobuf unmarshal message
 | 
						// protobuf unmarshal message
 | 
				
			||||||
	var fromServerMessage meowlib.FromServerMessage
 | 
						var fromServerMessage meowlib.FromServerMessage
 | 
				
			||||||
	err = proto.Unmarshal(msg, &fromServerMessage)
 | 
						err = proto.Unmarshal(msg, &fromServerMessage)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return "", "ReadMessage: Unmarshal FromServerMessage", err
 | 
							return nil, nil, "ReadMessage: Unmarshal FromServerMessage", err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	// check if invitation answer
 | 
						// check if invitation answer
 | 
				
			||||||
	if fromServerMessage.Invitation != nil {
 | 
						if fromServerMessage.Invitation != nil {
 | 
				
			||||||
@@ -135,19 +136,19 @@ func ReadMessage(messageFilename string, detachFilesStoragePath string) (string,
 | 
				
			|||||||
			// find the peer with that lookup key
 | 
								// find the peer with that lookup key
 | 
				
			||||||
			peer := client.GetConfig().GetIdentity().Peers.GetFromMyLookupKey(packedUserMessage.Destination)
 | 
								peer := client.GetConfig().GetIdentity().Peers.GetFromMyLookupKey(packedUserMessage.Destination)
 | 
				
			||||||
			if peer == nil {
 | 
								if peer == nil {
 | 
				
			||||||
				return "", "ReadMessage: GetFromMyLookupKey", errors.New("no visible peer for that message")
 | 
									return nil, nil, "ReadMessage: GetFromMyLookupKey", errors.New("no visible peer for that message")
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			// Unpack the message
 | 
								// Unpack the message
 | 
				
			||||||
			usermsg, err := peer.ProcessInboundUserMessage(packedUserMessage.Payload, packedUserMessage.Signature)
 | 
								usermsg, err := peer.ProcessInboundUserMessage(packedUserMessage.Payload, packedUserMessage.Signature)
 | 
				
			||||||
			if err != nil {
 | 
								if err != nil {
 | 
				
			||||||
				return "", "ReadMessage: ProcessInboundUserMessage", err
 | 
									return nil, nil, "ReadMessage: ProcessInboundUserMessage", err
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			fmt.Println("From:", usermsg.From)
 | 
								fmt.Println("From:", usermsg.From)
 | 
				
			||||||
			jsonUserMessage, _ := json.Marshal(usermsg)
 | 
								jsonUserMessage, _ := json.Marshal(usermsg)
 | 
				
			||||||
			fmt.Println(string(jsonUserMessage))
 | 
								fmt.Println(string(jsonUserMessage))
 | 
				
			||||||
			// detach files
 | 
								// detach files
 | 
				
			||||||
			filenames := []string{}
 | 
					
 | 
				
			||||||
			if usermsg.Files != nil {
 | 
								if usermsg.Files != nil {
 | 
				
			||||||
				for _, file := range usermsg.Files {
 | 
									for _, file := range usermsg.Files {
 | 
				
			||||||
					filename := uuid.New().String() + "_" + file.Filename
 | 
										filename := uuid.New().String() + "_" + file.Filename
 | 
				
			||||||
@@ -158,14 +159,15 @@ func ReadMessage(messageFilename string, detachFilesStoragePath string) (string,
 | 
				
			|||||||
				//? result["invitation finalized"] = peer.Name
 | 
									//? result["invitation finalized"] = peer.Name
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			// user message
 | 
								// user message
 | 
				
			||||||
			result["message"] = string(usermsg.Data)
 | 
								messagesOverview = append(messagesOverview, usermsg.From+" > "+string(usermsg.Data))
 | 
				
			||||||
			// add message to storage
 | 
								// add message to storage
 | 
				
			||||||
			err = peer.StoreMessage(usermsg, filenames)
 | 
								err = peer.StoreMessage(usermsg, filenames)
 | 
				
			||||||
			if err != nil {
 | 
								if err != nil {
 | 
				
			||||||
				return "", "ReadMessage: StoreMessage", err
 | 
									return nil, nil, "ReadMessage: StoreMessage", err
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
							return messagesOverview, filenames, "", nil
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// fmt.Println("have read fromServerMessage, will unmarshal packed")
 | 
						// fmt.Println("have read fromServerMessage, will unmarshal packed")
 | 
				
			||||||
@@ -176,8 +178,9 @@ func ReadMessage(messageFilename string, detachFilesStoragePath string) (string,
 | 
				
			|||||||
	// 	return C.CString(errorToJson(err, "ReadMessage: Unmarshal PackedUserMessage"))
 | 
						// 	return C.CString(errorToJson(err, "ReadMessage: Unmarshal PackedUserMessage"))
 | 
				
			||||||
	// }
 | 
						// }
 | 
				
			||||||
	// fmt.Println("Destination:", packedMessage.Destination)
 | 
						// fmt.Println("Destination:", packedMessage.Destination)
 | 
				
			||||||
	// fmt.Println("Payload lengh:", len(packedMessage.Payload))
 | 
						// fmt.Println("Payload lengh:", len(packedMessage.Pay ""load))
 | 
				
			||||||
	// server invitation finalize or more ?
 | 
						// server invitation finalize or more ?
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
	if fromServerMessage.Invitation != nil {
 | 
						if fromServerMessage.Invitation != nil {
 | 
				
			||||||
		fmt.Println("Invitation from:", fromServerMessage.Invitation.From)
 | 
							fmt.Println("Invitation from:", fromServerMessage.Invitation.From)
 | 
				
			||||||
		// find the peer with that lookup key
 | 
							// find the peer with that lookup key
 | 
				
			||||||
@@ -185,7 +188,7 @@ func ReadMessage(messageFilename string, detachFilesStoragePath string) (string,
 | 
				
			|||||||
		//! FOLOWING statement is WRONG !
 | 
							//! FOLOWING statement is WRONG !
 | 
				
			||||||
		peer := client.GetConfig().GetIdentity().Peers.GetFromPublicKey(fromServerMessage.Invitation.From)
 | 
							peer := client.GetConfig().GetIdentity().Peers.GetFromPublicKey(fromServerMessage.Invitation.From)
 | 
				
			||||||
		if peer == nil {
 | 
							if peer == nil {
 | 
				
			||||||
			return "", "ReadMessage: GetFromPublicKey", errors.New("no visible peer for that message")
 | 
								return nil, nil, "ReadMessage: GetFromPublicKey", errors.New("no visible peer for that message")
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		peer.ContactPublicKey = fromServerMessage.Invitation.From
 | 
							peer.ContactPublicKey = fromServerMessage.Invitation.From
 | 
				
			||||||
		str, _ := json.Marshal(peer)
 | 
							str, _ := json.Marshal(peer)
 | 
				
			||||||
@@ -201,6 +204,7 @@ func ReadMessage(messageFilename string, detachFilesStoragePath string) (string,
 | 
				
			|||||||
			return "", "ReadMessage: FinalizeInvitation", err
 | 
								return "", "ReadMessage: FinalizeInvitation", err
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		result["invitation finalized"] = peer.Name
 | 
							result["invitation finalized"] = peer.Name
 | 
				
			||||||
 | 
							*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user