replyGetData is a response to a get.data request - load a list of stored messages, send them to session as {data} response goes to a single session rather than all sessions in a topic
(sess *Session, id string, req *MsgBrowseOpts)
| 898 | // replyGetData is a response to a get.data request - load a list of stored messages, send them to session as {data} |
| 899 | // response goes to a single session rather than all sessions in a topic |
| 900 | func (t *Topic) replyGetData(sess *Session, id string, req *MsgBrowseOpts) error { |
| 901 | now := time.Now().UTC().Round(time.Millisecond) |
| 902 | |
| 903 | opts := msgOpts2storeOpts(req, sess.tag, t.perUser[sess.uid].lastSeenTag[sess.tag]) |
| 904 | |
| 905 | messages, err := store.Messages.GetAll(sess.appid, t.name, opts) |
| 906 | if err != nil { |
| 907 | log.Println("topic: error loading topics ", err) |
| 908 | reply := ErrUnknown(id, t.original, now) |
| 909 | simpleByteSender(sess.send, reply) |
| 910 | return err |
| 911 | } |
| 912 | log.Println("Loaded messages ", len(messages)) |
| 913 | |
| 914 | // Push the list of updated topics to the client as data messages |
| 915 | if messages != nil { |
| 916 | for _, mm := range messages { |
| 917 | from := types.ParseUid(mm.From) |
| 918 | msg := &ServerComMessage{Data: &MsgServerData{ |
| 919 | Topic: t.original, |
| 920 | From: from.UserId(), |
| 921 | Timestamp: mm.CreatedAt, |
| 922 | Content: mm.Content}} |
| 923 | simpleByteSender(sess.send, msg) |
| 924 | } |
| 925 | } |
| 926 | |
| 927 | return nil |
| 928 | } |
| 929 | |
| 930 | func (t *Topic) makeInvite(notify, target, from types.Uid, act types.InviteAction, modeWant, |
| 931 | modeGiven types.AccessMode, info interface{}) *ServerComMessage { |
no test coverage detected