Skip to content

Commit

Permalink
*) fixed bug described by Huppi in http://forum.yacy-websuche.de/view…
Browse files Browse the repository at this point in the history
…topic.php?t=239

*) added a preview function to message system
*) removed some old comments, I hope that's OK


git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@4036 6c8d7289-2bf4-0310-a012-ef5d649a1542
  • Loading branch information
low012 committed Aug 8, 2007
1 parent f778987 commit c8e5a4a
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 72 deletions.
66 changes: 64 additions & 2 deletions htroot/MessageSend_p.html
Expand Up @@ -6,9 +6,9 @@
</head>
<body id="MessageSend">
#%env/templates/header.template%#
<h2>Send message</h2>
#(mode)#
<!-- =========================== write message =========================== -->
<h2>Send message</h2>
#(permission)#
<!-- we have no permission to send the message -->
<p>You cannot send a message to <strong>#[peerName]#</strong>.<br />
Expand All @@ -21,7 +21,7 @@ <h2>Send message</h2>
You are allowed to send me a message &le; #[messagesize]# kb and an
attachment &le; #[attachmentsize]#.</tt>
</p>

<form action="MessageSend_p.html" method="post" enctype="multipart/form-data" accept-charset="UTF-8">
<fieldset>
<legend>Your Message</legend>
Expand All @@ -46,6 +46,67 @@ <h2>Send message</h2>
<input type="hidden" name="messagesize" value="#[messagesize]#" />
<input type="hidden" name="attachmentsize" value="#[attachmentsize]#" />
<input name="new" type="submit" value="Enter" />
<input type="submit" name="preview" value="Preview" />
</fieldset>
</form>
::
<!-- peer cannot respond -->
<p>
You cannot send a message to <strong>#[peerName]#</strong>.<br />
The peer is alive but cannot respond. Sorry.
</p>
#(/permission)#
::
<!-- =========================== preview message =========================== -->
<h2>Preview message</h2>
#(permission)#
<!-- we have no permission to send the message -->
<p>You cannot send a message to <strong>#[peerName]#</strong>.<br />
The peer does not respond. It was now removed from the peer-list.
</p>
::
<!-- we have the permission to send the message -->
<p>The peer <b>#[peerName]#</b> is alive and responded:</p>
<p><tt class="MessageBackground">#[response]#
You are allowed to send me a message &le; #[messagesize]# kb and an
attachment &le; #[attachmentsize]#.</tt>
</p>

<p>The message has not been sent yet!</p>

<dl class="pairs">
<dt>Subject:</dt><dd>#[subject]#</dd>
<dt>Message:</dt>
<dd>
#[previewmessage]#
</dd>
</dl>

<form action="MessageSend_p.html" method="post" enctype="multipart/form-data" accept-charset="UTF-8">
<fieldset>
<legend>Your Message</legend>
<dl>
<dt>
<label for="subject">Subject:</label>
</dt>
<dd>
<input name="subject" id="subject" type="text" size="80" maxlength="80" value="#[subject]#" />
</dd>
<dt>
<label for="message">Text:</label>
</dt>
<dd>
<textarea name="message" id="message" cols="80" rows="8">#[message]#</textarea>
<p class="help">
You can use <a href="WikiHelp.html" onclick="window.open('WikiHelp.html','WikiHelp','toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=640,height=480');return false;">Wiki Code</a> here.
</p>
</dd>
</dl>
<input type="hidden" name="hash" value="#[hash]#" />
<input type="hidden" name="messagesize" value="#[messagesize]#" />
<input type="hidden" name="attachmentsize" value="#[attachmentsize]#" />
<input name="new" type="submit" value="Enter" />
<input type="submit" name="preview" value="Preview" />
</fieldset>
</form>
::
Expand All @@ -57,6 +118,7 @@ <h2>Send message</h2>
#(/permission)#
::
<!-- =========================== send message =========================== -->
<h2>Send message</h2>
#(status)#
<!-- Message send successfully -->

Expand Down
97 changes: 43 additions & 54 deletions htroot/MessageSend_p.java
Expand Up @@ -67,20 +67,22 @@ public static String dateString(Date date) {
public static serverObjects respond(httpHeader header, serverObjects post, serverSwitch env) {
serverObjects prop = new serverObjects();

//String body = "";
if ((post == null) || (post.get("hash","").length() == 0)) {
prop.put("mode",2);
// prop.put("body", "<p>You cannot call this page directly. Instead, use a link on the <a href=\"Network.html\">Network</a> page.</p>");
prop.put("mode",2);
return prop;
}

String hash = post.get("hash", "");
String subject = post.get("subject", "");
String message = post.get("message", "");

if (message.length() == 0) {
prop.put("mode", 0);


if ((message.length() == 0) || (post.containsKey("preview"))) {
if (post.containsKey("preview")) {
prop.put("mode", 1);
} else {
prop.put("mode", 0);
}

// open an editor page for the message
// first ask if the other peer is online, and also what kind of document it accepts
HashMap result = yacyClient.permissionMessage(hash);
Expand All @@ -96,56 +98,48 @@ public static serverObjects respond(httpHeader header, serverObjects post, serve
else
peerName = targetPeer.get(yacySeed.NAME,"nameless");
}
prop.put("mode_permission_peerName", peerName);

prop.put("mode_permission_peerName", peerName);
String response = (result == null) ? "-1" : (String) result.get("response");
if ((response == null) || (response.equals("-1"))) {
prop.put("mode_permission",0);

// we don't have permission or other peer does not exist
//body += "<p>You cannot send a message to '" + peerName + "'. The peer does not respond. It was now removed from the peer-list.</p>";
prop.put("mode_permission",0);

if (targetPeer != null) {
yacyCore.peerActions.peerDeparture(targetPeer);
}
} else {
prop.put("mode_permission",1);

// write input form
try {
int messagesize = Integer.parseInt((String) result.get("messagesize"));
int attachmentsize = Integer.parseInt((String) result.get("attachmentsize"));

prop.put("mode_permission_response", response);
prop.put("mode_permission_messagesize", messagesize);
prop.put("mode_permission_attachmentsize", attachmentsize);
prop.put("mode_permission_subject", subject);
prop.put("mode_permission_message", message);
prop.put("mode_permission_hash", hash);

// body += "<p>The peer '" + peerName + "' is alive and responded:<br>";
// body += "'" + response + " You are allowed to send me a message &le; " + messagesize + " kb and an attachment &le; " + attachmentsize + ".'</p>";
// body += "<form action=\"MessageSend_p.html\" method=\"post\" enctype=\"multipart/form-data\" accept-charset=\"UTF-8\"><br><br>";
// body += "<p><h3>Your Message</h3></p>";
// body += "<p>Subject:<br><input name=\"subject\" type=\"text\" size=\"80\" maxlength=\"80\" value=\"" + subject + "\"></p>";
// body += "<p>Text:<br><textarea name=\"message\" cols=\"80\" rows=\"8\"></textarea></p>";
// body += "<input type=\"hidden\" name=\"hash\" value=\"" + hash + "\">";
// body += "<input type=\"hidden\" name=\"messagesize\" value=\"" + messagesize + "\">";
// body += "<input type=\"hidden\" name=\"attachmentsize\" value=\"" + attachmentsize + "\">";
// body += "<input name=\"new\" type=\"submit\" value=\"Enter\"></form>";
} catch (NumberFormatException e) {
// "unresolved pattern", the remote peer is alive but had an exception
//body += "<p>The peer '" + peerName + "' is alive but cannot respond. Sorry..</p>";
prop.put("mode_permission",2);
}

// write input form
try {
int messagesize = Integer.parseInt((String) result.get("messagesize"));
int attachmentsize = Integer.parseInt((String) result.get("attachmentsize"));

prop.put("mode_permission_response", response);
prop.put("mode_permission_messagesize", messagesize);
prop.put("mode_permission_attachmentsize", attachmentsize);
prop.put("mode_permission_subject", subject);
prop.put("mode_permission_message", message);
prop.put("mode_permission_hash", hash);
if (post.containsKey("preview")) {
prop.putWiki("mode_permission_previewmessage", message);

}

} catch (NumberFormatException e) {
// "unresolved pattern", the remote peer is alive but had an exception
prop.put("mode_permission",2);
}
}
} else {
prop.put("mode", 1);
prop.put("mode", 2);
// send written message to peer
try {
prop.put("mode_status", 0);
int messagesize = Integer.parseInt(post.get("messagesize", "0"));
//int attachmentsize = Integer.parseInt(post.get("attachmentsize", "0"));

if (messagesize < 1000) messagesize = 1000; // debug
if (subject.length() > 100) subject = subject.substring(0, 100);
if (message.length() > messagesize) message = message.substring(0, messagesize);
Expand All @@ -156,23 +150,18 @@ public static serverObjects respond(httpHeader header, serverObjects post, serve
mb = message.getBytes();
}
HashMap result = yacyClient.postMessage(hash, subject, mb);
prop.put("mode_status_response", result.get("response"));
// body += "<p>Your message has been sent. The target peer responded:</p>";
// body += "<p><i>" + result.get("response") + "</i></p>";

//message has been sent
prop.put("mode_status_response", result.get("response"));

} catch (NumberFormatException e) {
prop.put("mode_status", 1);
prop.put("mode_status", 1);

// "unresolved pattern", the remote peer is alive but had an exception
prop.put("mode_status_message", message);
// body += "<p>The target peer is alive but did not receive your message. Sorry..</p>";
// body += "<p>Here is a copy of your message, so you can copy it to save it for further attempts:<br>";
// body += message;
// body += "</p>";
prop.put("mode_status_message", message);
}
}

// return rewrite properties
//prop.put("body", body);
return prop;
}

Expand Down
21 changes: 8 additions & 13 deletions htroot/Messages_p.java
Expand Up @@ -74,7 +74,7 @@ public static String dateString(Date date) {
public static serverObjects respond(httpHeader header, serverObjects post, serverSwitch env) {
plasmaSwitchboard switchboard = (plasmaSwitchboard) env;
serverObjects prop = new serverObjects();

// set peer address / name
final String peerAddress = yacyCore.seedDB.mySeed.getPublicAddress();
final String peerName = yacyCore.seedDB.mySeed.getName();
Expand Down Expand Up @@ -106,10 +106,9 @@ public static serverObjects respond(httpHeader header, serverObjects post, serve
} else {
prop.put("peersKnown", 0);
}

prop.put("mode", 0);
prop.put("mode_error", 0);
//wikiCode wikiTransformer = new wikiCode(switchboard);

String action = ((post == null) ? "list" : post.get("action", "list"));
messageBoard.entry message;
Expand Down Expand Up @@ -143,28 +142,26 @@ public static serverObjects respond(httpHeader header, serverObjects post, serve
prop.put("mode_messages_"+count+"_date", dateString(message.date()));
prop.put("mode_messages_"+count+"_from", message.author());
prop.put("mode_messages_"+count+"_to", message.recipient());
//prop.put("mode_messages_"+count+"_subject", wikiTransformer.transform(message.subject()));
//TODO: not needed, when all templates will be cleaned via replaceHTML
prop.put("mode_messages_"+count+"_subject", message.subject());
prop.put("mode_messages_"+count+"_category", message.category());
prop.put("mode_messages_"+count+"_key", key);
prop.put("mode_messages_"+count+"_hash", message.authorHash());

if (((String)header.get(httpHeader.CONNECTION_PROP_PATH)).endsWith(".rss")) {
// set the peer address
prop.put("mode_messages_"+count+"_peerAddress", peerAddress);

// set the rfc822 date
prop.put("mode_messages_"+count+"_rfc822Date",httpc.dateString(message.date()));

// also write out the message body (needed for the RSS feed)
try {
prop.put("mode_messages_"+count+"_body",new String(message.message(), "UTF-8"));
} catch (UnsupportedEncodingException e) {
// can not happen, because UTF-8 must be supported by every JVM
}
}
}

dark = !dark;
count++;
}
Expand All @@ -180,12 +177,10 @@ public static serverObjects respond(httpHeader header, serverObjects post, serve
String key = post.get("object", "");
message = switchboard.messageDB.read(key);
if (message == null) throw new NullPointerException("Message with ID " + key + " does not exist");

prop.put("mode_from", message.author());
prop.put("mode_to", message.recipient());
prop.put("mode_date", dateString(message.date()));
//prop.put("mode_messages_subject", wikiTransformer.transform(message.subject()));
//TODO: not needed, when all templates will be cleaned via replaceHTML
prop.put("mode_subject", message.subject());
String theMessage = null;
try {
Expand Down
6 changes: 3 additions & 3 deletions source/de/anomic/yacy/yacyClient.java
Expand Up @@ -609,11 +609,11 @@ public static HashMap postMessage(String targetHash, String subject, byte[] mess
post.putASIS("myseed", yacyCore.seedDB.mySeed.genSeedStr(salt));
post.putASIS("subject", subject);
try {
post.put("message", new String(message, "UTF-8"));
post.putASIS("message", new String(message, "UTF-8"));
} catch (UnsupportedEncodingException e) {
post.put("message", new String(message));
post.putASIS("message", new String(message));
}

// send request
try {
final HashMap result = nxTools.table(
Expand Down

0 comments on commit c8e5a4a

Please sign in to comment.