Removed subject line, which won't be used in new conversation views.

This commit is contained in:
akwizgran
2013-11-30 15:09:26 +00:00
parent d771f6c94c
commit 3e6d7ba66a
15 changed files with 60 additions and 236 deletions

View File

@@ -1,16 +1,12 @@
package net.sf.briar.android.groups; package net.sf.briar.android.groups;
import static android.graphics.Typeface.BOLD;
import static android.view.Gravity.CENTER_VERTICAL;
import static android.widget.LinearLayout.HORIZONTAL; import static android.widget.LinearLayout.HORIZONTAL;
import static android.widget.LinearLayout.VERTICAL;
import static java.text.DateFormat.SHORT; import static java.text.DateFormat.SHORT;
import static net.sf.briar.android.util.CommonLayoutParams.WRAP_WRAP_1; import static net.sf.briar.android.util.CommonLayoutParams.WRAP_WRAP_1;
import java.util.ArrayList; import java.util.ArrayList;
import net.sf.briar.R; import net.sf.briar.R;
import net.sf.briar.android.util.HorizontalSpace;
import net.sf.briar.api.Author; import net.sf.briar.api.Author;
import net.sf.briar.api.db.GroupMessageHeader; import net.sf.briar.api.db.GroupMessageHeader;
import android.content.Context; import android.content.Context;
@@ -19,7 +15,6 @@ import android.text.format.DateUtils;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
@@ -41,16 +36,6 @@ class GroupAdapter extends ArrayAdapter<GroupMessageHeader> {
if(!item.isRead()) if(!item.isRead())
layout.setBackgroundColor(res.getColor(R.color.unread_background)); layout.setBackgroundColor(res.getColor(R.color.unread_background));
LinearLayout innerLayout = new LinearLayout(ctx);
// Give me all the unused width
innerLayout.setLayoutParams(WRAP_WRAP_1);
innerLayout.setOrientation(VERTICAL);
// FIXME: Can this layout be removed?
LinearLayout authorLayout = new LinearLayout(ctx);
authorLayout.setOrientation(HORIZONTAL);
authorLayout.setGravity(CENTER_VERTICAL);
TextView name = new TextView(ctx); TextView name = new TextView(ctx);
// Give me all the unused width // Give me all the unused width
name.setLayoutParams(WRAP_WRAP_1); name.setLayoutParams(WRAP_WRAP_1);
@@ -64,33 +49,11 @@ class GroupAdapter extends ArrayAdapter<GroupMessageHeader> {
} else { } else {
name.setText(author.getName()); name.setText(author.getName());
} }
authorLayout.addView(name); layout.addView(name);
innerLayout.addView(authorLayout);
if(item.getContentType().equals("text/plain")) {
TextView subject = new TextView(ctx);
subject.setTextSize(14);
subject.setMaxLines(2);
subject.setPadding(10, 0, 10, 10);
if(!item.isRead()) subject.setTypeface(null, BOLD);
String s = item.getSubject();
subject.setText(s == null ? "" : s);
innerLayout.addView(subject);
} else {
LinearLayout attachmentLayout = new LinearLayout(ctx);
attachmentLayout.setOrientation(HORIZONTAL);
ImageView attachment = new ImageView(ctx);
attachment.setPadding(5, 0, 5, 5);
attachment.setImageResource(R.drawable.content_attachment);
attachmentLayout.addView(attachment);
attachmentLayout.addView(new HorizontalSpace(ctx));
innerLayout.addView(attachmentLayout);
}
layout.addView(innerLayout);
TextView date = new TextView(ctx); TextView date = new TextView(ctx);
date.setTextSize(14); date.setTextSize(14);
date.setPadding(0, 10, 10, 10); date.setPadding(10, 10, 10, 10);
long then = item.getTimestamp(), now = System.currentTimeMillis(); long then = item.getTimestamp(), now = System.currentTimeMillis();
date.setText(DateUtils.formatSameDayTime(then, now, SHORT, SHORT)); date.setText(DateUtils.formatSameDayTime(then, now, SHORT, SHORT));
layout.addView(date); layout.addView(date);

View File

@@ -1,9 +1,7 @@
package net.sf.briar.android.groups; package net.sf.briar.android.groups;
import static android.graphics.Typeface.BOLD;
import static android.view.Gravity.CENTER; import static android.view.Gravity.CENTER;
import static android.widget.LinearLayout.HORIZONTAL; import static android.widget.LinearLayout.HORIZONTAL;
import static android.widget.LinearLayout.VERTICAL;
import static java.text.DateFormat.SHORT; import static java.text.DateFormat.SHORT;
import static net.sf.briar.android.groups.GroupListItem.MANAGE; import static net.sf.briar.android.groups.GroupListItem.MANAGE;
import static net.sf.briar.android.util.CommonLayoutParams.WRAP_WRAP_1; import static net.sf.briar.android.util.CommonLayoutParams.WRAP_WRAP_1;
@@ -14,14 +12,12 @@ import java.util.Comparator;
import java.util.List; import java.util.List;
import net.sf.briar.R; import net.sf.briar.R;
import net.sf.briar.android.util.HorizontalSpace;
import android.content.Context; import android.content.Context;
import android.content.res.Resources; import android.content.res.Resources;
import android.text.format.DateUtils; import android.text.format.DateUtils;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.BaseAdapter; import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
@@ -79,12 +75,9 @@ class GroupListAdapter extends BaseAdapter {
if(item.getUnreadCount() > 0) if(item.getUnreadCount() > 0)
layout.setBackgroundColor(res.getColor(R.color.unread_background)); layout.setBackgroundColor(res.getColor(R.color.unread_background));
LinearLayout innerLayout = new LinearLayout(ctx);
// Give me all the unused width
innerLayout.setLayoutParams(WRAP_WRAP_1);
innerLayout.setOrientation(VERTICAL);
TextView name = new TextView(ctx); TextView name = new TextView(ctx);
// Give me all the unused width
name.setLayoutParams(WRAP_WRAP_1);
name.setTextSize(18); name.setTextSize(18);
name.setMaxLines(1); name.setMaxLines(1);
name.setPadding(10, 10, 10, 10); name.setPadding(10, 10, 10, 10);
@@ -92,7 +85,7 @@ class GroupListAdapter extends BaseAdapter {
String groupName = item.getGroup().getName(); String groupName = item.getGroup().getName();
if(unread > 0) name.setText(groupName + " (" + unread + ")"); if(unread > 0) name.setText(groupName + " (" + unread + ")");
else name.setText(groupName); else name.setText(groupName);
innerLayout.addView(name); layout.addView(name);
if(item.isEmpty()) { if(item.isEmpty()) {
TextView noPosts = new TextView(ctx); TextView noPosts = new TextView(ctx);
@@ -100,33 +93,11 @@ class GroupListAdapter extends BaseAdapter {
noPosts.setPadding(10, 0, 10, 10); noPosts.setPadding(10, 0, 10, 10);
noPosts.setTextColor(res.getColor(R.color.no_posts)); noPosts.setTextColor(res.getColor(R.color.no_posts));
noPosts.setText(R.string.no_posts); noPosts.setText(R.string.no_posts);
innerLayout.addView(noPosts); layout.addView(noPosts);
layout.addView(innerLayout);
} else { } else {
if(item.getContentType().equals("text/plain")) {
TextView subject = new TextView(ctx);
subject.setTextSize(14);
subject.setMaxLines(2);
subject.setPadding(10, 0, 10, 10);
if(item.getUnreadCount() > 0) subject.setTypeface(null, BOLD);
String s = item.getSubject();
subject.setText(s == null ? "" : s);
innerLayout.addView(subject);
} else {
LinearLayout attachmentLayout = new LinearLayout(ctx);
attachmentLayout.setOrientation(HORIZONTAL);
ImageView attachment = new ImageView(ctx);
attachment.setPadding(5, 0, 5, 5);
attachment.setImageResource(R.drawable.content_attachment);
attachmentLayout.addView(attachment);
attachmentLayout.addView(new HorizontalSpace(ctx));
innerLayout.addView(attachmentLayout);
}
layout.addView(innerLayout);
TextView date = new TextView(ctx); TextView date = new TextView(ctx);
date.setTextSize(14); date.setTextSize(14);
date.setPadding(0, 10, 10, 10); date.setPadding(10, 0, 10, 10);
long then = item.getTimestamp(), now = System.currentTimeMillis(); long then = item.getTimestamp(), now = System.currentTimeMillis();
date.setText(DateUtils.formatSameDayTime(then, now, SHORT, SHORT)); date.setText(DateUtils.formatSameDayTime(then, now, SHORT, SHORT));
layout.addView(date); layout.addView(date);

View File

@@ -17,7 +17,7 @@ class GroupListItem {
private final Group group; private final Group group;
private final boolean empty; private final boolean empty;
private final String authorName, contentType, subject; private final String authorName, contentType;
private final long timestamp; private final long timestamp;
private final int unread; private final int unread;
@@ -27,7 +27,6 @@ class GroupListItem {
if(empty) { if(empty) {
authorName = null; authorName = null;
contentType = null; contentType = null;
subject = null;
timestamp = 0; timestamp = 0;
unread = 0; unread = 0;
} else { } else {
@@ -39,7 +38,6 @@ class GroupListItem {
if(a == null) authorName = null; if(a == null) authorName = null;
else authorName = a.getName(); else authorName = a.getName();
contentType = newest.getContentType(); contentType = newest.getContentType();
subject = newest.getSubject();
timestamp = newest.getTimestamp(); timestamp = newest.getTimestamp();
int unread = 0; int unread = 0;
for(GroupMessageHeader h : list) if(!h.isRead()) unread++; for(GroupMessageHeader h : list) if(!h.isRead()) unread++;
@@ -63,10 +61,6 @@ class GroupListItem {
return contentType; return contentType;
} }
String getSubject() {
return subject;
}
long getTimestamp() { long getTimestamp() {
return timestamp; return timestamp;
} }

View File

@@ -1,16 +1,12 @@
package net.sf.briar.android.messages; package net.sf.briar.android.messages;
import static android.graphics.Typeface.BOLD;
import static android.view.Gravity.CENTER_VERTICAL;
import static android.widget.LinearLayout.HORIZONTAL; import static android.widget.LinearLayout.HORIZONTAL;
import static android.widget.LinearLayout.VERTICAL;
import static java.text.DateFormat.SHORT; import static java.text.DateFormat.SHORT;
import static net.sf.briar.android.util.CommonLayoutParams.WRAP_WRAP_1; import static net.sf.briar.android.util.CommonLayoutParams.WRAP_WRAP_1;
import java.util.ArrayList; import java.util.ArrayList;
import net.sf.briar.R; import net.sf.briar.R;
import net.sf.briar.android.util.HorizontalSpace;
import net.sf.briar.api.db.PrivateMessageHeader; import net.sf.briar.api.db.PrivateMessageHeader;
import android.content.Context; import android.content.Context;
import android.content.res.Resources; import android.content.res.Resources;
@@ -18,7 +14,6 @@ import android.text.format.DateUtils;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
@@ -41,16 +36,6 @@ class ConversationAdapter extends ArrayAdapter<PrivateMessageHeader> {
layout.setBackgroundColor(res.getColor(R.color.unread_background)); layout.setBackgroundColor(res.getColor(R.color.unread_background));
} }
LinearLayout innerLayout = new LinearLayout(ctx);
// Give me all the unused width
innerLayout.setLayoutParams(WRAP_WRAP_1);
innerLayout.setOrientation(VERTICAL);
// FIXME: Can this layout be removed?
LinearLayout authorLayout = new LinearLayout(ctx);
authorLayout.setOrientation(HORIZONTAL);
authorLayout.setGravity(CENTER_VERTICAL);
TextView name = new TextView(ctx); TextView name = new TextView(ctx);
// Give me all the unused width // Give me all the unused width
name.setLayoutParams(WRAP_WRAP_1); name.setLayoutParams(WRAP_WRAP_1);
@@ -58,29 +43,7 @@ class ConversationAdapter extends ArrayAdapter<PrivateMessageHeader> {
name.setMaxLines(1); name.setMaxLines(1);
name.setPadding(10, 10, 10, 10); name.setPadding(10, 10, 10, 10);
name.setText(item.getAuthor().getName()); name.setText(item.getAuthor().getName());
authorLayout.addView(name); layout.addView(name);
innerLayout.addView(authorLayout);
if(item.getContentType().equals("text/plain")) {
TextView subject = new TextView(ctx);
subject.setTextSize(14);
subject.setMaxLines(2);
subject.setPadding(10, 0, 10, 10);
if(!item.isRead()) subject.setTypeface(null, BOLD);
String s = item.getSubject();
subject.setText(s == null ? "" : s);
innerLayout.addView(subject);
} else {
LinearLayout attachmentLayout = new LinearLayout(ctx);
attachmentLayout.setOrientation(HORIZONTAL);
ImageView attachment = new ImageView(ctx);
attachment.setPadding(5, 0, 5, 5);
attachment.setImageResource(R.drawable.content_attachment);
attachmentLayout.addView(attachment);
attachmentLayout.addView(new HorizontalSpace(ctx));
innerLayout.addView(attachmentLayout);
}
layout.addView(innerLayout);
TextView date = new TextView(ctx); TextView date = new TextView(ctx);
date.setTextSize(14); date.setTextSize(14);

View File

@@ -1,9 +1,6 @@
package net.sf.briar.android.messages; package net.sf.briar.android.messages;
import static android.graphics.Typeface.BOLD;
import static android.view.Gravity.LEFT;
import static android.widget.LinearLayout.HORIZONTAL; import static android.widget.LinearLayout.HORIZONTAL;
import static android.widget.LinearLayout.VERTICAL;
import static java.text.DateFormat.SHORT; import static java.text.DateFormat.SHORT;
import static net.sf.briar.android.util.CommonLayoutParams.WRAP_WRAP_1; import static net.sf.briar.android.util.CommonLayoutParams.WRAP_WRAP_1;
@@ -41,13 +38,9 @@ implements OnItemClickListener {
if(item.getUnreadCount() > 0) if(item.getUnreadCount() > 0)
layout.setBackgroundColor(res.getColor(R.color.unread_background)); layout.setBackgroundColor(res.getColor(R.color.unread_background));
LinearLayout innerLayout = new LinearLayout(ctx);
// Give me all the unused width
innerLayout.setLayoutParams(WRAP_WRAP_1);
innerLayout.setOrientation(VERTICAL);
innerLayout.setGravity(LEFT);
TextView name = new TextView(ctx); TextView name = new TextView(ctx);
// Give me all the unused width
name.setLayoutParams(WRAP_WRAP_1);
name.setTextSize(18); name.setTextSize(18);
name.setMaxLines(1); name.setMaxLines(1);
name.setPadding(10, 10, 10, 10); name.setPadding(10, 10, 10, 10);
@@ -55,7 +48,7 @@ implements OnItemClickListener {
String contactName = item.getContactName(); String contactName = item.getContactName();
if(unread > 0) name.setText(contactName + " (" + unread + ")"); if(unread > 0) name.setText(contactName + " (" + unread + ")");
else name.setText(contactName); else name.setText(contactName);
innerLayout.addView(name); layout.addView(name);
if(item.isEmpty()) { if(item.isEmpty()) {
TextView noMessages = new TextView(ctx); TextView noMessages = new TextView(ctx);
@@ -63,19 +56,8 @@ implements OnItemClickListener {
noMessages.setPadding(10, 0, 10, 10); noMessages.setPadding(10, 0, 10, 10);
noMessages.setTextColor(res.getColor(R.color.no_messages)); noMessages.setTextColor(res.getColor(R.color.no_messages));
noMessages.setText(R.string.no_messages); noMessages.setText(R.string.no_messages);
innerLayout.addView(noMessages); layout.addView(noMessages);
layout.addView(innerLayout);
} else { } else {
TextView subject = new TextView(ctx);
subject.setTextSize(14);
subject.setMaxLines(2);
subject.setPadding(10, 0, 10, 10);
if(unread > 0) subject.setTypeface(null, BOLD);
String s = item.getSubject();
subject.setText(s == null ? "" : s);
innerLayout.addView(subject);
layout.addView(innerLayout);
TextView date = new TextView(ctx); TextView date = new TextView(ctx);
date.setTextSize(14); date.setTextSize(14);
date.setPadding(0, 10, 10, 10); date.setPadding(0, 10, 10, 10);

View File

@@ -15,7 +15,6 @@ class ConversationListItem {
private final Contact contact; private final Contact contact;
private final boolean empty; private final boolean empty;
private final String subject;
private final long timestamp; private final long timestamp;
private final int unread; private final int unread;
@@ -24,14 +23,12 @@ class ConversationListItem {
this.contact = contact; this.contact = contact;
empty = headers.isEmpty(); empty = headers.isEmpty();
if(empty) { if(empty) {
subject = null;
timestamp = 0; timestamp = 0;
unread = 0; unread = 0;
} else { } else {
List<PrivateMessageHeader> list = List<PrivateMessageHeader> list =
new ArrayList<PrivateMessageHeader>(headers); new ArrayList<PrivateMessageHeader>(headers);
Collections.sort(list, DescendingHeaderComparator.INSTANCE); Collections.sort(list, DescendingHeaderComparator.INSTANCE);
subject = list.get(0).getSubject();
timestamp = list.get(0).getTimestamp(); timestamp = list.get(0).getTimestamp();
int unread = 0; int unread = 0;
for(PrivateMessageHeader h : list) if(!h.isRead()) unread++; for(PrivateMessageHeader h : list) if(!h.isRead()) unread++;
@@ -55,10 +52,6 @@ class ConversationListItem {
return empty; return empty;
} }
String getSubject() {
return subject;
}
long getTimestamp() { long getTimestamp() {
return timestamp; return timestamp;
} }

View File

@@ -9,9 +9,9 @@ public class GroupMessageHeader extends MessageHeader {
private final GroupId groupId; private final GroupId groupId;
public GroupMessageHeader(MessageId id, MessageId parent, Author author, public GroupMessageHeader(MessageId id, MessageId parent, Author author,
String contentType, String subject, long timestamp, boolean read, String contentType, long timestamp, boolean read,
GroupId groupId) { GroupId groupId) {
super(id, parent, author, contentType, subject, timestamp, read); super(id, parent, author, contentType, timestamp, read);
this.groupId = groupId; this.groupId = groupId;
} }

View File

@@ -7,17 +7,16 @@ public abstract class MessageHeader {
private final MessageId id, parent; private final MessageId id, parent;
private final Author author; private final Author author;
private final String contentType, subject; private final String contentType;
private final long timestamp; private final long timestamp;
private final boolean read; private final boolean read;
protected MessageHeader(MessageId id, MessageId parent, Author author, protected MessageHeader(MessageId id, MessageId parent, Author author,
String contentType, String subject, long timestamp, boolean read) { String contentType, long timestamp, boolean read) {
this.id = id; this.id = id;
this.parent = parent; this.parent = parent;
this.author = author; this.author = author;
this.contentType = contentType; this.contentType = contentType;
this.subject = subject;
this.timestamp = timestamp; this.timestamp = timestamp;
this.read = read; this.read = read;
} }
@@ -47,11 +46,6 @@ public abstract class MessageHeader {
return contentType; return contentType;
} }
/** Returns the message's subject line. */
public String getSubject() {
return subject;
}
/** Returns the timestamp created by the message's author. */ /** Returns the timestamp created by the message's author. */
public long getTimestamp() { public long getTimestamp() {
return timestamp; return timestamp;

View File

@@ -10,9 +10,9 @@ public class PrivateMessageHeader extends MessageHeader {
private final boolean incoming; private final boolean incoming;
public PrivateMessageHeader(MessageId id, MessageId parent, Author author, public PrivateMessageHeader(MessageId id, MessageId parent, Author author,
String contentType, String subject, long timestamp, boolean read, String contentType, long timestamp, boolean read,
ContactId contactId, boolean incoming) { ContactId contactId, boolean incoming) {
super(id, parent, author, contentType, subject, timestamp, read); super(id, parent, author, contentType, timestamp, read);
this.contactId = contactId; this.contactId = contactId;
this.incoming = incoming; this.incoming = incoming;
} }

View File

@@ -28,13 +28,6 @@ public interface Message {
/** Returns the message's content type. */ /** Returns the message's content type. */
String getContentType(); String getContentType();
/**
* Returns the message's subject line, which is created from the first 50
* bytes of the message body if the content type is text/plain, or is the
* empty string otherwise.
*/
String getSubject();
/** Returns the message's timestamp. */ /** Returns the message's timestamp. */
long getTimestamp(); long getTimestamp();

View File

@@ -145,7 +145,6 @@ abstract class JdbcDatabase implements Database<Connection> {
+ " authorName VARCHAR," // Null for private/anon messages + " authorName VARCHAR," // Null for private/anon messages
+ " authorKey VARCHAR," // Null for private/anon messages + " authorKey VARCHAR," // Null for private/anon messages
+ " contentType VARCHAR NOT NULL," + " contentType VARCHAR NOT NULL,"
+ " subject VARCHAR NOT NULL,"
+ " timestamp BIGINT NOT NULL," + " timestamp BIGINT NOT NULL,"
+ " length INT NOT NULL," + " length INT NOT NULL,"
+ " bodyStart INT NOT NULL," + " bodyStart INT NOT NULL,"
@@ -659,10 +658,10 @@ abstract class JdbcDatabase implements Database<Connection> {
PreparedStatement ps = null; PreparedStatement ps = null;
try { try {
String sql = "INSERT INTO messages (messageId, parentId, groupId," String sql = "INSERT INTO messages (messageId, parentId, groupId,"
+ " authorId, authorName, authorKey, contentType, subject," + " authorId, authorName, authorKey, contentType,"
+ " timestamp, length, bodyStart, bodyLength, raw," + " timestamp, length, bodyStart, bodyLength, raw,"
+ " incoming, read)" + " incoming, read)"
+ " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?," + " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,"
+ " FALSE)"; + " FALSE)";
ps = txn.prepareStatement(sql); ps = txn.prepareStatement(sql);
ps.setBytes(1, m.getId().getBytes()); ps.setBytes(1, m.getId().getBytes());
@@ -680,14 +679,13 @@ abstract class JdbcDatabase implements Database<Connection> {
ps.setBytes(6, a.getPublicKey()); ps.setBytes(6, a.getPublicKey());
} }
ps.setString(7, m.getContentType()); ps.setString(7, m.getContentType());
ps.setString(8, m.getSubject()); ps.setLong(8, m.getTimestamp());
ps.setLong(9, m.getTimestamp());
byte[] raw = m.getSerialised(); byte[] raw = m.getSerialised();
ps.setInt(10, raw.length); ps.setInt(9, raw.length);
ps.setInt(11, m.getBodyStart()); ps.setInt(10, m.getBodyStart());
ps.setInt(12, m.getBodyLength()); ps.setInt(11, m.getBodyLength());
ps.setBytes(13, raw); ps.setBytes(12, raw);
ps.setBoolean(14, incoming); ps.setBoolean(13, incoming);
int affected = ps.executeUpdate(); int affected = ps.executeUpdate();
if(affected != 1) throw new DbStateException(); if(affected != 1) throw new DbStateException();
ps.close(); ps.close();
@@ -758,23 +756,22 @@ abstract class JdbcDatabase implements Database<Connection> {
PreparedStatement ps = null; PreparedStatement ps = null;
try { try {
String sql = "INSERT INTO messages (messageId, parentId," String sql = "INSERT INTO messages (messageId, parentId,"
+ " contentType, subject, timestamp, length, bodyStart," + " contentType, timestamp, length, bodyStart,"
+ " bodyLength, raw, incoming, contactId, read)" + " bodyLength, raw, incoming, contactId, read)"
+ " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, FALSE)"; + " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, FALSE)";
ps = txn.prepareStatement(sql); ps = txn.prepareStatement(sql);
ps.setBytes(1, m.getId().getBytes()); ps.setBytes(1, m.getId().getBytes());
if(m.getParent() == null) ps.setNull(2, BINARY); if(m.getParent() == null) ps.setNull(2, BINARY);
else ps.setBytes(2, m.getParent().getBytes()); else ps.setBytes(2, m.getParent().getBytes());
ps.setString(3, m.getContentType()); ps.setString(3, m.getContentType());
ps.setString(4, m.getSubject()); ps.setLong(4, m.getTimestamp());
ps.setLong(5, m.getTimestamp());
byte[] raw = m.getSerialised(); byte[] raw = m.getSerialised();
ps.setInt(6, raw.length); ps.setInt(5, raw.length);
ps.setInt(7, m.getBodyStart()); ps.setInt(6, m.getBodyStart());
ps.setInt(8, m.getBodyLength()); ps.setInt(7, m.getBodyLength());
ps.setBytes(9, raw); ps.setBytes(8, raw);
ps.setBoolean(10, incoming); ps.setBoolean(9, incoming);
ps.setInt(11, c.getInt()); ps.setInt(10, c.getInt());
int affected = ps.executeUpdate(); int affected = ps.executeUpdate();
if(affected != 1) throw new DbStateException(); if(affected != 1) throw new DbStateException();
ps.close(); ps.close();
@@ -1288,7 +1285,7 @@ abstract class JdbcDatabase implements Database<Connection> {
ResultSet rs = null; ResultSet rs = null;
try { try {
String sql = "SELECT messageId, parentId, authorId, authorName," String sql = "SELECT messageId, parentId, authorId, authorName,"
+ " authorKey, contentType, subject, timestamp, read" + " authorKey, contentType, timestamp, read"
+ " FROM messages" + " FROM messages"
+ " WHERE groupId = ?"; + " WHERE groupId = ?";
ps = txn.prepareStatement(sql); ps = txn.prepareStatement(sql);
@@ -1311,11 +1308,10 @@ abstract class JdbcDatabase implements Database<Connection> {
author = new Author(authorId, authorName, authorKey); author = new Author(authorId, authorName, authorKey);
} }
String contentType = rs.getString(6); String contentType = rs.getString(6);
String subject = rs.getString(7); long timestamp = rs.getLong(7);
long timestamp = rs.getLong(8); boolean read = rs.getBoolean(8);
boolean read = rs.getBoolean(9);
headers.add(new GroupMessageHeader(id, parent, author, headers.add(new GroupMessageHeader(id, parent, author,
contentType, subject, timestamp, read, g)); contentType, timestamp, read, g));
} }
rs.close(); rs.close();
ps.close(); ps.close();
@@ -1647,7 +1643,7 @@ abstract class JdbcDatabase implements Database<Connection> {
ResultSet rs = null; ResultSet rs = null;
try { try {
// Get the incoming message headers // Get the incoming message headers
String sql = "SELECT m.messageId, parentId, contentType, subject," String sql = "SELECT m.messageId, parentId, contentType,"
+ " timestamp, read, c.authorId, name, publicKey" + " timestamp, read, c.authorId, name, publicKey"
+ " FROM messages AS m" + " FROM messages AS m"
+ " JOIN contacts AS c" + " JOIN contacts AS c"
@@ -1665,22 +1661,20 @@ abstract class JdbcDatabase implements Database<Connection> {
byte[] b = rs.getBytes(2); byte[] b = rs.getBytes(2);
MessageId parent = b == null ? null : new MessageId(b); MessageId parent = b == null ? null : new MessageId(b);
String contentType = rs.getString(3); String contentType = rs.getString(3);
String subject = rs.getString(4); long timestamp = rs.getLong(4);
long timestamp = rs.getLong(5); boolean read = rs.getBoolean(5);
boolean read = rs.getBoolean(6); AuthorId authorId = new AuthorId(rs.getBytes(6));
AuthorId authorId = new AuthorId(rs.getBytes(7)); String authorName = rs.getString(7);
String authorName = rs.getString(8); byte[] authorKey = rs.getBytes(8);
byte[] authorKey = rs.getBytes(9);
Author author = new Author(authorId, authorName, authorKey); Author author = new Author(authorId, authorName, authorKey);
headers.add(new PrivateMessageHeader(id, parent, author, headers.add(new PrivateMessageHeader(id, parent, author,
contentType, subject, timestamp, read, c, true)); contentType, timestamp, read, c, true));
} }
rs.close(); rs.close();
ps.close(); ps.close();
// Get the outgoing message headers // Get the outgoing message headers
sql = "SELECT m.messageId, parentId, contentType, subject," sql = "SELECT m.messageId, parentId, contentType, timestamp, read,"
+ " timestamp, read, a.authorId, a.name," + " a.authorId, a.name, a.publicKey"
+ " a.publicKey"
+ " FROM messages AS m" + " FROM messages AS m"
+ " JOIN contacts AS c" + " JOIN contacts AS c"
+ " ON m.contactId = c.contactId" + " ON m.contactId = c.contactId"
@@ -1697,15 +1691,14 @@ abstract class JdbcDatabase implements Database<Connection> {
byte[] b = rs.getBytes(2); byte[] b = rs.getBytes(2);
MessageId parent = b == null ? null : new MessageId(b); MessageId parent = b == null ? null : new MessageId(b);
String contentType = rs.getString(3); String contentType = rs.getString(3);
String subject = rs.getString(4); long timestamp = rs.getLong(4);
long timestamp = rs.getLong(5); boolean read = rs.getBoolean(5);
boolean read = rs.getBoolean(6); AuthorId authorId = new AuthorId(rs.getBytes(6));
AuthorId authorId = new AuthorId(rs.getBytes(7)); String authorName = rs.getString(7);
String authorName = rs.getString(8); byte[] authorKey = rs.getBytes(8);
byte[] authorKey = rs.getBytes(9);
Author author = new Author(authorId, authorName, authorKey); Author author = new Author(authorId, authorName, authorKey);
headers.add(new PrivateMessageHeader(id, parent, author, headers.add(new PrivateMessageHeader(id, parent, author,
contentType, subject, timestamp, read, c, false)); contentType, timestamp, read, c, false));
} }
rs.close(); rs.close();
ps.close(); ps.close();

View File

@@ -4,7 +4,6 @@ import static net.sf.briar.api.AuthorConstants.MAX_SIGNATURE_LENGTH;
import static net.sf.briar.api.messaging.MessagingConstants.MAX_BODY_LENGTH; import static net.sf.briar.api.messaging.MessagingConstants.MAX_BODY_LENGTH;
import static net.sf.briar.api.messaging.MessagingConstants.MAX_CONTENT_TYPE_LENGTH; import static net.sf.briar.api.messaging.MessagingConstants.MAX_CONTENT_TYPE_LENGTH;
import static net.sf.briar.api.messaging.MessagingConstants.MAX_PACKET_LENGTH; import static net.sf.briar.api.messaging.MessagingConstants.MAX_PACKET_LENGTH;
import static net.sf.briar.api.messaging.MessagingConstants.MAX_SUBJECT_LENGTH;
import static net.sf.briar.api.messaging.MessagingConstants.MESSAGE_SALT_LENGTH; import static net.sf.briar.api.messaging.MessagingConstants.MESSAGE_SALT_LENGTH;
import static net.sf.briar.api.messaging.Types.AUTHOR; import static net.sf.briar.api.messaging.Types.AUTHOR;
import static net.sf.briar.api.messaging.Types.GROUP; import static net.sf.briar.api.messaging.Types.GROUP;
@@ -12,9 +11,6 @@ import static net.sf.briar.api.messaging.Types.MESSAGE;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;
import java.security.GeneralSecurityException; import java.security.GeneralSecurityException;
import java.security.SecureRandom; import java.security.SecureRandom;
@@ -44,7 +40,6 @@ class MessageFactoryImpl implements MessageFactory {
private final MessageDigest messageDigest; private final MessageDigest messageDigest;
private final WriterFactory writerFactory; private final WriterFactory writerFactory;
private final Clock clock; private final Clock clock;
private final CharsetDecoder decoder;
@Inject @Inject
MessageFactoryImpl(CryptoComponent crypto, WriterFactory writerFactory, MessageFactoryImpl(CryptoComponent crypto, WriterFactory writerFactory,
@@ -54,7 +49,6 @@ class MessageFactoryImpl implements MessageFactory {
messageDigest = crypto.getMessageDigest(); messageDigest = crypto.getMessageDigest();
this.writerFactory = writerFactory; this.writerFactory = writerFactory;
this.clock = clock; this.clock = clock;
decoder = Charset.forName("UTF-8").newDecoder();
} }
public Message createPrivateMessage(MessageId parent, String contentType, public Message createPrivateMessage(MessageId parent, String contentType,
@@ -129,17 +123,7 @@ class MessageFactoryImpl implements MessageFactory {
// Hash the message, including the signature, to get the message ID // Hash the message, including the signature, to get the message ID
w.removeConsumer(digestingConsumer); w.removeConsumer(digestingConsumer);
MessageId id = new MessageId(messageDigest.digest()); MessageId id = new MessageId(messageDigest.digest());
// If the content type is text/plain, extract a subject line return new MessageImpl(id, parent, group, author, contentType,
String subject;
if(contentType.equals("text/plain")) {
byte[] start = new byte[Math.min(MAX_SUBJECT_LENGTH, body.length)];
System.arraycopy(body, 0, start, 0, start.length);
decoder.reset();
subject = decoder.decode(ByteBuffer.wrap(start)).toString();
} else {
subject = "";
}
return new MessageImpl(id, parent, group, author, contentType, subject,
timestamp, out.toByteArray(), bodyStart, body.length); timestamp, out.toByteArray(), bodyStart, body.length);
} }

View File

@@ -12,13 +12,13 @@ class MessageImpl implements Message {
private final MessageId id, parent; private final MessageId id, parent;
private final Group group; private final Group group;
private final Author author; private final Author author;
private final String contentType, subject; private final String contentType;
private final long timestamp; private final long timestamp;
private final byte[] raw; private final byte[] raw;
private final int bodyStart, bodyLength; private final int bodyStart, bodyLength;
public MessageImpl(MessageId id, MessageId parent, Group group, public MessageImpl(MessageId id, MessageId parent, Group group,
Author author, String contentType, String subject, long timestamp, Author author, String contentType, long timestamp,
byte[] raw, int bodyStart, int bodyLength) { byte[] raw, int bodyStart, int bodyLength) {
if(bodyStart + bodyLength > raw.length) if(bodyStart + bodyLength > raw.length)
throw new IllegalArgumentException(); throw new IllegalArgumentException();
@@ -29,7 +29,6 @@ class MessageImpl implements Message {
this.group = group; this.group = group;
this.author = author; this.author = author;
this.contentType = contentType; this.contentType = contentType;
this.subject = subject;
this.timestamp = timestamp; this.timestamp = timestamp;
this.raw = raw; this.raw = raw;
this.bodyStart = bodyStart; this.bodyStart = bodyStart;
@@ -56,10 +55,6 @@ class MessageImpl implements Message {
return contentType; return contentType;
} }
public String getSubject() {
return subject;
}
public long getTimestamp() { public long getTimestamp() {
return timestamp; return timestamp;
} }

View File

@@ -44,7 +44,7 @@ class MessageVerifierImpl implements MessageVerifier {
throw new GeneralSecurityException(); throw new GeneralSecurityException();
} }
return new MessageImpl(id, m.getParent(), m.getGroup(), author, return new MessageImpl(id, m.getParent(), m.getGroup(), author,
m.getContentType(), m.getSubject(), m.getTimestamp(), raw, m.getContentType(), m.getTimestamp(), raw, m.getBodyStart(),
m.getBodyStart(), m.getBodyLength()); m.getBodyLength());
} }
} }

View File

@@ -1239,7 +1239,6 @@ public class H2DatabaseTest extends BriarTestCase {
if(m.getAuthor() == null) assertNull(h.getAuthor()); if(m.getAuthor() == null) assertNull(h.getAuthor());
else assertEquals(m.getAuthor(), h.getAuthor()); else assertEquals(m.getAuthor(), h.getAuthor());
assertEquals(m.getContentType(), h.getContentType()); assertEquals(m.getContentType(), h.getContentType());
assertEquals(m.getSubject(), h.getSubject());
assertEquals(m.getTimestamp(), h.getTimestamp()); assertEquals(m.getTimestamp(), h.getTimestamp());
} }