-
-
Notifications
You must be signed in to change notification settings - Fork 672
Use recent_private_conversations on PMs screen, when available #4104
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
Changes from all commits
df57102
deac44e
e665047
7c70e3d
ae35faa
7529da2
c95cd36
fcc3b53
beebd5e
3441017
d36e1c0
eb119f5
c753f0a
ae7db07
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,7 @@ import deepFreeze from 'deep-freeze'; | |
| import { createStore } from 'redux'; | ||
|
|
||
| import type { CrossRealmBot, Message, PmRecipientUser, Stream, User } from '../../api/modelTypes'; | ||
| import type { Action, GlobalState, RealmState } from '../../reduxTypes'; | ||
| import type { Action, GlobalState, MessagesState, RealmState } from '../../reduxTypes'; | ||
| import type { Auth, Account, Outbox } from '../../types'; | ||
| import { ZulipVersion } from '../../utils/zulipVersion'; | ||
| import { | ||
|
|
@@ -16,6 +16,8 @@ import { | |
| import rootReducer from '../../boot/reducers'; | ||
| import { authOfAccount } from '../../account/accountMisc'; | ||
| import { HOME_NARROW } from '../../utils/narrow'; | ||
| import { NULL_OBJECT } from '../../nullObjects'; | ||
| import { objectFromEntries } from '../../jsBackport'; | ||
|
|
||
| /* ======================================================================== | ||
| * Utilities | ||
|
|
@@ -73,8 +75,13 @@ export const randString = () => randInt(2 ** 54).toString(36); | |
| * Users and bots | ||
| */ | ||
|
|
||
| type UserOrBotPropertiesArgs = {| | ||
| name?: string, | ||
| user_id?: number, | ||
| |}; | ||
|
|
||
| const randUserId: () => number = makeUniqueRandInt('user IDs', 10000); | ||
| const userOrBotProperties = ({ name: _name }) => { | ||
| const userOrBotProperties = ({ name: _name, user_id }: UserOrBotPropertiesArgs) => { | ||
| const name = _name ?? randString(); | ||
| const capsName = name.substring(0, 1).toUpperCase() + name.substring(1); | ||
| return deepFreeze({ | ||
|
|
@@ -88,12 +95,12 @@ const userOrBotProperties = ({ name: _name }) => { | |
| full_name: `${capsName} User`, | ||
| is_admin: false, | ||
| timezone: 'UTC', | ||
| user_id: randUserId(), | ||
| user_id: user_id ?? randUserId(), | ||
| }); | ||
| }; | ||
|
|
||
| /** Beware! These values may not be representative. */ | ||
| export const makeUser = (args: { name?: string } = {}): User => | ||
| export const makeUser = (args: UserOrBotPropertiesArgs = NULL_OBJECT): User => | ||
| deepFreeze({ | ||
| ...userOrBotProperties(args), | ||
|
|
||
|
|
@@ -107,7 +114,7 @@ export const makeUser = (args: { name?: string } = {}): User => | |
| }); | ||
|
|
||
| /** Beware! These values may not be representative. */ | ||
| export const makeCrossRealmBot = (args: { name?: string } = {}): CrossRealmBot => | ||
|
gnprice marked this conversation as resolved.
|
||
| export const makeCrossRealmBot = (args: UserOrBotPropertiesArgs = NULL_OBJECT): CrossRealmBot => | ||
| deepFreeze({ | ||
| ...userOrBotProperties(args), | ||
| is_bot: true, | ||
|
|
@@ -182,16 +189,17 @@ export const stream: Stream = makeStream({ | |
| * Messages | ||
| */ | ||
|
|
||
| const displayRecipientFromUser = (user: User): PmRecipientUser => { | ||
| const { email, full_name, user_id: id } = user; | ||
| return deepFreeze({ | ||
| email, | ||
| full_name, | ||
| id, | ||
| is_mirror_dummy: false, | ||
| short_name: '', // what is this, anyway? | ||
| const displayRecipientFromUsers = (users: User[]): PmRecipientUser[] => | ||
| users.map(user => { | ||
|
gnprice marked this conversation as resolved.
|
||
| const { email, full_name, user_id: id } = user; | ||
| return deepFreeze({ | ||
| email, | ||
| full_name, | ||
| id, | ||
| is_mirror_dummy: false, | ||
| short_name: '', // what is this, anyway? | ||
| }); | ||
| }); | ||
| }; | ||
|
|
||
| /** Boring properties common to all example Message objects. */ | ||
| const messagePropertiesBase = deepFreeze({ | ||
|
|
@@ -233,14 +241,14 @@ const messagePropertiesFromSender = (user: User) => { | |
| }; | ||
|
|
||
| /** Beware! These values may not be representative. */ | ||
| export const pmMessage = (extra?: $Rest<Message, {}>): Message => { | ||
| export const pmMessageFromTo = (from: User, to: User[], extra?: $Rest<Message, {}>): Message => { | ||
| const baseMessage: Message = { | ||
| ...messagePropertiesBase, | ||
| ...messagePropertiesFromSender(otherUser), | ||
| ...messagePropertiesFromSender(from), | ||
|
|
||
| content: 'This is an example PM message.', | ||
| content_type: 'text/markdown', | ||
| display_recipient: [displayRecipientFromUser(selfUser)], | ||
| display_recipient: displayRecipientFromUsers([from, ...to]), | ||
| id: 1234567, | ||
| recipient_id: 2342, | ||
| stream_id: -1, | ||
|
|
@@ -252,6 +260,9 @@ export const pmMessage = (extra?: $Rest<Message, {}>): Message => { | |
| return deepFreeze({ ...baseMessage, ...extra }); | ||
| }; | ||
|
|
||
| export const pmMessage = (extra?: $Rest<Message, {}>): Message => | ||
| pmMessageFromTo(selfUser, [otherUser], extra); | ||
|
gnprice marked this conversation as resolved.
|
||
|
|
||
| const messagePropertiesFromStream = (stream1: Stream) => { | ||
| const { stream_id, name: display_recipient } = stream1; | ||
| return deepFreeze({ | ||
|
|
@@ -279,6 +290,13 @@ export const streamMessage = (extra?: $Rest<Message, {}>): Message => { | |
| return deepFreeze({ ...baseMessage, ...extra }); | ||
| }; | ||
|
|
||
| /** Construct a MessagesState from a list of messages. */ | ||
| export const makeMessagesState = (messages: Message[]): MessagesState => { | ||
| const state: { [id: number]: Message } = objectFromEntries(messages.map(m => [m.id, m])); | ||
| // exact object + indexer properties issue; fixed in v0.111.0 | ||
| return (state: $FlowFixMe); | ||
|
Comment on lines
+296
to
+297
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This catches my eye because When I remove the fixme, one thing I notice is there are actually two errors here -- and one of them isn't related to that Flow bug, I think, but comes from the fact that (a) I'd feel better if this were explicit about what kind of type difference it's meant to launder. If e.g. this line were to spell out what the |
||
| }; | ||
|
|
||
| /* ======================================================================== | ||
| * Outbox messages | ||
| * | ||
|
|
@@ -424,6 +442,7 @@ export const action = deepFreeze({ | |
| realm_users: [], | ||
| user_id: 4, | ||
| realm_user_groups: [], | ||
| recent_private_conversations: [], | ||
| streams: [], | ||
| never_subscribed: [], | ||
| subscriptions: [], | ||
|
|
@@ -491,5 +510,6 @@ export const eventNewMessageActionBase /* \: $Diff<EventNewMessageAction, {| mes | |
| type: EVENT_NEW_MESSAGE, | ||
| id: 1001, | ||
| caughtUp: {}, | ||
| ownId: selfUser.user_id, | ||
| ownEmail: selfAccount.email, | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,9 +47,9 @@ export const storeKeys: Array<$Keys<GlobalState>> = [ | |
| * don't have to re-download it. | ||
| */ | ||
| // prettier-ignore | ||
| export const cacheKeys: Array<$Keys<GlobalState>> = [ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This bit was in Isham's version, but I just noticed it: do you see a reason this type should get dropped? |
||
| 'flags', 'messages', 'mute', 'narrows', 'realm', 'streams', | ||
| 'subscriptions', 'unread', 'userGroups', 'users', | ||
| export const cacheKeys = [ | ||
| 'flags', 'messages', 'mute', 'narrows', 'realm', 'recentPrivateConversations', | ||
| 'streams', 'subscriptions', 'unread', 'userGroups', 'users', | ||
| ]; | ||
|
|
||
| /** | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.