Verify friend/unfriends

This commit is contained in:
Natsumi
2022-02-12 19:28:33 +13:00
parent 1b135e1f15
commit 33a8b079ab
+21 -10
View File
@@ -10467,28 +10467,25 @@ speechSynthesis.getVoices();
if (!this.friendLogInitStatus || this.friendLog.has(id)) { if (!this.friendLogInitStatus || this.friendLog.has(id)) {
return; return;
} }
var ctx = {
id,
displayName: null,
trustLevel: null
};
var ref = API.cachedUsers.get(id); var ref = API.cachedUsers.get(id);
if (typeof ref !== 'undefined') { if (typeof ref !== 'undefined') {
ctx.displayName = ref.displayName; API.getFriendStatus({
ctx.trustLevel = ref.$trustLevel; userId: id
}).then((args) => {
if (args.json.isFriend) {
var friendLogHistory = { var friendLogHistory = {
created_at: new Date().toJSON(), created_at: new Date().toJSON(),
type: 'Friend', type: 'Friend',
userId: id, userId: id,
displayName: ctx.displayName displayName: ref.displayName
}; };
this.friendLogTable.data.push(friendLogHistory); this.friendLogTable.data.push(friendLogHistory);
database.addFriendLogHistory(friendLogHistory); database.addFriendLogHistory(friendLogHistory);
this.queueFriendLogNoty(friendLogHistory); this.queueFriendLogNoty(friendLogHistory);
var friendLogCurrent = { var friendLogCurrent = {
userId: id, userId: id,
displayName: ctx.displayName, displayName: ref.displayName,
trustLevel: ctx.trustLevel trustLevel: ref.$trustLevel
}; };
this.friendLog.set(id, friendLogCurrent); this.friendLog.set(id, friendLogCurrent);
database.setFriendLogCurrent(friendLogCurrent); database.setFriendLogCurrent(friendLogCurrent);
@@ -10496,6 +10493,8 @@ speechSynthesis.getVoices();
this.deleteFriendRequest(id); this.deleteFriendRequest(id);
this.updateSharedFeed(true); this.updateSharedFeed(true);
} }
});
}
}; };
$app.methods.deleteFriendRequest = function (userId) { $app.methods.deleteFriendRequest = function (userId) {
@@ -10516,6 +10515,10 @@ speechSynthesis.getVoices();
if (typeof ctx === 'undefined') { if (typeof ctx === 'undefined') {
return; return;
} }
API.getFriendStatus({
userId: id
}).then((args) => {
if (!args.json.isFriend) {
var friendLogHistory = { var friendLogHistory = {
created_at: new Date().toJSON(), created_at: new Date().toJSON(),
type: 'Unfriend', type: 'Unfriend',
@@ -10529,6 +10532,8 @@ speechSynthesis.getVoices();
database.deleteFriendLogCurrent(id); database.deleteFriendLogCurrent(id);
this.notifyMenu('friendLog'); this.notifyMenu('friendLog');
this.updateSharedFeed(true); this.updateSharedFeed(true);
}
});
}; };
$app.methods.updateFriendships = function (ref) { $app.methods.updateFriendships = function (ref) {
@@ -10553,6 +10558,10 @@ speechSynthesis.getVoices();
return; return;
} }
if (ctx.displayName !== ref.displayName) { if (ctx.displayName !== ref.displayName) {
API.getFriendStatus({
userId: ref.id
}).then((args) => {
if (args.json.isFriend) {
if (ctx.displayName) { if (ctx.displayName) {
var friendLogHistory = { var friendLogHistory = {
created_at: new Date().toJSON(), created_at: new Date().toJSON(),
@@ -10583,6 +10592,8 @@ speechSynthesis.getVoices();
this.notifyMenu('friendLog'); this.notifyMenu('friendLog');
this.updateSharedFeed(true); this.updateSharedFeed(true);
} }
});
}
if ( if (
ref.$trustLevel && ref.$trustLevel &&
ctx.trustLevel && ctx.trustLevel &&