mirror of
https://github.com/ilyakooo0/urbit.git
synced 2024-12-01 11:33:41 +03:00
chat: reversed order that messages are stored in for faster performance
This commit is contained in:
parent
eef6e56dca
commit
ecc8942eaf
@ -408,41 +408,15 @@
|
||||
?> (~(has by synced) pas)
|
||||
:: check if read is permitted
|
||||
?> (is-permitted src.bol pas)
|
||||
=/ =mailbox (need (chat-scry pas))
|
||||
=* envs envelopes.mailbox
|
||||
%- zing
|
||||
:~ [%give %fact ~ %chat-update !>([%create pas])]~
|
||||
?. ?&(?=(^ backlog-start) (~(has by allow-history) pas)) ~
|
||||
(paginate-messages pas (need (chat-scry pas)) u.backlog-start)
|
||||
[%give %fact ~ %chat-update !>([%messages pas 0 (lent envs) envs])]~
|
||||
[%give %kick [%backlog pax]~ `src.bol]~
|
||||
==
|
||||
::
|
||||
++ paginate-messages
|
||||
|= [=path =mailbox start=@ud]
|
||||
^- (list card)
|
||||
=/ cards=(list card) ~
|
||||
=/ end (lent envelopes.mailbox)
|
||||
?: |((gte start end) =(end 0))
|
||||
cards
|
||||
=. envelopes.mailbox (slag start `(list envelope)`envelopes.mailbox)
|
||||
|- ^- (list card)
|
||||
?~ envelopes.mailbox
|
||||
cards
|
||||
?: (lte end 5.000)
|
||||
=. cards
|
||||
%+ snoc cards
|
||||
%- messages-fact
|
||||
[path start (lent envelopes.mailbox) envelopes.mailbox]
|
||||
$(envelopes.mailbox ~)
|
||||
=. cards
|
||||
%+ snoc cards
|
||||
%- messages-fact
|
||||
:^ path start
|
||||
(add start 5.000)
|
||||
(scag 5.000 `(list envelope)`envelopes.mailbox)
|
||||
=: start (add start 5.000)
|
||||
end (sub end 5.000)
|
||||
==
|
||||
$(envelopes.mailbox (slag 5.000 `(list envelope)`envelopes.mailbox))
|
||||
::
|
||||
++ fact-invite-update
|
||||
|= [wir=wire fact=invite-update]
|
||||
^- (quip card _state)
|
||||
@ -644,11 +618,6 @@
|
||||
^- card
|
||||
[%pass / %agent [our.bol %invite-store] %poke %invite-action !>(act)]
|
||||
::
|
||||
++ messages-fact
|
||||
|= [=path start=@ud end=@ud envelopes=(list envelope)]
|
||||
^- card
|
||||
[%give %fact ~ %chat-update !>([%messages path start end envelopes])]
|
||||
::
|
||||
++ sec-to-perm
|
||||
|= [pax=path =kind]
|
||||
^- permission-action
|
||||
|
@ -7,10 +7,12 @@
|
||||
+$ versioned-state
|
||||
$% state-zero
|
||||
state-one
|
||||
state-two
|
||||
==
|
||||
::
|
||||
+$ state-zero [%0 =inbox]
|
||||
+$ state-one [%1 =inbox]
|
||||
+$ state-two [%2 =inbox]
|
||||
::
|
||||
+$ diff
|
||||
$% [%chat-initial inbox]
|
||||
@ -19,7 +21,7 @@
|
||||
==
|
||||
--
|
||||
::
|
||||
=| state-one
|
||||
=| state-two
|
||||
=* state -
|
||||
::
|
||||
%- agent:dbug
|
||||
@ -38,10 +40,14 @@
|
||||
++ on-load
|
||||
|= old-vase=vase
|
||||
=/ old !<(versioned-state old-vase)
|
||||
?: ?=(%1 -.old)
|
||||
?: ?=(%2 -.old)
|
||||
[~ this(state old)]
|
||||
:_ this(state [%1 inbox.old])
|
||||
[%pass /lo-chst %agent [our.bowl %chat-hook] %poke %noun !>(%store-load)]~
|
||||
=/ reversed-inbox=^inbox
|
||||
%- ~(run by inbox.old)
|
||||
|= =mailbox
|
||||
^- ^mailbox
|
||||
[config.mailbox (flop envelopes.mailbox)]
|
||||
[~ this(state [%2 reversed-inbox])]
|
||||
::
|
||||
++ on-poke
|
||||
~/ %chat-store-poke
|
||||
@ -188,6 +194,7 @@
|
||||
:- (send-diff path.act act)
|
||||
state(inbox (~(del by inbox) path.act))
|
||||
::
|
||||
|
||||
++ handle-message
|
||||
|= act=chat-action
|
||||
^- (quip card _state)
|
||||
@ -196,7 +203,7 @@
|
||||
?~ mailbox
|
||||
[~ state]
|
||||
=. letter.envelope.act (evaluate-letter [author letter]:envelope.act)
|
||||
=^ envelope u.mailbox (append-envelope u.mailbox envelope.act)
|
||||
=^ envelope u.mailbox (prepend-envelope u.mailbox envelope.act)
|
||||
:- (send-diff path.act act(envelope envelope))
|
||||
state(inbox (~(put by inbox) path.act u.mailbox))
|
||||
::
|
||||
@ -212,15 +219,10 @@
|
||||
?~ envelopes.act
|
||||
:_ state(inbox (~(put by inbox) path.act u.mailbox))
|
||||
%+ send-diff path.act
|
||||
:* %messages
|
||||
path.act
|
||||
(sub length.config.u.mailbox (lent evaluated-envelopes))
|
||||
length.config.u.mailbox
|
||||
evaluated-envelopes
|
||||
==
|
||||
[%messages path.act 0 (lent evaluated-envelopes) evaluated-envelopes]
|
||||
=. letter.i.envelopes.act (evaluate-letter [author letter]:i.envelopes.act)
|
||||
=^ envelope u.mailbox (append-envelope u.mailbox i.envelopes.act)
|
||||
=. evaluated-envelopes (snoc evaluated-envelopes envelope)
|
||||
=^ envelope u.mailbox (prepend-envelope u.mailbox i.envelopes.act)
|
||||
=. evaluated-envelopes [envelope evaluated-envelopes]
|
||||
$(envelopes.act t.envelopes.act)
|
||||
::
|
||||
++ handle-read
|
||||
@ -246,12 +248,12 @@
|
||||
letter(output (eval bol hoon))
|
||||
letter
|
||||
::
|
||||
++ append-envelope
|
||||
++ prepend-envelope
|
||||
|= [=mailbox =envelope]
|
||||
^+ [envelope mailbox]
|
||||
=. number.envelope +(length.config.mailbox)
|
||||
=: length.config.mailbox +(length.config.mailbox)
|
||||
envelopes.mailbox (snoc envelopes.mailbox envelope)
|
||||
envelopes.mailbox [envelope envelopes.mailbox]
|
||||
==
|
||||
[envelope mailbox]
|
||||
::
|
||||
|
@ -126,10 +126,9 @@
|
||||
++ truncate-envelopes
|
||||
|= envelopes=(list envelope)
|
||||
^- (list envelope)
|
||||
=/ length (lent envelopes)
|
||||
?: (lth length message-limit)
|
||||
?: (lth (lent envelopes) message-limit)
|
||||
envelopes
|
||||
(slag (sub length message-limit) envelopes)
|
||||
(scag message-limit envelopes)
|
||||
--
|
||||
::
|
||||
++ on-agent
|
||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -107,9 +107,9 @@ export class ChatScreen extends Component {
|
||||
return;
|
||||
}
|
||||
|
||||
let end = props.envelopes[0].number;
|
||||
let start = props.envelopes[props.envelopes.length - 1].number;
|
||||
if (end > 0) {
|
||||
let start = end - 400 > 0 ? end - 400 : 0;
|
||||
let end = start + 400 < props.length ? start + 400 : props.length;
|
||||
|
||||
if (start === 0 && end === 1) {
|
||||
return;
|
||||
@ -182,36 +182,29 @@ export class ChatScreen extends Component {
|
||||
const { props, state } = this;
|
||||
|
||||
let messages = props.envelopes.slice(0);
|
||||
|
||||
let lastMsgNum = messages.length > 0 ? messages.length : 0;
|
||||
|
||||
if (messages.length > 100 * state.numPages) {
|
||||
messages = messages.slice(
|
||||
messages.length - 100 * state.numPages,
|
||||
messages.length
|
||||
);
|
||||
messages = messages.slice(0, 100 * state.numPages);
|
||||
}
|
||||
|
||||
let pendingMessages = props.pendingMessages.has(props.station)
|
||||
? props.pendingMessages.get(props.station)
|
||||
? props.pendingMessages.get(props.station).reverse()
|
||||
: [];
|
||||
|
||||
pendingMessages.map(function(value) {
|
||||
return (value.pending = true);
|
||||
});
|
||||
|
||||
let reversedMessages = messages.concat(pendingMessages);
|
||||
reversedMessages = reversedMessages.reverse();
|
||||
|
||||
reversedMessages = reversedMessages.map((msg, i) => {
|
||||
let messageElements = pendingMessages.concat(messages).map((msg, i) => {
|
||||
// Render sigil if previous message is not by the same sender
|
||||
let aut = ["author"];
|
||||
let renderSigil =
|
||||
_.get(reversedMessages[i + 1], aut) !==
|
||||
_.get(messages[i + 1], aut) !==
|
||||
_.get(msg, aut, msg.author);
|
||||
let paddingTop = renderSigil;
|
||||
let paddingBot =
|
||||
_.get(reversedMessages[i - 1], aut) !==
|
||||
_.get(messages[i - 1], aut) !==
|
||||
_.get(msg, aut, msg.author);
|
||||
|
||||
return (
|
||||
@ -288,7 +281,7 @@ export class ChatScreen extends Component {
|
||||
}}></div>
|
||||
{ (
|
||||
!(props.station in props.chatSynced) &&
|
||||
(reversedMessages.length > 0)
|
||||
(messages.length > 0)
|
||||
) ? (
|
||||
<ResubscribeElement
|
||||
api={props.api}
|
||||
@ -296,7 +289,7 @@ export class ChatScreen extends Component {
|
||||
station={props.station} />
|
||||
) : (<div/>)
|
||||
}
|
||||
{reversedMessages}
|
||||
{messageElements}
|
||||
</div>
|
||||
<ChatInput
|
||||
api={props.api}
|
||||
|
@ -17,7 +17,7 @@ export class ChatUpdateReducer {
|
||||
message(json, state) {
|
||||
let data = _.get(json, 'message', false);
|
||||
if (data) {
|
||||
state.inbox[data.path].envelopes.push(data.envelope);
|
||||
state.inbox[data.path].envelopes.unshift(data.envelope);
|
||||
state.inbox[data.path].config.length
|
||||
= state.inbox[data.path].config.length + 1;
|
||||
}
|
||||
@ -27,7 +27,7 @@ export class ChatUpdateReducer {
|
||||
let data = _.get(json, 'messages', false);
|
||||
if (data) {
|
||||
state.inbox[data.path].envelopes =
|
||||
data.envelopes.concat(state.inbox[data.path].envelopes);
|
||||
state.inbox[data.path].envelopes.concat(data.envelopes);
|
||||
state.inbox[data.path].config.length =
|
||||
state.inbox[data.path].config.length + data.envelopes.length;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user