mirror of
https://github.com/spacebarchat/server.git
synced 2024-11-22 02:12:40 +01:00
allow receiving messages via channel inbox.
This commit is contained in:
parent
268cfbe2b2
commit
d4f2859957
@ -365,28 +365,30 @@ export class Member extends BaseClassWithoutId {
|
||||
bio: "",
|
||||
};
|
||||
|
||||
const ret = Member.create({
|
||||
...member,
|
||||
roles: [Role.create({ id: guild_id })],
|
||||
// read_state: {},
|
||||
settings: {
|
||||
guild_id: null,
|
||||
mute_config: null,
|
||||
mute_scheduled_events: false,
|
||||
flags: 0,
|
||||
hide_muted_channels: false,
|
||||
notify_highlights: 0,
|
||||
channel_overrides: {},
|
||||
message_notifications: 0,
|
||||
mobile_push: true,
|
||||
muted: false,
|
||||
suppress_everyone: false,
|
||||
suppress_roles: false,
|
||||
version: 0,
|
||||
},
|
||||
// Member.save is needed because else the roles relations wouldn't be updated
|
||||
});
|
||||
|
||||
await Promise.all([
|
||||
Member.create({
|
||||
...member,
|
||||
roles: [Role.create({ id: guild_id })],
|
||||
// read_state: {},
|
||||
settings: {
|
||||
guild_id: null,
|
||||
mute_config: null,
|
||||
mute_scheduled_events: false,
|
||||
flags: 0,
|
||||
hide_muted_channels: false,
|
||||
notify_highlights: 0,
|
||||
channel_overrides: {},
|
||||
message_notifications: 0,
|
||||
mobile_push: true,
|
||||
muted: false,
|
||||
suppress_everyone: false,
|
||||
suppress_roles: false,
|
||||
version: 0,
|
||||
},
|
||||
// Member.save is needed because else the roles relations wouldn't be updated
|
||||
}).save(),
|
||||
ret.save(),
|
||||
Guild.increment({ id: guild_id }, "member_count", 1),
|
||||
emitEvent({
|
||||
event: "GUILD_MEMBER_ADD",
|
||||
@ -443,6 +445,8 @@ export class Member extends BaseClassWithoutId {
|
||||
} as MessageCreateEvent),
|
||||
]);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
toPublicMember() {
|
||||
|
@ -310,12 +310,23 @@ export class Message extends BaseClass {
|
||||
relations: { guild: true },
|
||||
});
|
||||
|
||||
const user = await User.fromAP(attrib as APPerson);
|
||||
let member;
|
||||
if (
|
||||
(await Member.count({
|
||||
where: { id: user.id, guild_id: channel.guild_id },
|
||||
})) == 0
|
||||
)
|
||||
member = await Member.addToGuild(user.id, channel.guild.id);
|
||||
|
||||
return Message.create({
|
||||
id: Snowflake.generate(),
|
||||
author: await User.fromAP(attrib as APPerson),
|
||||
author: user,
|
||||
member,
|
||||
content: data.content, // convert html to markdown
|
||||
timestamp: data.published,
|
||||
channel_id,
|
||||
channel,
|
||||
guild: channel.guild,
|
||||
|
||||
sticker_items: [],
|
||||
guild_id: channel.guild_id,
|
||||
@ -323,6 +334,9 @@ export class Message extends BaseClass {
|
||||
embeds: [],
|
||||
reactions: [],
|
||||
type: 0,
|
||||
mentions: [],
|
||||
mention_roles: [],
|
||||
mention_channels: [],
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -330,11 +330,40 @@ export class User extends BaseClass {
|
||||
}).then((x) => x.json())) as APPerson;
|
||||
}
|
||||
|
||||
const cache = await User.findOne({
|
||||
where: {
|
||||
email: `${data.preferredUsername}@${
|
||||
new URL(data.id!).hostname
|
||||
}`,
|
||||
},
|
||||
});
|
||||
if (cache) return cache;
|
||||
|
||||
return User.create({
|
||||
id: Snowflake.generate(), // hm
|
||||
username: data.preferredUsername,
|
||||
discriminator: new URL(data.id!).hostname,
|
||||
premium: false,
|
||||
bio: data.summary, // TODO: convert to markdown
|
||||
});
|
||||
|
||||
email: `${data.preferredUsername}@${new URL(data.id!).hostname}`,
|
||||
data: {
|
||||
hash: "#",
|
||||
valid_tokens_since: new Date(),
|
||||
},
|
||||
extended_settings: "{}",
|
||||
settings: UserSettings.create(),
|
||||
publicKey: "",
|
||||
privateKey: "",
|
||||
|
||||
premium_since: Config.get().defaults.user.premium
|
||||
? new Date()
|
||||
: undefined,
|
||||
rights: Config.get().register.defaultRights,
|
||||
premium_type: Config.get().defaults.user.premiumType ?? 0,
|
||||
verified: Config.get().defaults.user.verified ?? true,
|
||||
created_at: new Date(),
|
||||
}).save();
|
||||
}
|
||||
|
||||
static async getPublicUser(user_id: string, opts?: FindOneOptions<User>) {
|
||||
|
Loading…
Reference in New Issue
Block a user