tinode/dart-sdk

How to use the library?

XuanTung95 opened this issue · 15 comments

After login, I cannot figure out how to do these things:

  • Get list of topic
  • Find other user
  • Get list message of topic
  • Listen to the incoming message of topic.
  • Listen to the typing message.

Can you add more examples for these?

This library has very few features and I can answer some of your questions. I also hope to work with you to solve some problems with this library.
I've been using this library for about two weeks now, and some of the solutions need to be verified by you
另外你是**人吗?

1:Get list of topic
var me = MySingleton.tinode.getMeTopic();
MySingleton.tinode.onRawMessage.listen((value) {
Get the list of topic here
}
var info = await me.subscribe(im.MetaGetBuilder(me).withLaterSub(null).withDesc(null).withTags().withCred().build(), null);

2:Find other user
Same as the first question,only Need to change here
MySingleton.tinode.getFndTopic();

The third problem, which is in the demo

@c1s1x1 Thank for the info.
After investigate I find that.
1- Get list of topic can use

tinode.getMeTopic().onSubsUpdated.listen((value) {
  for (var item in value) {
    Topic topic = tinode.getTopic(item.topic ?? '');
  }
})

4- Listen to the incoming message of topic. can use

tinode.subscribe(
              topic.name ?? '',
              MetaGetBuilder(me)
                  .withLaterSub(null)
                  .withDesc(null)
                  .withTags()
                  .withCred()
                  .build(),
              SetParams());
topic.onData.listen((DataMessage? value) {
            print("data: ${value?.content}");
          });

5- Listen to the typing message. can use

topic.onInfo.listen((InfoMessage value) {
            print('${value.topic}  ${value.what}');
          });

2 and 3 still have no idea how to do it.

Sorry, I have a problem answering the first question, I should use onSubsUpdated listener.
2:Find other user

var me =tinode.getFndTopic();
tinode.onRawMessage.listen((value) { 
    Find other user 
};
await me.subscribe(
          MetaGetBuilder(me)
          .withLaterSub(null)
          .withDesc(null)
          .withTags()
          .withCred()
          .build(), null);

image
By the way, what country are you from?

The third question I did not understand

I'm from Viet Nam.

  • Get list message of topic: I mean load previous messages from the server. It should be pagination I think.
  • Find other user: I don't understand how to find multiple times with different keywords if you only subscribe one time. There must be other way.
  • Get list message of topic: Well, I don't know how to load previous messages from the server.
  • Find other user: I didn't find a way to search by different keywords.I also need this feature

@c1s1x1 I strongly recommend you to read the Tinode server API document first, then use dart-sdk.

@c1s1x1 I strongly recommend you to read the Tinode server API document first, then use dart-sdk.

老哥,我看过服务器端的文档,后台支持的功能,不代表flutter端就有对应的接口功能啊,肯定是在不改动源码的基础上使用最好。就好比tinodewWeb端支持文件图片传输,flutter端就不支持,必须改源码才可以。
如果你也看过flutter端,能回答一下怎么去创建新topic和添加成员吗?最近卡在这里了

OK so basically we can send all kind of message same as js client,
message type is defined in package-types.dart

const String Hi = 'hi';
const String Acc = 'acc';
const String Login = 'login';
const String Sub = 'sub';
const String Leave = 'leave';
const String Pub = 'pub';
const String Get = 'get';
const String Set = 'set';
const String Del = 'del';
const String Note = 'note';
  • To get of previous messages of topic:
tinode.getMeta(
                        topic.name ?? '',
                        MetaGetBuilder(topic)
                            .withData(
                                null,
                                topic.messages.isEmpty
                                    ? null
                                    : topic.messages.first.seq,
                                20)
                            .build(),
                      );
  • To find other user, which I copy from js:
var res = await tinode.getFndTopic().setMeta(SetParams(
  desc: TopicDescription(
    public: 'keyword',
  )));
res = await tinode.getFndTopic().getMeta(
    MetaGetBuilder(tinode.getFndTopic()).withSub(
        null, null, null).build()
);

@cfanboy Could you post the link to the doc here?

OK so basically we can send all kind of message same as js client,
message type is defined in package-types.dart

const String Hi = 'hi';
const String Acc = 'acc';
const String Login = 'login';
const String Sub = 'sub';
const String Leave = 'leave';
const String Pub = 'pub';
const String Get = 'get';
const String Set = 'set';
const String Del = 'del';
const String Note = 'note';
  • To get of previous messages of topic:
tinode.getMeta(
                        topic.name ?? '',
                        MetaGetBuilder(topic)
                            .withData(
                                null,
                                topic.messages.isEmpty
                                    ? null
                                    : topic.messages.first.seq,
                                20)
                            .build(),
                      );
  • To find other user, which I copy from js:
var res = await tinode.getFndTopic().setMeta(SetParams(
  desc: TopicDescription(
    public: 'keyword',
  )));
res = await tinode.getFndTopic().getMeta(
    MetaGetBuilder(tinode.getFndTopic()).withSub(
        null, null, null).build()
);

@cfanboy Could you post the link to the doc here?

https://github.com/tinode/chat/blob/master/docs/API.md here

I'm from Viet Nam.

  • Get list message of topic: I mean load previous messages from the server. It should be pagination I think.
  • Find other user: I don't understand how to find multiple times with different keywords if you only subscribe one time. There must be other way.

now I can get historical data,but it seems that I have to change the source code

await grp!.subscribe(
        MetaGetBuilder(grp!)
        .withSub(null, null, null)
        .withData(null,null,24)
        .withDesc(this.topicSubscription.touched)
        .build(), null);

It's changed here, but I'm not sure if the change will have any impact
image

image

First time to get historical data without any problem,but When I get the history message for the second time, I get an array out of bounds error
image
image

I think there is a bug here. so,I made a simple change to replace when the exact same message is matched
image

@c1s1x1 这个库,你用的怎么样, 现在有人想找人基于tinode做一个简易的客服系统, 如果有兴趣可以Telegram联系: @miaomiao_c