diff --git a/mobile/messages.go b/mobile/messages.go index c950266e..ee8754d6 100644 --- a/mobile/messages.go +++ b/mobile/messages.go @@ -39,3 +39,17 @@ func (m *Mobile) Messages(offset string, limit int, threadId string) ([]byte, er return proto.Marshal(msgs) } + +// Message calls core Message +func (m *Mobile) Message(blockId string) ([]byte, error) { + if !m.node.Started() { + return nil, core.ErrStopped + } + + msg, err := m.node.Message(blockId) + if err != nil { + return nil, err + } + + return proto.Marshal(msg) +} diff --git a/mobile/mobile_test.go b/mobile/mobile_test.go index 8c4fac30..77bfbe5f 100644 --- a/mobile/mobile_test.go +++ b/mobile/mobile_test.go @@ -28,12 +28,13 @@ var testVars = struct { mobile1 *Mobile mobile2 *Mobile - thrdId string - dir []byte - filesBlock *pb.Block - files []*pb.Files - invite *pb.ExternalInvite - avatar string + thrdId string + dir []byte + filesBlock *pb.Block + files []*pb.Files + invite *pb.ExternalInvite + avatar string + messageBlockId string }{ initConfig1: InitConfig{ BaseRepoPath: "testdata/.textile1", @@ -420,10 +421,11 @@ func TestMobile_RemoveThread(t *testing.T) { } func TestMobile_AddMessage(t *testing.T) { - _, err := testVars.mobile1.AddMessage(testVars.thrdId, "ping pong") + blockId, err := testVars.mobile1.AddMessage(testVars.thrdId, "ping pong") if err != nil { t.Fatalf("add thread message failed: %s", err) } + testVars.messageBlockId = blockId } func TestMobile_Messages(t *testing.T) { @@ -441,6 +443,21 @@ func TestMobile_Messages(t *testing.T) { } } +func TestMobile_Message(t *testing.T) { + res, err := testVars.mobile1.Message(testVars.messageBlockId) + if err != nil { + t.Fatalf("thread message failed: %s", err) + } + text := new(pb.Text) + err = proto.Unmarshal(res, text) + if err != nil { + t.Fatal(err) + } + if text.GetBlock() != testVars.messageBlockId { + t.Fatal("wrong block id") + } +} + func TestMobile_AddData(t *testing.T) { input := "howdy"