YMDynamicMessagesCellViewModel.m 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. //
  2. // YMDynamicMessagesCellViewModel.m
  3. // MSYOUPAI
  4. //
  5. // Created by YoMi on 2024/3/21.
  6. // Copyright © 2024 MS. All rights reserved.
  7. //
  8. #import "YMDynamicMessagesCellViewModel.h"
  9. #import "YMDynamicMessagesModel.h"
  10. @interface YMDynamicMessagesCellViewModel ()
  11. /// 动态Id
  12. @property (nonatomic, assign, readwrite) NSInteger dynamicId;
  13. /// 用户Id
  14. @property (nonatomic, assign, readwrite) NSInteger userId;
  15. /// 用户头像
  16. @property (nonatomic, strong, readwrite) NSString *userAvatar;
  17. /// 动态消息内容
  18. @property (nonatomic, strong, readwrite) NSAttributedString *dynamicMessagesContent;
  19. /// 动态消息日期
  20. @property (nonatomic, strong, readwrite) NSString *dynamicMessagesDate;
  21. @end
  22. @implementation YMDynamicMessagesCellViewModel
  23. - (void)ym_initialize{
  24. [super ym_initialize];
  25. if ([self.params[ParamsModel] isKindOfClass:[YMDynamicMessagesModel class]]) {
  26. YMDynamicMessagesModel *model = self.params[ParamsModel];
  27. self.dynamicId = model.dynamic_id;
  28. self.userId = model.from_user_id;
  29. self.userAvatar = model.from_user_avatar;
  30. NSString *content = @"";
  31. if (model.is_delete == 1) {
  32. content = @"评论已被删除";
  33. } else {
  34. switch (model.is_type) {
  35. case 1:
  36. {
  37. content = model.content;
  38. }
  39. break;
  40. case 2:
  41. {
  42. content = stringFormat(@"%@回复了你:%@",model.from_user_nickname,model.content);
  43. }
  44. break;
  45. case 3:
  46. {
  47. content = stringFormat(@"%@评论了你:%@",model.from_user_nickname,model.content);
  48. }
  49. break;
  50. default:
  51. break;
  52. }
  53. NSMutableAttributedString *dynamicMessagesContentAttributed = [[NSMutableAttributedString alloc]initWithString:content];
  54. dynamicMessagesContentAttributed.yy_font = LCFont(13);
  55. dynamicMessagesContentAttributed.yy_color = HexColorFromRGB(0x333333);
  56. dynamicMessagesContentAttributed.yy_alignment = NSTextAlignmentLeft;
  57. dynamicMessagesContentAttributed.yy_lineSpacing = 5;
  58. [dynamicMessagesContentAttributed yy_setColor:HexColorFromRGB(0x7c69fe) range:[content rangeOfString:model.from_user_nickname]];
  59. self.dynamicMessagesContent = dynamicMessagesContentAttributed;
  60. }
  61. self.dynamicMessagesDate = model.create_time;
  62. }
  63. }
  64. @end