add channel to demo data and init-db

This commit is contained in:
or-else
2020-08-27 15:54:12 -07:00
parent 7599f2c7da
commit d6ac845a5e
4 changed files with 57 additions and 9 deletions

View File

@ -72,7 +72,7 @@ When you register a new account you are asked for an email address to send valid
* [Web](https://github.com/tinode/webapp/)
* Scriptable [command line](tn-cli/)
* One-on-one and group messaging.
* Channels with an unlimited number (or hundreds of thousands) of members.
* Channels with an unlimited number of members.
* Sharded clustering with failover.
* Flexible access control with permissions for various actions.
* Server-generated presence notifications for people, group chats.

View File

@ -148,6 +148,15 @@
"tags": ["support","public"],
"public": {"fn": "Support", "photo": "support-128.jpg", "type": "jpg"},
"access": {"auth": "JRWP", "anon": "JW"}
},
{
"createdAt": "-122h",
"name": "*BACDF",
"owner": "bob",
"channel": true,
"tags": ["coffee","channel"],
"public": {"fn": "Coffee Channel", "photo": "chan-128.jpg", "type": "jpg"},
"access": {"auth": "N", "anon": "N"}
}
],
"p2psubs": [
@ -253,6 +262,29 @@
"private": {"comment": "I'm not the owner, Frank is"},
"topic": "*BF",
"user": "bob"
},
{
"createdAt": "-111.2h",
"topic": "*BACDF",
"user": "alice"
},
{
"createdAt": "-111.1h",
"topic": "*BACDF",
"asChan": true,
"user": "carol"
},
{
"createdAt": "-111.0h",
"topic": "*BACDF",
"asChan": true,
"user": "dave"
},
{
"createdAt": "-110.8h",
"topic": "*BACDF",
"asChan": true,
"user": "frank"
}
],
"messages": [

View File

@ -146,6 +146,7 @@ func genDb(data *Data) {
Auth: accessAuth,
Anon: accessAnon,
},
UseBt: gt.Channel,
Tags: gt.Tags,
Public: parsePublic(&gt.Public, data.datapath)}
var owner types.Uid
@ -234,9 +235,14 @@ func genDb(data *Data) {
log.Println("Generating group subscriptions...")
for _, ss := range data.Groupsubs {
want := types.ModeCPublic
given := types.ModeCPublic
var want, given types.AccessMode
if ss.AsChan {
want = types.ModeCChn
given = types.ModeCChn
} else {
want = types.ModeCPublic
given = types.ModeCPublic
}
if ss.Want != "" {
if err := want.UnmarshalText([]byte(ss.Want)); err != nil {
log.Fatal(err)
@ -247,11 +253,14 @@ func genDb(data *Data) {
log.Fatal(err)
}
}
tname := nameIndex[ss.Topic]
if ss.AsChan {
tname = types.GrpToChn(tname)
}
if err = store.Subs.Create(&types.Subscription{
ObjHeader: types.ObjHeader{CreatedAt: getCreatedTime(ss.CreatedAt)},
User: nameIndex[ss.User],
Topic: nameIndex[ss.Topic],
Topic: tname,
ModeWant: want,
ModeGiven: given,
Private: ss.Private}); err != nil {
@ -288,6 +297,10 @@ func genDb(data *Data) {
var topic string
var from types.Uid
if subIdx < len(data.Groupsubs) {
if data.Groupsubs[subIdx].AsChan {
// Channel readers should not have any published messages.
continue
}
topic = nameIndex[data.Groupsubs[subIdx].Topic]
from = types.ParseUid(nameIndex[data.Groupsubs[subIdx].User])
} else {

View File

@ -81,12 +81,14 @@ GroupTopic object in data.json
"createdAt": "-128h",
"name": "*ABC",
"owner": "carol",
"channel": true,
"public": {"fn": "Let's talk about flowers", "photo": "abc-64.jpg", "type": "jpg"}
*/
type GroupTopic struct {
CreatedAt string `json:"createdAt"`
Name string `json:"name"`
Owner string `json:"owner"`
Channel bool `json:"channel"`
Public vCardy `json:"public"`
Access DefAccess `json:"access"`
Tags []string `json:"tags"`
@ -99,16 +101,17 @@ GroupSub object in data.json
"createdAt": "-112h",
"private": "My super cool group topic",
"topic": "*ABC",
"user": "alice"
"user": "alice",
"asChan: false,
"want": "JRWPSA",
"have": "JRWP",
"tags": ["super cool", "super", "cool"],
"have": "JRWP"
*/
type GroupSub struct {
CreatedAt string `json:"createdAt"`
Private tPrivate `json:"private"`
Topic string `json:"topic"`
User string `json:"user"`
AsChan bool `json:"asChan"`
Want string `json:"want"`
Have string `json:"have"`
}