Skip to content
This repository has been archived by the owner on Mar 12, 2020. It is now read-only.

Add method to get a single message #945

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions mobile/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
31 changes: 24 additions & 7 deletions mobile/mobile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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) {
Expand All @@ -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"

Expand Down