Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

activity: self activity should change recency #3626

Merged
merged 1 commit into from
Jun 25, 2024
Merged
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
8 changes: 4 additions & 4 deletions apps/tlon-web/src/chat/ChatInput/ChatInput.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as Popover from '@radix-ui/react-popover';
import { Editor } from '@tiptap/react';
import { getKey } from '@tloncorp/shared/dist/urbit/activity';
import { getKey, getThreadKey } from '@tloncorp/shared/dist/urbit/activity';
import {
CacheId,
Cite,
Expand Down Expand Up @@ -61,7 +61,6 @@ import {
useIsDmOrMultiDm,
useThreadParentId,
} from '@/logic/utils';
import { useMyLastMessage } from '@/state/channel/channel';
import {
SendMessageVariables,
SendReplyVariables,
Expand Down Expand Up @@ -393,8 +392,9 @@ export default function ChatInput({
onUpdate.current.flush();
setDraft(inlinesToJSON(['']));
setTimeout(() => {
// TODO: chesterton's fence, but why execute a read here?
useUnreadsStore.getState().read(getKey(whom));
const key = replying ? getThreadKey(whom, replying) : getKey(whom);
useUnreadsStore.getState().read(key);
useUnreadsStore.getState().bump(key);
clearAttachments();
}, 0);
},
Expand Down
21 changes: 19 additions & 2 deletions apps/tlon-web/src/state/unreads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ export interface UnreadsStore {
sources: Unreads;
seen: (whom: string) => void;
read: (whom: string) => void;
delayedRead: (whom: string, callback: () => void) => void;
bump: (whom: string) => void;
update: (unreads: Activity) => void;
delayedRead: (whom: string, callback: () => void) => void;
}

export const unreadStoreLogger = createDevLogger('UnreadsStore', false);
export const unreadStoreLogger = createDevLogger('UnreadsStore', true);

function getUnreadStatus(count: number, notify: boolean): ReadStatus {
if (count > 0 || notify) {
Expand Down Expand Up @@ -338,6 +339,22 @@ export const useUnreadsStore = create<UnreadsStore>((set, get) => ({
})
);
},
bump: (key) => {
set(
produce((draft: UnreadsStore) => {
const source = draft.sources[key];
if (!source) {
return;
}

unreadStoreLogger.log('bump', key);
draft.sources[key] = {
...source,
recency: Date.now(),
};
})
);
},
delayedRead: (key, cb) => {
const { sources, read } = get();
const source = sources[key] || emptyUnread();
Expand Down
3 changes: 2 additions & 1 deletion desk/app/activity.hoon
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,7 @@
::
%all
|= =index:a
?^ time.action index(reads [u.time.action ~])
=/ latest=(unit [=time event:a])
::REVIEW is this taking the item from the correct end? lol
(ram:on-event:a stream.index)
Expand Down Expand Up @@ -846,7 +847,7 @@
|(is-msg ?=(?(%dm-invite %chan-init) -<.event))
?. supported $(stream rest)
=? notified &(notify.volume notified.event) &
=. newest time
=? newest (gth time newest) time
?. &(unreads.volume ?=(?(%dm-post %dm-reply %post %reply) -<.event))
$(stream rest)
=. total +(total)
Expand Down
10 changes: 7 additions & 3 deletions desk/app/channels.hoon
Original file line number Diff line number Diff line change
Expand Up @@ -743,15 +743,20 @@
++ on-post
|= v-post:c
^+ ca-core
?: =(author our.bowl) ca-core
?: =(author our.bowl)
=/ =source [%channel nest group.perm.perm.channel]
(send ~[`action`[%read source [%all `now.bowl]]])
=/ mention=? (was-mentioned:utils content our.bowl)
=/ action
[%add %post [[author id] id] nest group.perm.perm.channel content mention]
(send ~[action])
++ on-reply
|= [parent=v-post:c v-reply:c]
^+ ca-core
?: =(author our.bowl) ca-core
=/ parent-key=message-key [[author id]:parent id.parent]
?: =(author our.bowl)
=/ =source [%thread parent-key nest group.perm.perm.channel]
(send ~[`action`[%read source [%all `now.bowl]]])
=/ mention=? (was-mentioned:utils content our.bowl)
=/ in-replies
%+ lien (tap:on-v-replies:c replies.parent)
Expand All @@ -760,7 +765,6 @@
=(author.u.reply our.bowl)
=/ =path (scry-path %activity /volume-settings/noun)
=+ .^(settings=volume-settings %gx path)
=/ parent-key=message-key [[author id]:parent id.parent]
=/ =action
:* %add %reply
[[author id] id]
Expand Down
13 changes: 8 additions & 5 deletions desk/app/chat.hoon
Original file line number Diff line number Diff line change
Expand Up @@ -773,16 +773,19 @@
mention=?
==
^+ cor
?: ?& ?=(?(%post %reply) -.concern)
.= our.bowl
p.id:?-(-.concern %post key.concern, %reply key.concern)
==
cor
?. .^(? %gu /(scot %p our.bowl)/activity/(scot %da now.bowl)/$)
cor
%- emit
=; =cage
[%pass /activity/submit %agent [our.bowl %activity] %poke cage]
?: ?& ?=(?(%post %reply) -.concern)
.= our.bowl
p.id:?-(-.concern %post key.concern, %reply key.concern)
==
=/ =source
?: ?=(%post -.concern) [%dm whom]
[%dm-thread top.concern whom]
activity-action+!>(`action`[%read source [%all `now.bowl]])
:- %activity-action
!> ^- action
:- %add
Expand Down
2 changes: 1 addition & 1 deletion desk/sur/activity.hoon
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
+$ read-action
$% [%item id=time-id]
[%event event=incoming-event]
[%all ~]
[%all time=(unit time)]
==
::
+| %updates
Expand Down