Android UI for blogs (restricted groups).

This commit is contained in:
akwizgran
2013-03-23 14:30:59 +00:00
parent d5879df6eb
commit 4e5366509d
24 changed files with 168 additions and 65 deletions

View File

@@ -287,10 +287,8 @@ DatabaseCleaner.Callback {
} finally {
contactLock.readLock().unlock();
}
if(added) {
GroupId g = m.getGroup().getId();
callListeners(new GroupMessageAddedEvent(g, false));
}
if(added)
callListeners(new GroupMessageAddedEvent(m.getGroup(), false));
}
/**
@@ -1357,7 +1355,7 @@ DatabaseCleaner.Callback {
if(added) {
Group g = m.getGroup();
if(g == null) callListeners(new PrivateMessageAddedEvent(c, true));
else callListeners(new GroupMessageAddedEvent(g.getId(), true));
else callListeners(new GroupMessageAddedEvent(g, true));
}
}
@@ -1855,7 +1853,7 @@ DatabaseCleaner.Callback {
return added;
}
public void unsubscribe(GroupId g) throws DbException {
public void unsubscribe(Group g) throws DbException {
Collection<ContactId> affected;
messageLock.writeLock().lock();
try {
@@ -1863,10 +1861,11 @@ DatabaseCleaner.Callback {
try {
T txn = db.startTransaction();
try {
if(!db.containsSubscription(txn, g))
GroupId id = g.getId();
if(!db.containsSubscription(txn, id))
throw new NoSuchSubscriptionException();
affected = db.getVisibility(txn, g);
db.removeSubscription(txn, g);
affected = db.getVisibility(txn, id);
db.removeSubscription(txn, id);
db.commitTransaction(txn);
} catch(DbException e) {
db.abortTransaction(txn);

View File

@@ -823,7 +823,8 @@ abstract class JdbcDatabase implements Database<Connection> {
ps = txn.prepareStatement(sql);
ps.setBytes(1, g.getId().getBytes());
ps.setString(2, g.getName());
ps.setBytes(3, g.getPublicKey());
if(g.isRestricted()) ps.setBytes(3, g.getPublicKey());
else ps.setNull(3, BINARY);
int affected = ps.executeUpdate();
if(affected != 1) throw new DbStateException();
ps.close();
@@ -3029,9 +3030,8 @@ abstract class JdbcDatabase implements Database<Connection> {
for(Group g : subs) {
ps.setBytes(2, g.getId().getBytes());
ps.setString(3, g.getName());
byte[] key = g.getPublicKey();
if(key == null) ps.setNull(4, BINARY);
else ps.setBytes(4, key);
if(g.isRestricted()) ps.setBytes(4, g.getPublicKey());
else ps.setNull(4, BINARY);
ps.addBatch();
}
int[] affectedBatch = ps.executeBatch();

View File

@@ -99,8 +99,7 @@ class MessageFactoryImpl implements MessageFactory {
// Validate the arguments
if((author == null) != (authorKey == null))
throw new IllegalArgumentException();
if((group == null || group.getPublicKey() == null)
!= (groupKey == null))
if((group == null || !group.isRestricted()) != (groupKey == null))
throw new IllegalArgumentException();
if(contentType.getBytes("UTF-8").length > MAX_CONTENT_TYPE_LENGTH)
throw new IllegalArgumentException();
@@ -182,9 +181,8 @@ class MessageFactoryImpl implements MessageFactory {
private void writeGroup(Writer w, Group g) throws IOException {
w.writeStructId(GROUP);
w.writeString(g.getName());
byte[] publicKey = g.getPublicKey();
if(publicKey == null) w.writeNull();
else w.writeBytes(publicKey);
if(g.isRestricted()) w.writeBytes(g.getPublicKey());
else w.writeNull();
}
private void writeAuthor(Writer w, Author a) throws IOException {

View File

@@ -93,7 +93,7 @@ class MessageReader implements StructReader<UnverifiedMessage> {
int signedByGroup = (int) counting.getCount();
// Read the group's signature, if there is one
byte[] groupSig = null;
if(group == null || group.getPublicKey() == null) r.readNull();
if(group == null || !group.isRestricted()) r.readNull();
else groupSig = r.readBytes(MAX_SIGNATURE_LENGTH);
// That's all, folks
r.removeConsumer(counting);

View File

@@ -46,7 +46,7 @@ class MessageVerifierImpl implements MessageVerifier {
}
// Verify the group's signature, if there is one
Group group = m.getGroup();
if(group != null && group.getPublicKey() != null) {
if(group != null && group.isRestricted()) {
PublicKey k = keyParser.parsePublicKey(group.getPublicKey());
signature.initVerify(k);
signature.update(raw, 0, m.getLengthSignedByGroup());

View File

@@ -133,9 +133,8 @@ class PacketWriterImpl implements PacketWriter {
for(Group g : u.getGroups()) {
w.writeStructId(GROUP);
w.writeString(g.getName());
byte[] publicKey = g.getPublicKey();
if(publicKey == null) w.writeNull();
else w.writeBytes(publicKey);
if(g.isRestricted()) w.writeBytes(g.getPublicKey());
else w.writeNull();
}
w.writeListEnd();
w.writeInt64(u.getVersion());