首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >对火力基地的颤振调用是从一个地点进行的,而不是下一个地点。

对火力基地的颤振调用是从一个地点进行的,而不是下一个地点。
EN

Stack Overflow用户
提问于 2022-08-14 13:58:03
回答 1查看 39关注 0票数 0

我有一个奇怪的虫子,我似乎不能工作。我正在为我的应用程序开发朋友请求系统,当请求发出时,它会为每个用户生成一个" RequestTile“,发送请求的用户会显示RequestTile的一个版本,而接收请求的人则会看到不同的版本。

“发送的请求”瓷砖显示用户名和一个带有cancel图标的Iconbutton按钮,该图标触发对数据库的调用,以从2个位置删除请求。

接收到的请求块显示用户名和2个IconButtons,一个用于接受请求,另一个用于取消请求。

两个用户的两个取消图标都会触发数据库的cancel方法。问题是他们中只有一个在做应该做的事。发送方可以单击IconButton,并按照应该的方式删除两个用户屏幕的Tile,但是当接收方按下IconButton时,它确实会运行该方法,因为我为每个步骤添加了日志条目,但是对数据库的调用由于某种原因没有运行。

这是我的按钮密码..。

代码语言:javascript
运行
复制
!isSentRequest
                ? IconButton(
                    onPressed: () {
                      Utilities.logWarning('Cancelling Requests Received from $requestersId');
                      _db.cancelFriendRequest(requestersId);
                    },
                    icon: Icon(
                      Icons.thumb_down_alt,
                      color: Colors.red,
                      size: 30.r,
                    ),
                  )
                : Container(),
            SizedBox(width: 10.w),
            !isSentRequest
                ? IconButton(
                    onPressed: () {
                      Utilities.logWarning('Accepting Request Received from $requestersId');
                      _db.acceptFriendRequest(requestersId);
                    },
                    icon: Icon(
                      Icons.thumb_up_alt,
                      color: Colors.green,
                      size: 30.r,
                    ),
                  )
                : IconButton(
                    onPressed: () {
                      Utilities.logWarning('Cancelling Requests Sent to $requestersId');
                      _db.cancelFriendRequest(requestersId);
                    },
                    icon: Icon(
                      Icons.cancel,
                      color: Colors.red,
                      size: 30.r,
                    ),
                  ),

以下是取消两个按钮使用的请求的数据库方法.

代码语言:javascript
运行
复制
  Future<void> cancelFriendRequest(String _friendUID) async {
// Remove friend request from users received collection
await _db
    .collection(USER_COLLECTION)
    .doc(_auth.getCurrentUID())
    .collection(requestsSent)
    .doc(_friendUID)
    .delete();
Utilities.logWarning('Removed friend request from users received collection');

// Remove user from requested friends sent collection
await _db
    .collection(USER_COLLECTION)
    .doc(_friendUID)
    .collection(requestsReceived)
    .doc(_auth.getCurrentUID())
    .delete();
Utilities.logWarning('Removed user from requested friends sent collection');

}

正如您在数据库方法中看到的那样,当我从任何一个用户的角度按下按钮时,就会有两个日志显示在控制台中。

我希望有人能解释一下为什么它正确地从一个按钮运行该方法,而不是从另一个按钮运行。

编辑在进行_db方法调用之前对日志进行更新,以向我显示每个用户的requesterID,以确保它们是正确的,这是根据从哪个用户设备调用的。

以下是当我按下接收方请求取消的拒绝按钮时的日志输出.

以下是当我按下发送者请求取消的取消按钮时的日志输出.

正如您可以看到的,这两个按钮按下显示了所有三个步骤,在调用方法之前,首先调用DB,然后第二次调用DB,但只有当发送方按下它实际上从数据库中删除条目时,

发件人收集面包屑..。

接收器收集面包屑..。

纠正了任何发现这个问题的方法--

代码语言:javascript
运行
复制
  Future<void> denyReceivedFriendRequest(String _friendUID) async {
// Remove friend request from users received collection
_db.collection(USER_COLLECTION).doc(_auth.getCurrentUID()).collection(requestsReceived).doc(_friendUID).delete();
Utilities.logWarning('Removed friend request from ${_auth.getCurrentUID()} receieved collection');

// Remove user from requested friends sent collection
_db.collection(USER_COLLECTION).doc(_friendUID).collection(requestsSent).doc(_auth.getCurrentUID()).delete();
Utilities.logWarning('Removed friend request from $_friendUID sent collection');



  Future<void> cancelSentFriendRequest(String _friendUID) async {
// Remove friend request from users received collection
_db.collection(USER_COLLECTION).doc(_auth.getCurrentUID()).collection(requestsSent).doc(_friendUID).delete();
Utilities.logWarning('Removed friend request from ${_auth.getCurrentUID()} sent collection');

// Remove user from requested friends sent collection
_db.collection(USER_COLLECTION).doc(_friendUID).collection(requestsReceived).doc(_auth.getCurrentUID()).delete();
Utilities.logWarning('Removed friend request from $_friendUID received collection');
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-08-14 14:21:22

只是一个建议,当用户(发件人)发送一个请求时,它就保存在请求发送集合中。因此,当接收者想要删除这个请求时,删除的方法应该是不同的,即访问请求、发送朋友请求和接收接收请求。

代码语言:javascript
运行
复制
Future<void> cancelFriendRequest(String _friendUID) async {
// Remove friend request from users received collection
await _db
    .collection(USER_COLLECTION)
    .doc(_friendUID)
    .collection(requestsSent)
    .doc(_auth.getCurrentUID())
    .delete();
Utilities.logWarning('Removed friend request from users received collection');

// Remove user from requested friends sent collection
await _db
    .collection(USER_COLLECTION)
    .doc(_auth.getCurrentUID())
    .collection(requestsReceived)
    .doc(_friendUID)
    .delete();

请注意,这个文档在这里已经被替换了。对于接收方,首先获取friendID文档,然后检查请求发送的集合,然后获取接收方文档并删除它。然后获取接收方访问请求接收集合的文档,然后删除好友(发送方) ID并删除它。

所以对于发送者来说,方法应该是不同的,对于接收者来说,方法应该是不同的。

进一步解释

用户发送请求。集合的创建方式如下

代码语言:javascript
运行
复制
doc("UserID")->collection("requestSent")->doc("user2")

现在,当用户1获取这个文档时,它必须是

代码语言:javascript
运行
复制
doc(UserID)->collection("requestSent")->doc(friendID) - delete

当用户2获取相同的文档时,它必须是

代码语言:javascript
运行
复制
doc(friendID)->collection("requestSent")->doc(UserID) - delete

如果您注意到访问相同数据的文档有不同的值(UserID和friendID),则取决于访问文档的对象。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73352236

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档